Skip to content
This repository was archived by the owner on Nov 12, 2023. It is now read-only.
This repository was 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

@Antikyth

Description

@Antikyth

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,
        })
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Unassigned

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions