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

Access struct fields from Roto #105

Open
tertsdiepraam opened this issue Jan 20, 2025 · 0 comments
Open

Access struct fields from Roto #105

tertsdiepraam opened this issue Jan 20, 2025 · 0 comments

Comments

@tertsdiepraam
Copy link
Contributor

tertsdiepraam commented Jan 20, 2025

Roto should be able to read and write fields from Rust types. These fields need to be registered with their offsets and types. This should be done with a declarative macro like so:

rt.register_clone_type(Foo, fields!{ Foo: bar, baz });

The fields macro would expand to something like:

unsafe { Fields::new(TypeId::of<Foo>(), &[
   Field::new("bar", std::mem::offset_of!(Foo.bar), create_type_description!(Foo, bar)),
   Field::new("baz", std::mem::offset_of!(Foo.baz), create_type_description!(Foo, baz)),
]) };

where create_type_description would be implemented like:

fn create_type_description_from_option<T>(x: Option<T>) -> ...{
    // do the reflect thing
}

macro_rules! create_type_description {
    ($ty: ident, $field: ident) => {{
        let opt: Option<$ty> = None;
        let opt = opt.map(|x| x.$field;
        create_type_description_from_option(opt)
    }}
}

Similarly, there should be a way to get enum variants into Roto.

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

1 participant