-
Notifications
You must be signed in to change notification settings - Fork 432
Add binding for git_message_trailers
#749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
15a7d4e
5575c3d
33ebdcd
f6fd4b7
b0015cc
e94008a
e830f7d
55ea909
e7b0306
cd4c2db
e450945
a0bd026
34fa7b5
023fb92
16321f3
70b7ebd
ed11c76
958e378
2508506
f35b68f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Suggested-by: Alex Crichton <[email protected]> See: #749 (comment)
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,22 +88,6 @@ impl Binding for MessageTrailers { | |
| } | ||
| } | ||
|
|
||
| struct Trailer<'pair> { | ||
| key: *const c_char, | ||
| value: *const c_char, | ||
| _marker: marker::PhantomData<&'pair c_char>, | ||
| } | ||
|
|
||
| impl<'pair> Trailer<'pair> { | ||
| fn to_str_tuple(self) -> (&'pair str, &'pair str) { | ||
| unsafe { | ||
| let key = CStr::from_ptr(self.key).to_str().unwrap(); | ||
| let value = CStr::from_ptr(self.value).to_str().unwrap(); | ||
| (key, value) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A borrowed iterator. | ||
| pub struct MessageTrailersIterator<'a> { | ||
| trailers: &'a MessageTrailers, | ||
|
|
@@ -116,16 +100,23 @@ impl<'pair> Iterator for MessageTrailersIterator<'pair> { | |
| fn next(&mut self) -> Option<Self::Item> { | ||
| self.range.next().map(|index| unsafe { | ||
| let addr = self.trailers.raw.trailers.wrapping_add(index); | ||
| Trailer { | ||
| key: (*addr).key, | ||
| value: (*addr).value, | ||
| _marker: marker::PhantomData, | ||
| } | ||
| .to_str_tuple() | ||
| to_str_tuple((*addr).key, (*addr).value, marker::PhantomData) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn to_str_tuple<'pair>( | ||
| key: *const c_char, | ||
| value: *const c_char, | ||
| _marker: marker::PhantomData<&'pair c_char>, | ||
| ) -> (&'pair str, &'pair str) { | ||
| unsafe { | ||
| let k = CStr::from_ptr(key).to_str().unwrap(); | ||
| let v = CStr::from_ptr(value).to_str().unwrap(); | ||
| (k, v) | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add implementations for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I implemented The doc says that See rev. e7b0306 |
||
|
|
||
| /// Get the trailers for the given message. | ||
| pub fn message_trailers<'pair, S: IntoCString>(message: S) -> Result<MessageTrailers, Error> { | ||
| _message_trailers(message.into_c_string()?) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add
size_hinthere too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay I think I understand now. I confused myself thought that
size_hint()was part ofExactSizeIterator.See rev 16321f3