diff --git a/sailfish/src/lib.rs b/sailfish/src/lib.rs index 165380e..a384741 100644 --- a/sailfish/src/lib.rs +++ b/sailfish/src/lib.rs @@ -42,6 +42,10 @@ pub use runtime::{RenderError, RenderResult}; /// Template that can be rendered with consuming itself. pub trait TemplateOnce: Sized { + /// Render the template and return the rendering result as `RenderResult` + /// + /// This method never returns `Err`, unless you manually implement `Render` trait + /// for custom type and return `Err` inside it. #[inline] fn render_once(self) -> runtime::RenderResult { let mut buf = String::new(); @@ -49,6 +53,7 @@ pub trait TemplateOnce: Sized { Ok(buf) } + /// Render the template and append the result to `buf`. fn render_once_to_string(self, buf: &mut String) -> Result<(), RenderError>; } diff --git a/sailfish/src/runtime/buffer.rs b/sailfish/src/runtime/buffer.rs index 888b000..9ae14fb 100644 --- a/sailfish/src/runtime/buffer.rs +++ b/sailfish/src/runtime/buffer.rs @@ -110,6 +110,9 @@ impl Buffer { self.len = 0; } + /// Converts a `Buffer` into a `String`. + /// + /// This consumes the `Buffer`, so we do not need to copy its contents. #[inline] pub fn into_string(self) -> String { let buf = ManuallyDrop::new(self); diff --git a/sailfish/src/runtime/escape/mod.rs b/sailfish/src/runtime/escape/mod.rs index eccae83..ed6b92f 100644 --- a/sailfish/src/runtime/escape/mod.rs +++ b/sailfish/src/runtime/escape/mod.rs @@ -38,6 +38,19 @@ pub fn escape(feed: &str, buf: &mut Buffer) { } /// default escape function +/// +/// This function appends the escaped contents of `feed` into `buf`. +/// +/// # Examples +/// +/// ``` +/// use sailfish::runtime::Buffer; +/// use sailfish::runtime::escape::escape; +/// +/// let mut buf = Buffer::new(); +/// escape("