pub enum Node {
Element(Element),
Text(String),
Raw(String),
Comment(String),
Fragment(Vec<Node>),
}Expand description
A node in the HTML tree.
§Examples
use winged_rust::prelude::*;
let node = Node::from(div().text("hi"));
assert_eq!(node.render(), "<div>hi</div>");Variants§
Element(Element)
An element with a tag name, attributes and children.
Text(String)
Escaped text. The escaping already happened — see crate::core::escape.
Raw(String)
Verbatim markup, never escaped. For imported snippets: an SVG, an embed code.
Unlike Node::Fragment, this is an opaque string, so pretty printing can only
indent the whole blob. Reach for a fragment when you want the children indented.
Comment(String)
An HTML comment. New in the Rust port — Winged-Swift has no comment node.
The content has -- neutralised so the comment cannot be closed early.
Fragment(Vec<Node>)
A transparent group that renders its children with no wrapper element.
Use it to return several nodes from one expression — a map of cards, the body of
an if, a group of <meta> tags — without introducing an extra <div>.
Implementations§
Source§impl Node
impl Node
Sourcepub fn raw(content: impl Into<String>) -> Self
pub fn raw(content: impl Into<String>) -> Self
Creates a raw markup node. The content is not escaped.
Sourcepub fn comment(content: impl AsRef<str>) -> Self
pub fn comment(content: impl AsRef<str>) -> Self
Creates a comment node.
Any -- in the content is replaced with - -, so the comment cannot terminate
early and inject markup.
§Examples
use winged_rust::prelude::*;
assert_eq!(Node::comment("a -- b").render(), "<!-- a - - b -->");Sourcepub fn fragment(children: impl IntoIterator<Item = Node>) -> Self
pub fn fragment(children: impl IntoIterator<Item = Node>) -> Self
Creates a transparent group of nodes.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether this node renders to nothing.
The pretty-print writer arrives at the same answer without calling this: it lets a
child write straight into the output and rolls the separator back if the child wrote
nothing, which is what stops an empty fragment — the body of a false if — from
leaving a blank line behind.
Trait Implementations§
impl Eq for Node
Source§impl Render for Node
impl Render for Node
Source§fn write_into(&self, out: &mut String, options: &RenderOptions, depth: usize)
fn write_into(&self, out: &mut String, options: &RenderOptions, depth: usize)
Source§fn render_pretty(&self) -> String
fn render_pretty(&self) -> String
Source§fn render_with(&self, options: &RenderOptions) -> String
fn render_with(&self, options: &RenderOptions) -> String
impl StructuralPartialEq for Node
Auto Trait Implementations§
impl Freeze for Node
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl UnsafeUnpin for Node
impl UnwindSafe for Node
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more