Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don’t need std::marker any more
  • Loading branch information
LemmingAvalanche committed Oct 15, 2021
commit a0bd0260110a6fa1f701bf9f467f5721c0ee72ea
8 changes: 2 additions & 6 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::ops::Range;
use std::ffi::CStr;
use std::ffi::CString;
use std::marker;
use std::ptr;

use libc::{c_char, c_int};
Expand Down Expand Up @@ -37,7 +36,6 @@ fn _message_prettify(message: CString, comment_char: Option<u8>) -> Result<Strin
/// Use `iter()` to get access to the values.
pub struct MessageTrailers {
raw: raw::git_message_trailer_array,
_marker: marker::PhantomData<c_char>,
}

impl MessageTrailers {
Expand Down Expand Up @@ -80,7 +78,6 @@ impl Binding for MessageTrailers {
unsafe fn from_raw(raw: *mut raw::git_message_trailer_array) -> MessageTrailers {
MessageTrailers {
raw: *raw,
_marker: marker::PhantomData,
}
}
fn raw(&self) -> *mut raw::git_message_trailer_array {
Expand All @@ -100,15 +97,14 @@ impl<'pair> Iterator for MessageTrailersIterator<'pair> {
fn next(&mut self) -> Option<Self::Item> {
self.range
.next()
.map(|index| to_str_tuple(&self.trailers, index, marker::PhantomData))
.map(|index| to_str_tuple(&self.trailers, index))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add size_hint here too?

Copy link
Contributor Author

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 of ExactSizeIterator.

See rev 16321f3

}

#[inline(always)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This annotation isn't necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See rev 023fb92

fn to_str_tuple(
trailers: &MessageTrailers,
index: usize,
_marker: marker::PhantomData<c_char>,
) -> (&str, &str) {
unsafe {
let addr = trailers.raw.trailers.wrapping_add(index);
Expand All @@ -128,7 +124,7 @@ impl DoubleEndedIterator for MessageTrailersIterator<'_> {
fn next_back(&mut self) -> Option<Self::Item> {
self.range
.next_back()
.map(|index| to_str_tuple(&self.trailers, index, marker::PhantomData))
.map(|index| to_str_tuple(&self.trailers, index))
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add implementations for size_hint and ExactSizeIterator here as well? (which would also necessitate DoubleEndedIterator, and the implementations should be relatively easy if the counter field is changed to a Range)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented len() for ExactSizeIterator. The doc says that size_hint() can be derived from it. I couldn’t implement size_hint() myself.

The doc says that len() has a default implementation, but I guess just returning the value directly wouldn’t be less efficient than whatever the default impl. is.

See rev. e7b0306


Expand Down