Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct Image {
- pub name: String,
- bytes: Vec<u8>,
- }
- impl Image {
- pub fn new(name: String, bytes: &[u8]) -> Image {
- Image {
- name,
- bytes: bytes.to_vec(),
- }
- }
- pub fn bytes(&self) -> impl Iterator<Item = u8> {
- // If i return the self.bytes.iter() I get an iterator over &u8's (because we're operating on a borrow of Image)
- // It seems to me that it would be better to return an iterator of u8's instead
- // (and the most efficient way to do that is probably to clone the vector before constructing the iterator?)
- // However i want to know why THIS doesnt work:
- // This should construct an iterator with an internal borrow of self, which derefrences each value as it's returned by the iterator
- // Does this just not work because i cannot communicate to the caller that the returned value has a borrow on self?
- // If this was a type that let me specify a lifetime parameter would it work if i specified that both `self` and the return value has the lifetime 'a?
- self.bytes.iter().map(|byte| *byte)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement