Skip to content

Conversation

@sunjay
Copy link
Contributor

@sunjay sunjay commented Feb 12, 2019

Added Default derive for NodeHtmlBlock so that it can be constructed even though one of its fields is hidden.

This is useful for when you are replacing a node in the AST by creating an HTML block in its place. Having Default implemented makes it so you can specify only the fields you care about and not have to know about the #[doc(hidden)] fields.

NodeHtmlBlock {
    literal: b"<h1>Hello!</h1>".to_vec(),
    ..NodeHtmlBlock::default()
}

I noticed that the other structs with hidden fields (other than Ast) all implement Default, so I thought I would add it for NodeHtmlBlock too.

It is probably a good idea to add some constructors for Ast as well so that people can create that struct when needed (to add brand new nodes to the tree). I don't know what those constructors would be (don't know the code well enough), so I'll leave that up to you. :)

@kivikakk
Copy link
Owner

Thanks, this looks good!

It is probably a good idea to add some constructors for Ast as well so that people can create that struct when needed (to add brand new nodes to the tree).

Good idea! I'll make make_block public (documented) and rename it to make_ast, since that's what it does.

@kivikakk kivikakk merged commit d858dd1 into kivikakk:master Feb 12, 2019
@sunjay sunjay deleted the nodehtmlblock-default branch February 12, 2019 03:22
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

Successfully merging this pull request may close these issues.

2 participants