Closed
Description
Since Ref
is essentially a reference type, it would be nice if it implemented Clone
and Copy
when the underlying ByteSlice
does. The whole point of zerocopy
is not copying, so I imagine clone
ing the entire underlying type through the Deref
impl (which this would interfere with) is not a common operation.
My use case: I followed the example for parsing a UDP header, so my structs look like this:
struct Header<B: ByteSlice> {
pub props: Ref<B, Props>,
pub names: B,
pub name_hashes: B,
pub package_ids: Ref<B, [PackageId]>,
// …
}
I can't take &self
, do some processing on a Ref
, and hand out types with the same lifetime as the underlying slice. But I can't take self
either, because I do this for more than one field and Ref: !Clone
, so my struct is !Clone
too. I'd like to do something like this:
fn cool_packages<'a>(&self) -> impl 'a + Iterator<Item = &'a PackageId> where B: 'a + Clone {
self.package_ids.clone()
.into_slice()
.iter()
.filter(|p| is_cool(p))
}
Am I missing a soundness issue?
Metadata
Metadata
Assignees
Labels
No labels