Skip to content
Discussion options

You must be logged in to vote

Hi @rljacobson, thanks for your exploration! Aside from partial records and extensible builders, CGP has another undocumented feature for HasFields, which is that you can use FromFields and ToFields to convert to/from the Fields type. Here is an example use:

#[derive(Clone, Debug, Eq, PartialEq, HasFields)]
pub struct Person {
    pub name: String,
    pub age: u8,
}

let name = "Alice".to_owned();

let person1 = Person { name: name.clone(), age: 32 };

// Product![ Field<symbol!("name"), String>, Field<symbol!("age"), u8> ]
let product = person1.clone().to_fields();
assert_eq!(product, product![name.clone().into(), 32.into()]);

// Product![ Field<symbol!("name"), &String>, Field<symbol!…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@rljacobson
Comment options

@soareschen
Comment options

Answer selected by rljacobson
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants