| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error# as IOErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::FromUtf8Errorrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/FromUtf8Error#; |
| 3 | |
| 4 | /// The Output API. |
| 5 | /// |
| 6 | /// Handlebars uses this trait to define rendered output. |
| 7 | pub trait Outputrust-analyzer cargo handlebars 5.1.2 output/Output# { |
| 8 | fn writerust-analyzer cargo handlebars 5.1.2 output/Output#write().(&mut self, seg: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), IOErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#>; |
| 9 | |
| 10 | /// Designed to be used with `write!` macro. |
| 11 | /// for backward compatibility and to avoid breakage the default implementation |
| 12 | /// uses `format!` this may be not what you want. |
| 13 | fn write_fmtrust-analyzer cargo handlebars 5.1.2 output/Output#write_fmt().(&mut self, args: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Argumentsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Arguments#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), IOErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 14 | // Check if there is nothing to format to avoid allocation on case like |
| 15 | // write!(out, "hey")?; |
| 16 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(content) = args.as_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Arguments<'a>`]as_str().() { |
| 17 | self.writerust-analyzer cargo handlebars 5.1.2 output/Output#write().(content) |
| 18 | } else { |
| 19 | self.writerust-analyzer cargo handlebars 5.1.2 output/Output#write().(&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/format().(args)) |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | pub struct WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> { |
| 25 | writerust-analyzer cargo handlebars 5.1.2 output/WriteOutput#write.: W, |
| 26 | } |
| 27 | |
| 28 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Outputrust-analyzer cargo handlebars 5.1.2 output/Output# for WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#<W> { |
| 29 | fn writerust-analyzer cargo handlebars 5.1.2 output/impl#[`WriteOutput<W>`][Output]write().(&mut self, seg: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), IOErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 30 | self.writerust-analyzer cargo handlebars 5.1.2 output/WriteOutput#write..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(seg.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 31 | } |
| 32 | |
| 33 | fn write_fmtrust-analyzer cargo handlebars 5.1.2 output/impl#[`WriteOutput<W>`][Output]write_fmt().(&mut self, args: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Argumentsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Arguments#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), IOErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 34 | self.writerust-analyzer cargo handlebars 5.1.2 output/WriteOutput#write..write_fmtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_fmt().(args) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#<W> { |
| 39 | pub fn newrust-analyzer cargo handlebars 5.1.2 output/impl#[`WriteOutput<W>`]new().(write: W) -> WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#<W> { |
| 40 | WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput# { writerust-analyzer cargo handlebars 5.1.2 output/WriteOutput#write. } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | pub struct StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput# { |
| 45 | bufrust-analyzer cargo handlebars 5.1.2 output/StringOutput#buf.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 46 | } |
| 47 | |
| 48 | impl Outputrust-analyzer cargo handlebars 5.1.2 output/Output# for StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput# { |
| 49 | fn writerust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput][Output]write().(&mut self, seg: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), IOErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 50 | self.bufrust-analyzer cargo handlebars 5.1.2 output/StringOutput#buf..extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(seg.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()); |
| 51 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 52 | } |
| 53 | |
| 54 | fn write_fmtrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput][Output]write_fmt().(&mut self, args: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Argumentsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Arguments#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), IOErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 55 | self.bufrust-analyzer cargo handlebars 5.1.2 output/StringOutput#buf..write_fmtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_fmt().(args) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | impl StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput# { |
| 60 | pub fn newrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]new().() -> StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput# { |
| 61 | StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput# { |
| 62 | bufrust-analyzer cargo handlebars 5.1.2 output/StringOutput#buf.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().1024), |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | pub fn into_stringrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]into_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, FromUtf8Errorrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/FromUtf8Error#> { |
| 67 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(self.bufrust-analyzer cargo handlebars 5.1.2 output/StringOutput#buf.) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput# { |
| 72 | fn defaultrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput][Default]default().() -> Selfrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput][Default] { |
| 73 | StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput#::newrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]new().() |
| 74 | } |
| 75 | } |