Skip to content
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

impl Clone + Copy for Ref #627

Closed
nathan opened this issue Nov 18, 2023 · 1 comment · Fixed by #989
Closed

impl Clone + Copy for Ref #627

nathan opened this issue Nov 18, 2023 · 1 comment · Fixed by #989

Comments

@nathan
Copy link

nathan commented Nov 18, 2023

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 cloneing 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?

@joshlf
Copy link
Member

joshlf commented Dec 15, 2023

This should be doable; I'll put it on our roadmap for 0.8.

@joshlf joshlf mentioned this issue Dec 15, 2023
87 tasks
joshlf added a commit that referenced this issue Mar 1, 2024
joshlf added a commit that referenced this issue Mar 1, 2024
joshlf added a commit that referenced this issue Mar 1, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants