pub struct Renderer<'a> { /* private fields */ }Expand description
Implementations§
Source§impl<'a> Renderer<'a>
impl<'a> Renderer<'a>
Sourcepub fn arg(&mut self, value: &'a (impl Display + Debug)) -> &mut Self
pub fn arg(&mut self, value: &'a (impl Display + Debug)) -> &mut Self
Add a positional argument.
Sourcepub fn named(
&mut self,
name: &'a str,
value: &'a (impl Display + Debug),
) -> &mut Self
pub fn named( &mut self, name: &'a str, value: &'a (impl Display + Debug), ) -> &mut Self
Add a named argument.
Examples found in repository?
examples/struct.rs (line 34)
15fn main() {
16 let origin = Point { x: 0.0, y: 0.0 };
17 let target = Point { x: 3.5, y: -2.1 };
18
19 // Display
20 let result = formatx!("From {} to {}", origin, target).unwrap();
21 println!("{result}");
22
23 // Debug
24 let result = formatx!("Debug: {:?}", origin).unwrap();
25 println!("{result}");
26
27 // Pretty debug
28 let result = formatx!("Pretty: {:#?}", origin).unwrap();
29 println!("{result}");
30
31 // Template reuse
32 let template = formatx::Template::new("Point {name}: {point}").unwrap();
33 let r1 = template.render()
34 .named("name", &"Origin")
35 .named("point", &origin)
36 .finish()
37 .unwrap();
38 let r2 = template.render()
39 .named("name", &"Target")
40 .named("point", &target)
41 .finish()
42 .unwrap();
43 println!("{r1}");
44 println!("{r2}");
45}Sourcepub fn finish(&self) -> Result<String, Error>
pub fn finish(&self) -> Result<String, Error>
Strict: produce the formatted output.
Returns Err(Error::MissingArgument) if any placeholder references an
argument that was not provided.
Examples found in repository?
examples/struct.rs (line 36)
15fn main() {
16 let origin = Point { x: 0.0, y: 0.0 };
17 let target = Point { x: 3.5, y: -2.1 };
18
19 // Display
20 let result = formatx!("From {} to {}", origin, target).unwrap();
21 println!("{result}");
22
23 // Debug
24 let result = formatx!("Debug: {:?}", origin).unwrap();
25 println!("{result}");
26
27 // Pretty debug
28 let result = formatx!("Pretty: {:#?}", origin).unwrap();
29 println!("{result}");
30
31 // Template reuse
32 let template = formatx::Template::new("Point {name}: {point}").unwrap();
33 let r1 = template.render()
34 .named("name", &"Origin")
35 .named("point", &origin)
36 .finish()
37 .unwrap();
38 let r2 = template.render()
39 .named("name", &"Target")
40 .named("point", &target)
41 .finish()
42 .unwrap();
43 println!("{r1}");
44 println!("{r2}");
45}Sourcepub fn finish_lenient(&self) -> Result<String, Error>
pub fn finish_lenient(&self) -> Result<String, Error>
Lenient: produce the formatted output.
Missing arguments are replaced with an empty string "" instead of
producing an error.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Renderer<'a>
impl<'a> !Send for Renderer<'a>
impl<'a> !Sync for Renderer<'a>
impl<'a> !UnwindSafe for Renderer<'a>
impl<'a> Freeze for Renderer<'a>
impl<'a> Unpin for Renderer<'a>
impl<'a> UnsafeUnpin for Renderer<'a>
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
Mutably borrows from an owned value. Read more