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

Make getters work with immutable Data #23

Closed
mlr-msft opened this issue Jun 7, 2019 · 1 comment
Closed

Make getters work with immutable Data #23

mlr-msft opened this issue Jun 7, 2019 · 1 comment
Milestone

Comments

@mlr-msft
Copy link

mlr-msft commented Jun 7, 2019

I'd like to be able to work with immutable data. e.g.:

impl<T> IpV4Header<T> {
    pub fn validate<T>(bytes: T) -> Result<()>
    where
        T: AsRef<[u8]>,
    { ...

Unfortunately, the accessor functions (e.g. get_protocol) that are generated require the AsMut<[u8]> trait. Is there something I'm not doing correctly?

Thanks in advance.

@mlr-msft mlr-msft changed the title Question about Immutability Question About Working with Immutable Data Jun 7, 2019
@dzamlo
Copy link
Owner

dzamlo commented Jun 9, 2019

Ti use the getter and setter require that the type implement BitRange (and Bit for single bit field). And the implementation only exist for T: AsMut<[$slice_ty]> + AsRef<[$slice_ty] at the moment.

So yes, currently the getter will also require AsMut<[u8]>.

Maybe, I should split the BitRange trait in two (Only with a getter and one with a setter). And only require the necessary one of the two for each method.

@dzamlo dzamlo changed the title Question About Working with Immutable Data Make getters work with immutable Data Jun 9, 2019
@dzamlo dzamlo added this to the 0.14.0 milestone Jun 9, 2019
@dzamlo dzamlo closed this as completed in d92de6a Oct 27, 2020
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

No branches or pull requests

2 participants