Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

XRBK macro: allow deriving ReadableWithContext by placing a #[read_with(...)] attribute on the item #37

Open
Antikyth opened this issue Jan 10, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Antikyth
Copy link
Collaborator

Antikyth commented Jan 10, 2023

Examples

#[derive(X11Size, ReadableWithContext)]
#[read_with(len: &usize)]
pub struct MyVec<T> {
    #[context(len => *len)]
    vec: Vec<T>,
}

Which could derive the following:

#[automatically_derived]
impl<T: Readable + X11Size> ReadableWithContext for MyVec<T> {
    type Context = (usize);

    fn read_with(buf: &mut impl Buf, (param_len): &(usize)) -> Result<Self, ReadError> {
        fn field_vec(len: &usize) -> <Vec<T>>::Context {
            *len
        }

        let field_vec = <Vec<T>>::read_with(buf, field_vec(param_len));

        Ok(Self {
            vec: field_vec,
        })
    }
}
@Antikyth Antikyth added the enhancement New feature or request label Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Status: Unassigned
Development

No branches or pull requests

1 participant