pub struct PartsWriter<'a> { /* private fields */ }Expand description
A context-carrying writer over a view-parts buffer, created per position.
The view! macro creates a PartsWriter for each dynamic position it
fills and hands it to the matching position trait:
NodeViewParts,
AttributeValueViewParts,
AttributeKeyViewParts,
ElementNameViewParts, or
AttributeViewParts.
Implementations of those traits make a value renderable by pushing it
through the push_* methods, which seal the pushed text with the
HtmlContext of the position so rendering escapes or validates it
correctly, or by delegating to another implementation of the same
position trait. push_str_unescaped is the
only way to opt out of that protection.
Implementations§
Source§impl<'a> PartsWriter<'a>
impl<'a> PartsWriter<'a>
Sourcepub fn new(parts: &'a mut ViewParts, context: HtmlContext) -> Self
pub fn new(parts: &'a mut ViewParts, context: HtmlContext) -> Self
Creates a writer that seals everything pushed into it with context.
Sourcepub fn push_str(&mut self, value: impl Into<Cow<'static, str>>) -> &mut Self
pub fn push_str(&mut self, value: impl Into<Cow<'static, str>>) -> &mut Self
Appends a string, sealed with this writer’s context.
Sourcepub fn push_str_unescaped(
&mut self,
value: impl Into<Cow<'static, str>>,
) -> &mut Self
pub fn push_str_unescaped( &mut self, value: impl Into<Cow<'static, str>>, ) -> &mut Self
Appends a string that renders verbatim, bypassing this writer’s context.
Use this only for trusted markup. Passing untrusted input defeats the runtime’s escaping and can lead to XSS vulnerabilities.
Sourcepub fn push_char(&mut self, value: char) -> &mut Self
pub fn push_char(&mut self, value: char) -> &mut Self
Appends a character, sealed with this writer’s context.
Sourcepub fn push_bool(&mut self, value: bool) -> &mut Self
pub fn push_bool(&mut self, value: bool) -> &mut Self
Appends a bool rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_i8(&mut self, value: i8) -> &mut Self
pub fn push_i8(&mut self, value: i8) -> &mut Self
Appends a i8 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_i16(&mut self, value: i16) -> &mut Self
pub fn push_i16(&mut self, value: i16) -> &mut Self
Appends a i16 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_i32(&mut self, value: i32) -> &mut Self
pub fn push_i32(&mut self, value: i32) -> &mut Self
Appends a i32 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_i64(&mut self, value: i64) -> &mut Self
pub fn push_i64(&mut self, value: i64) -> &mut Self
Appends a i64 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_i128(&mut self, value: i128) -> &mut Self
pub fn push_i128(&mut self, value: i128) -> &mut Self
Appends a i128 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_isize(&mut self, value: isize) -> &mut Self
pub fn push_isize(&mut self, value: isize) -> &mut Self
Appends a isize rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_u8(&mut self, value: u8) -> &mut Self
pub fn push_u8(&mut self, value: u8) -> &mut Self
Appends a u8 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_u16(&mut self, value: u16) -> &mut Self
pub fn push_u16(&mut self, value: u16) -> &mut Self
Appends a u16 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_u32(&mut self, value: u32) -> &mut Self
pub fn push_u32(&mut self, value: u32) -> &mut Self
Appends a u32 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_u64(&mut self, value: u64) -> &mut Self
pub fn push_u64(&mut self, value: u64) -> &mut Self
Appends a u64 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_u128(&mut self, value: u128) -> &mut Self
pub fn push_u128(&mut self, value: u128) -> &mut Self
Appends a u128 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_usize(&mut self, value: usize) -> &mut Self
pub fn push_usize(&mut self, value: usize) -> &mut Self
Appends a usize rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_f32(&mut self, value: f32) -> &mut Self
pub fn push_f32(&mut self, value: f32) -> &mut Self
Appends a f32 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_f64(&mut self, value: f64) -> &mut Self
pub fn push_f64(&mut self, value: f64) -> &mut Self
Appends a f64 rendered as text.
Its rendered form contains no character that is significant in any HTML context, so no escaping applies.
Sourcepub fn push_dyn(&mut self, part: Box<dyn DynViewPart>) -> &mut Self
pub fn push_dyn(&mut self, part: Box<dyn DynViewPart>) -> &mut Self
Appends a part that writes its output at render time, sealed with this writer’s context.