-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Hello,
I see that there is another thread discussing defaults but this is slightly different.
When defining a struct as a component it is already possible to derive or implement default to use the .. syntax. However you cannot derive Default if there are child elements to the component because Lazy does not implement Default.
The only way around it that I have found is to implement Default without deriving using a concrete type for the F:
pub struct MyComponent<'a> {
pub class: &'a str,
// Possibly many more attributes here
pub children: Lazy<fn(&mut Buffer<Node>), Node>,
}
impl<'a> Default for MyComponent<'a> {
fn default() -> MyComponent<'a> {
Button {
class: "",
// Need to add defaults for all the other attributes
children: Lazy::dangerously_create(|_| ())
}
}
}
This works, but if there are many attributes it would be convenient to derive it.
A possible solution would be to add a Default for Lazy<fn(&mut Buffer<C>)>. I made the suggestion here:
dvaergiller@c9257c2
Is there a better way to do this? If not, I'd be happy to make a pull request out of this.
adamjhf
Metadata
Metadata
Assignees
Labels
No labels