From 7e5d7eea9c580ef4b41a765bde624af431942b96 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:41:35 +0200 Subject: Merging upstream version 1.70.0+dfsg2. Signed-off-by: Daniel Baumann --- vendor/handlebars-3.5.5/src/output.rs | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 vendor/handlebars-3.5.5/src/output.rs (limited to 'vendor/handlebars-3.5.5/src/output.rs') diff --git a/vendor/handlebars-3.5.5/src/output.rs b/vendor/handlebars-3.5.5/src/output.rs new file mode 100644 index 000000000..f1c5865a5 --- /dev/null +++ b/vendor/handlebars-3.5.5/src/output.rs @@ -0,0 +1,48 @@ +use std::io::{Error as IOError, Write}; +use std::string::FromUtf8Error; + +/// The Output API. +/// +/// Handlebars uses this trait to define rendered output. +pub trait Output { + fn write(&mut self, seg: &str) -> Result<(), IOError>; +} + +pub struct WriteOutput { + write: W, +} + +impl Output for WriteOutput { + fn write(&mut self, seg: &str) -> Result<(), IOError> { + self.write.write_all(seg.as_bytes()) + } +} + +impl WriteOutput { + pub fn new(write: W) -> WriteOutput { + WriteOutput { write } + } +} + +pub struct StringOutput { + buf: Vec, +} + +impl Output for StringOutput { + fn write(&mut self, seg: &str) -> Result<(), IOError> { + self.buf.extend_from_slice(seg.as_bytes()); + Ok(()) + } +} + +impl StringOutput { + pub fn new() -> StringOutput { + StringOutput { + buf: Vec::with_capacity(8 * 1024), + } + } + + pub fn into_string(self) -> Result { + String::from_utf8(self.buf) + } +} -- cgit v1.2.3