### Combine Trait Usage Example Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.Combine.html Illustrates the conceptual usage of the Combine trait with a rotating buffer, showing how adding a new element shifts the existing elements and appends the new one. ```rust (A, B, C, D).combine(X) -> (B, C, D, X) ``` -------------------------------- ### Get Template Source Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Retrieves a reference to the original source string from which the template was created. ```rust pub fn source(&self) -> &str ``` -------------------------------- ### Get Type ID Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Gets the `TypeId` of the Section. This is a blanket implementation for any type that is 'static. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Ramhorns::from_folder Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Loads all `.html` files as templates from the given folder, making them accessible via their path, joining partials as required. ```APIDOC ## Ramhorns::from_folder>(dir: P) -> Result ### Description Loads all the `.html` files as templates from the given folder, making them accessible via their path, joining partials as required. If a custom extension is wanted, see [from_folder_with_extension] ### Method `pub fn from_folder>(dir: P) -> Result` ### Parameters #### Path Parameters - **dir** (P: AsRef) - Required - The directory path to load templates from. ### Request Example ```rust let tpls: Ramhorns = Ramhorns::from_folder("./templates").unwrap(); let content = "I am the content"; let rendered = tpls.get("hello.html").unwrap().render(&content); ``` ### Response #### Success Response (Result) - **Self**: An instance of Ramhorns containing the loaded templates. - **Error**: An error if loading fails. ``` -------------------------------- ### Load Templates from Folder Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Loads all .html files as templates from a specified folder. Templates are accessible by their path, with partials joined as required. Ensure the folder exists and contains valid HTML files. ```rust let tpls: Ramhorns = Ramhorns::from_folder("./templates").unwrap(); let content = "I am the content"; let rendered = tpls.get("hello.html").unwrap().render(&content); ``` -------------------------------- ### capacity_hint Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Provides an estimated capacity needed for the content given a template. This is useful for pre-allocating memory. ```rust fn capacity_hint(&self, _tpl: &Template<'_>) -> usize ``` -------------------------------- ### Render Template to File Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Renders the template directly to a file specified by a path. Requires the path to be convertible to AsRef. ```rust pub fn render_to_file(&self, path: P, content: &C) -> Result<()> where P: AsRef, C: Content ``` -------------------------------- ### Load Templates with Custom Extension Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Loads templates from a folder using a specified file extension. This is useful when templates are not in .html format. Partials are joined as required. Ensure the folder exists and contains files with the specified extension. ```rust let tpls: Ramhorns = Ramhorns::from_folder_with_extension("./templates", "mustache").unwrap(); let content = "I am the content"; let rendered = tpls.get("hello.mustache").unwrap().render(&content); ``` -------------------------------- ### Ramhorns::from_folder_with_extension Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Loads all files with the specified extension from the given folder as templates. ```APIDOC ## Ramhorns::from_folder_with_extension>(dir: P, extension: &str) -> Result ### Description Loads all files with the extension given in the `extension` parameter as templates from the given folder, making them accessible via their path, joining partials as required. ### Method `pub fn from_folder_with_extension>(dir: P, extension: &str) -> Result` ### Parameters #### Path Parameters - **dir** (P: AsRef) - Required - The directory path to load templates from. - **extension** (&str) - Required - The file extension to filter templates by. ### Request Example ```rust let tpls: Ramhorns = Ramhorns::from_folder_with_extension("./templates", "mustache").unwrap(); let content = "I am the content"; let rendered = tpls.get("hello.mustache").unwrap().render(&content); ``` ### Response #### Success Response (Result) - **Self**: An instance of Ramhorns containing the loaded templates. - **Error**: An error if loading fails. ``` -------------------------------- ### Create Template from Source Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Creates a new Template from a given source string. If the source is a &str, it's borrowed; if it's a String, ownership is taken. ```rust pub fn new(source: S) -> Result where S: Into> ``` -------------------------------- ### Ramhorns::from_file Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Retrieves a template by name, loading it from file if it doesn't exist. ```APIDOC ## Ramhorns::from_file(&mut self, name: &str) -> Result<&Template<'static>, Error> ### Description Get the template with the given name. If the template doesn’t exist, it will be loaded from file and parsed first. Use this method in tandem with `lazy`. ### Method `pub fn from_file(&mut self, name: &str) -> Result<&Template<'static>, Error>` ### Parameters #### Path Parameters - **name** (&str) - Required - The name of the template to retrieve or load. ### Response #### Success Response (Result<&Template<'static>, Error>) - **&Template<'static>**: A reference to the template. - **Error**: An error if loading or parsing fails. ``` -------------------------------- ### Render Template with Data - Ramhorns Source: https://docs.rs/ramhorns Demonstrates how to define Rust structs with the `Content` derive macro, create a Mustache template string, and render it with data. Ensure the `ramhorns` crate is added as a dependency. ```rust use ramhorns::{Template, Content}; #[derive(Content)] struct Post<'a> { title: &'a str, teaser: &'a str, } #[derive(Content)] struct Blog<'a> { title: String, // Strings are cool posts: Vec>, // &'a [Post<'a>] would work too } // Standard Mustache action here let source = "

{{title}}

" + "{{#posts}}

{{title}}

{{teaser}}

{{/posts}}" + "{{^posts}}

No posts yet :(

{{/posts}}"; let tpl = Template::new(source).unwrap(); let rendered = tpl.render(&Blog { title: "My Awesome Blog!".to_string(), posts: vec![ Post { title: "How I tried Ramhorns and found love 💖", teaser: "This can happen to you too", }, Post { title: "Rust is kinda awesome", teaser: "Yes, even the borrow checker! 🦀", }, ] }); assert_eq!(rendered, "

My Awesome Blog!

" + "
" + "

How I tried Ramhorns and found love 💖

" + "

This can happen to you too

" + "
" + "
" + "

Rust is kinda awesome

" + "

Yes, even the borrow checker! 🦀

" + "
"); ``` -------------------------------- ### Template::render_to_file Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Renders the template to a file using the provided Content. ```APIDOC ## Template::render_to_file(&self, path: P, content: &C) -> Result<()> ### Description Render this `Template` with a given `Content` to a file. ### Parameters #### Path Parameters - **path** (P) - Required - The path to the file where the template will be rendered. - **content** (&C) - Required - The content implementing the `Content` trait to render with. ### Returns - `Result<()>` - Ok(()) on success, or an error if rendering fails. ``` -------------------------------- ### Create Section From Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Creates a Section from a value. This is a blanket implementation of the From trait. ```rust fn from(t: T) -> T ``` -------------------------------- ### Template::new Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Creates a new Template from a source string. The source can be borrowed or owned. ```APIDOC ## Template::new(source: S) -> Result ### Description Create a new `Template` out of the source. * If `source` is a `&str`, this `Template` will borrow it with appropriate lifetime. * If `source` is a `String`, this `Template` will take it’s ownership (The `'tpl` lifetime will be `'static`). ### Parameters #### Path Parameters - **source** (S) - Required - The input string to create the template from. ``` -------------------------------- ### Template::render Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Renders the template to a String using the provided Content. ```APIDOC ## Template::render(&self, content: &C) -> String ### Description Render this `Template` with a given `Content` to a `String`. ### Parameters #### Path Parameters - **content** (&C) - Required - The content implementing the `Content` trait to render with. ### Returns - `String` - The rendered template as a string. ``` -------------------------------- ### Template::capacity_hint Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Estimates the buffer size needed for rendering the template. ```APIDOC ## Template::capacity_hint(&self) -> usize ### Description Estimate how big of a buffer should be allocated to render this `Template`. ### Returns - `usize` - An estimated capacity for the rendering buffer. ``` -------------------------------- ### Render Mustache Template with Rust Data Source: https://docs.rs/ramhorns/latest/ramhorns/index.html Demonstrates how to define Rust structs with the `Content` derive macro, create a Mustache template string, and render it with data. Ensure the `Content` trait is derived for your data structures. ```rust use ramhorns::{Template, Content}; #[derive(Content)] struct Post<'a> { title: &'a str, teaser: &'a str, } #[derive(Content)] struct Blog<'a> { title: String, // Strings are cool posts: Vec> // &'a [Post<'a>] would work too } // Standard Mustache action here let source = "

{{title}}

\ {{#posts}}

{{title}}

{{teaser}}

{{/posts}}\ {{^posts}}

No posts yet :(

{{/posts}}"; let tpl = Template::new(source).unwrap(); let rendered = tpl.render(&Blog { title: "My Awesome Blog!".to_string(), posts: vec![ Post { title: "How I tried Ramhorns and found love 💖", teaser: "This can happen to you too", }, Post { title: "Rust is kinda awesome", teaser: "Yes, even the borrow checker! 🦀", }, ] }); assert_eq!(rendered, "

My Awesome Blog!

\
\

How I tried Ramhorns and found love 💖

\

This can happen to you too

\
\
\

Rust is kinda awesome

\

Yes, even the borrow checker! 🦀

\
"); ``` -------------------------------- ### capacity_hint Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Provides a hint about the likely capacity required for the content during rendering. ```APIDOC ## fn capacity_hint(&self, _tpl: &Template<'_>) -> usize ### Description How much capacity is _likely_ required for all the data in this `Content` for a given `Template`. ### Signature ```rust fn capacity_hint(&self, _tpl: &Template<'_>) -> usize ``` ``` -------------------------------- ### Derive Content Macro Usage Source: https://docs.rs/ramhorns/latest/ramhorns/derive.Content.html Illustrates the basic usage of the `#[derive(Content)]` macro and its available attributes like `#[md]` and `#[ramhorns]` for content processing. ```rust #[derive(Content)] { // Attributes available to this derive: #[md] #[ramhorns] } ``` -------------------------------- ### render_section Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders a section with the provided content. ```APIDOC ## fn render_section( &self, section: Section<'_, C>, encoder: &mut E, ) -> Result<(), E::Error> where C: ContentSequence, E: Encoder, ### Description Render a section with self. ### Signature ```rust fn render_section(&self, section: Section<'_, C>, encoder: &mut E) -> Result<(), E::Error> where C: ContentSequence, E: Encoder ``` ``` -------------------------------- ### Section::with Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Attaches a `Content` to the current section, maintaining a stack of up to 4 `Content` items. ```APIDOC ## Section::with ### Description Attach a `Content` to this section. This will keep track of a stack up to 4 `Content`s deep, cycling on overflow. ### Signature ```rust pub fn with( self, content: &X, ) -> Section<'section, (::I, ::J, ::K, &X)> where X: Content + ?Sized ``` ``` -------------------------------- ### ContentSequence Implementation for Tuple (A, B, C, D) Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Provides a ContentSequence implementation for tuples of four elements, where each element must also implement Content and Copy. This allows tuples to be used directly in templating contexts. ```rust impl ContentSequence for (A, B, C, D) where A: Content + Copy, B: Content + Copy, C: Content + Copy, D: Content + Copy ``` -------------------------------- ### Ramhorns::get Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Retrieves a template by its name. ```APIDOC ## Ramhorns::get(&self, name: &str) -> Option<&Template<'static>> ### Description Get the template with the given name, if it exists. ### Method `pub fn get(&self, name: &str) -> Option<&Template<'static>>` ### Parameters #### Path Parameters - **name** (&str) - Required - The name of the template to retrieve. ### Response #### Success Response (Option<&Template<'static>>) - **&Template<'static>**: A reference to the template if found. - **None**: If the template is not found. ``` -------------------------------- ### Template::source Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Retrieves a reference to the original source string used to create the template. ```APIDOC ## Template::source(&self) -> &str ### Description Get a reference to a source this `Template` was created from. ### Returns - `&str` - A string slice referencing the original template source. ``` -------------------------------- ### Render Template to String Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Renders the template into a String using the provided Content. Ensure the Content trait is implemented for the data type. ```rust pub fn render(&self, content: &C) -> String ``` -------------------------------- ### Template::render_to_writer Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Renders the template to a writer using the provided Content. ```APIDOC ## Template::render_to_writer(&self, writer: &mut W, content: &C) -> Result<()> ### Description Render this `Template` with a given `Content` to a writer. ### Parameters #### Path Parameters - **writer** (&mut W) - Required - A mutable reference to a writer implementing the `Write` trait. - **content** (&C) - Required - The content implementing the `Content` trait to render with. ### Returns - `Result<()>` - Ok(()) on success, or an error if rendering fails. ``` -------------------------------- ### Clone to Uninit Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Performs copy-assignment from the Section to uninitialized memory. This is a nightly-only experimental API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Clone Section From Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Performs copy-assignment from a source Section to this Section. This is part of the Clone trait implementation. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Ramhorns::extend_from_folder_with_extension Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Extends the template collection with files with a specified extension from the given folder. ```APIDOC ## Ramhorns::extend_from_folder_with_extension>(&mut self, dir: P, extension: &str) -> Result<(), Error> ### Description Extends the template collection with files with `extension` from the given folder, making them accessible via their path, joining partials as required. If there is a file with the same name as a previously loaded template or partial, it will not be loaded. ### Method `pub fn extend_from_folder_with_extension>(&mut self, dir: P, extension: &str) -> Result<(), Error>` ### Parameters #### Path Parameters - **dir** (P: AsRef) - Required - The directory path to load templates from. - **extension** (&str) - Required - The file extension to filter templates by. ### Response #### Success Response (Result<(), Error>) - **()**: Indicates success. - **Error**: An error if loading fails. ``` -------------------------------- ### Estimate Render Buffer Size Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Provides an estimate of the buffer size needed for rendering the template. This can be used for pre-allocating memory. ```rust pub fn capacity_hint(&self) -> usize ``` -------------------------------- ### Render Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Renders the section's content to the provided Encoder. This method is essential for outputting the section's content. ```rust pub fn render(&self, encoder: &mut E) -> Result<(), E::Error> where E: Encoder, ``` -------------------------------- ### Ramhorns::extend_from_folder Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Extends the template collection with files with `.html` extension from the given folder. ```APIDOC ## Ramhorns::extend_from_folder>(&mut self, dir: P) -> Result<(), Error> ### Description Extends the template collection with files with `.html` extension from the given folder, making them accessible via their path, joining partials as required. If there is a file with the same name as a previously loaded template or partial, it will not be loaded. ### Method `pub fn extend_from_folder>(&mut self, dir: P) -> Result<(), Error>` ### Parameters #### Path Parameters - **dir** (P: AsRef) - Required - The directory path to load templates from. ### Response #### Success Response (Result<(), Error>) - **()**: Indicates success. - **Error**: An error if loading fails. ``` -------------------------------- ### Lazy Template Loading Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Creates an empty Ramhorns aggregator for a given folder, deferring actual template loading until a template is requested via `from_file`. This is efficient for scenarios where not all templates might be used. Ensure the folder path is valid. ```rust let mut tpls: Ramhorns = Ramhorns::lazy("./templates").unwrap(); let content = "I am the content"; let rendered = tpls.from_file("hello.html").unwrap().render(&content); ``` -------------------------------- ### Section::render Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Renders the section's content to a provided `Encoder`. ```APIDOC ## Section::render ### Description Render this section once to the provided `Encoder`. ### Signature ```rust pub fn render(&self, encoder: &mut E) -> Result<(), E::Error> where E: Encoder ``` ``` -------------------------------- ### Render Field Section Method Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Renders a field as a section using its hash or string name. This is useful for rendering blocks of content that may contain other template logic. ```rust fn render_field_section( &self, _hash: u64, _name: &str, _section: Section<'_, P>, _encoder: &mut E, ) -> Result<(), E::Error> where P: ContentSequence, E: Encoder ``` -------------------------------- ### Insert Template from String Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Inserts a template parsed from a source string with a given name. If a template with the same name already exists, it will be replaced. Use with caution as this can load partials from arbitrary paths; only use with trusted sources. ```rust insert(&mut self, src: S, name: T) -> Result<(), Error> where S: Into>, T: Into>, ``` -------------------------------- ### render_section Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders a section of content. This method is part of the core rendering logic for template sections. ```rust fn render_section( &self, section: Section<'_, C>, encoder: &mut E, ) -> Result<(), E::Error> where C: ContentSequence, E: Encoder ``` -------------------------------- ### Tuple (A, B, C, D) render_field_section Implementation Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Implements the render_field_section method for a tuple of four elements. It delegates the rendering to the individual elements within the tuple. ```rust fn render_field_section( &self, hash: u64, name: &str, section: Section<'_, P>, encoder: &mut E, ) -> Result<(), E::Error> where P: ContentSequence, E: Encoder ``` -------------------------------- ### render_field_section Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders a specific field as a section by name or hash. Returns true if the field exists. ```rust fn render_field_section( &self, _hash: u64, _name: &str, _section: Section<'_, C>, _encoder: &mut E, ) -> Result where C: ContentSequence, E: Encoder ``` -------------------------------- ### Try Convert Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Attempts to convert a value into a Section. This is a blanket implementation of the TryFrom trait. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Ramhorns::lazy Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Creates a new empty aggregator for a given folder, loading templates only when needed. ```APIDOC ## Ramhorns::lazy>(dir: P) -> Result ### Description Create a new empty aggregator for a given folder. This won’t do anything until a template has been added using `from_file`. ### Method `pub fn lazy>(dir: P) -> Result` ### Parameters #### Path Parameters - **dir** (P: AsRef) - Required - The directory path for the aggregator. ### Request Example ```rust let mut tpls: Ramhorns = Ramhorns::lazy("./templates").unwrap(); let content = "I am the content"; let rendered = tpls.from_file("hello.html").unwrap().render(&content); ``` ### Response #### Success Response (Result) - **Self**: An empty Ramhorns aggregator. - **Error**: An error if initialization fails. ``` -------------------------------- ### render_inverse Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders an inverse section with the provided content. ```APIDOC ## fn render_inverse( &self, section: Section<'_, C>, encoder: &mut E, ) -> Result<(), E::Error> where C: ContentSequence, E: Encoder, ### Description Render a section with self. ### Signature ```rust fn render_inverse(&self, section: Section<'_, C>, encoder: &mut E) -> Result<(), E::Error> where C: ContentSequence, E: Encoder ``` ``` -------------------------------- ### Tuple (A, B, C, D) render_field_inverse Implementation Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Implements the render_field_inverse method for a tuple of four elements. It delegates the rendering to the individual elements within the tuple. ```rust fn render_field_inverse( &self, hash: u64, name: &str, section: Section<'_, P>, encoder: &mut E, ) -> Result<(), E::Error> where P: ContentSequence, E: Encoder ``` -------------------------------- ### Render Template to Writer Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Renders the template to a mutable writer implementing the Write trait. This is useful for streaming output. ```rust pub fn render_to_writer(&self, writer: &mut W, content: &C) -> Result<()> where W: Write, C: Content ``` -------------------------------- ### try_into Function Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html The `try_into` method attempts to perform a conversion from the current type `T` to a target type `U`. It returns a `Result` which is `Ok(U)` on success or `Err(>::Error)` on failure. ```APIDOC #### fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### Clone Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Creates a duplicate of the Section. This implementation is available when the Contents are Clone. ```rust fn clone(&self) -> Section<'section, Contents> ``` -------------------------------- ### Implement Debug for Template Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Provides a Debug implementation for the Template struct, allowing it to be formatted for debugging purposes. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### Try Into Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Attempts to convert the Section into another type. This is a blanket implementation of the TryInto trait. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### render_field_section Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Render a field by the hash or string of its name as a section. ```APIDOC ## fn render_field_section( &self, _hash: u64, _name: &str, _section: Section<'_, P>, _encoder: &mut E, ) -> Result<(), E::Error> where P: ContentSequence, E: Encoder ``` -------------------------------- ### render_escaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders the content to an encoder, escaping HTML characters. Use this for safe display of variables. ```rust fn render_escaped( &self, _encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### Attach Content to Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Attaches a new Content to the section, maintaining a stack of up to 4 Content items. This method is useful for building up complex sections incrementally. ```rust pub fn with( self, content: &X, ) -> Section<'section, (::I, ::J, ::K, &X)> where X: Content + ?Sized, ``` -------------------------------- ### Combine Trait Implementation for (A, B, C, D) Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.Combine.html Implementation of the Combine trait for a tuple of four elements, where each element satisfies the Content and Copy traits. ```APIDOC ### impl Combine for (A, B, C, D) where A: Content + Copy, B: Content + Copy, C: Content + Copy, D: Content + Copy, #### Associated Types * **type I = B** * **type J = C** * **type K = D** * **type Previous = ((), A, B, C)** #### Methods * **fn combine(self, other: &X) -> (B, C, D, &X)** * **fn crawl_back(self) -> ((), A, B, C)** ``` -------------------------------- ### write_html Method Source: https://docs.rs/ramhorns/latest/ramhorns/encoding/trait.Encoder.html This method is used to write HTML content generated from an iterator of pulldown_cmark Event types. It handles the conversion of these events into a safe HTML output. ```rust fn write_html<'a, I: Iterator>>( &mut self, iter: I, ) -> Result<(), Self::Error> ``` -------------------------------- ### is_truthy Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Determines if the content is considered truthy, typically used when rendering sections. ```rust fn is_truthy(&self) -> bool ``` -------------------------------- ### Render Field Inverse Section Method Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Renders a field as an inverse section using its hash or string name. This is typically used for displaying content when a condition is false. ```rust fn render_field_inverse( &self, _hash: u64, _name: &str, _section: Section<'_, P>, _encoder: &mut E, ) -> Result<(), E::Error> where P: ContentSequence, E: Encoder ``` -------------------------------- ### Implement TryInto for U Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Blanket implementation of the TryInto trait for attempting to convert type T into type U, provided U implements TryFrom. ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Into Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Converts the Section into another type. This is a blanket implementation of the Into trait. ```rust fn into(self) -> U ``` -------------------------------- ### Combine Trait Implementation for () Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.Combine.html Provides a basic implementation of the Combine trait for the unit type `()`, where all associated types and the combine/crawl_back methods return the unit type. ```rust impl Combine for () { type I = (); type J = (); type K = (); type Previous = (); fn combine(self, other: &X) -> ((), (), (), &X) { // Implementation details omitted for brevity } fn crawl_back(self) -> Self::Previous { // Implementation details omitted for brevity } } ``` -------------------------------- ### format_unescaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/encoding/trait.Encoder.html Writes a value that implements the Display trait to the encoder in plain mode, without escaping HTML characters. ```rust fn format_unescaped( &mut self, display: D, ) -> Result<(), Self::Error> ``` -------------------------------- ### Combine Trait Implementation for () Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.Combine.html Implementation of the Combine trait for the unit type `()`. ```APIDOC ### impl Combine for () #### Associated Types * **type I = ()** * **type J = ()** * **type K = ()** * **type Previous = ()** #### Methods * **fn combine(self, other: &X) -> ((), (), (), &X)** * **fn crawl_back(self) -> Self::Previous** ``` -------------------------------- ### render_unescaped Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders the content as a variable without any HTML escaping. ```APIDOC ## fn render_unescaped(&self, encoder: &mut E) -> Result<(), E::Error> ### Description Renders self as a variable to the encoder. This doesn’t perform any escaping at all. ### Signature ```rust fn render_unescaped(&self, encoder: &mut E) -> Result<(), E::Error> ``` ``` -------------------------------- ### render_unescaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders the content to an encoder without any HTML escaping. Use with caution when the content is trusted. ```rust fn render_unescaped( &self, encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### Define Section Struct Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Defines the Section struct, which holds a sequence of content to be rendered. It is generic over the content type. ```rust pub struct Section<'section, Contents: ContentSequence> { /* private fields */ } ``` -------------------------------- ### Content Trait Definition Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Defines the Content trait with various rendering methods. Most users will not need to implement this directly, as `#[derive(Content)]` is usually sufficient. ```rust pub trait Content { // Provided methods fn is_truthy(&self) -> bool { ... } fn capacity_hint(&self, _tpl: &Template<'_>) -> usize { ... } fn render_escaped( &self, _encoder: &mut E, ) -> Result<(), E::Error> { ... } fn render_unescaped( &self, encoder: &mut E, ) -> Result<(), E::Error> { ... } fn render_section( &self, section: Section<'_, C>, encoder: &mut E, ) -> Result<(), E::Error> where C: ContentSequence, E: Encoder { ... } fn render_inverse( &self, section: Section<'_, C>, encoder: &mut E, ) -> Result<(), E::Error> where C: ContentSequence, E: Encoder { ... } fn render_field_escaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result { ... } fn render_field_unescaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result { ... } fn render_field_section( &self, _hash: u64, _name: &str, _section: Section<'_, C>, _encoder: &mut E, ) -> Result where C: ContentSequence, E: Encoder { ... } fn render_field_inverse( &self, _hash: u64, _name: &str, _section: Section<'_, C>, _encoder: &mut E, ) -> Result where C: ContentSequence, E: Encoder { ... } } ``` -------------------------------- ### render_escaped Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders the content as a variable, escaping HTML characters. ```APIDOC ## fn render_escaped(&self, _encoder: &mut E) -> Result<(), E::Error> ### Description Renders self as a variable to the encoder. This will escape HTML characters, eg: `<` will become `<`. ### Signature ```rust fn render_escaped(&self, _encoder: &mut E) -> Result<(), E::Error> ``` ``` -------------------------------- ### String Encoder Implementation Source: https://docs.rs/ramhorns/latest/ramhorns/encoding/trait.Encoder.html Demonstrates the implementation of the Encoder trait for the standard String type. The associated error type is NeverError. ```rust impl Encoder for String { type Error = NeverError; fn write_unescaped(&mut self, part: &str) -> Result<(), Self::Error> fn write_escaped(&mut self, part: &str) -> Result<(), Self::Error> fn write_html<'a, I: Iterator>>( &mut self, iter: I, ) -> Result<(), Self::Error> fn format_unescaped( &mut self, display: D, ) -> Result<(), Self::Error> fn format_escaped(&mut self, display: D) -> Result<(), Self::Error> } ``` -------------------------------- ### format_escaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/encoding/trait.Encoder.html Writes a value that implements the Display trait to the encoder, escaping special HTML characters. ```rust fn format_escaped(&mut self, display: D) -> Result<(), Self::Error> ``` -------------------------------- ### render_inverse Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders the inverse of a section. This is used for conditional logic within templates. ```rust fn render_inverse( &self, section: Section<'_, C>, encoder: &mut E, ) -> Result<(), E::Error> where C: ContentSequence, E: Encoder ``` -------------------------------- ### Ramhorns::insert Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Ramhorns.html Inserts a template parsed from a string source with a given name. ```APIDOC ## Ramhorns::insert(&mut self, src: S, name: T) -> Result<(), Error> ### Description Insert a template parsed from `src` with the name `name`. If a template with this name is present, it gets replaced. ### Warning This can load partials from an arbitrary path. Use only with trusted source. ### Method `pub fn insert(&mut self, src: S, name: T) -> Result<(), Error>` ### Parameters #### Path Parameters - **src** (S: Into>) - Required - The template content as a string. - **name** (T: Into>) - Required - The name to assign to the template. ### Response #### Success Response (Result<(), Error>) - **()**: Indicates success. - **Error**: An error if insertion fails. ``` -------------------------------- ### is_truthy Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Marks whether this content is truthy. Used when attempting to render a section. ```APIDOC ## fn is_truthy(&self) -> bool ### Description Marks whether this content is truthy. Used when attempting to render a section. ### Signature ```rust fn is_truthy(&self) -> bool ``` ``` -------------------------------- ### Tuple (A, B, C, D) render_field_unescaped Implementation Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Implements the render_field_unescaped method for a tuple of four elements. It delegates the rendering to the individual elements within the tuple. ```rust fn render_field_unescaped( &self, hash: u64, name: &str, encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### Render Field Unescaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Renders a field using its hash or string name without any HTML escaping. Use this cautiously when you are certain the content is safe or when raw output is required. ```rust fn render_field_unescaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### Render Field Escaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Renders a field using its hash or string name, escaping HTML characters. Use this when you need to display field content safely in an HTML context. ```rust fn render_field_escaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### Borrow Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Immutably borrows the Section. This is a blanket implementation for borrowing any type. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### Tuple (A, B, C, D) render_field_escaped Implementation Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Implements the render_field_escaped method for a tuple of four elements. It delegates the rendering to the individual elements within the tuple. ```rust fn render_field_escaped( &self, hash: u64, name: &str, encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### Section::without_first Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Returns a new Section instance without the first `Block` in its stack. ```APIDOC ## Section::without_first ### Description The section without the first `Block` in the stack. ### Signature ```rust pub fn without_first(self) -> Self ``` ``` -------------------------------- ### Combine Trait Implementation for (A, B, C, D) Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.Combine.html Implements the Combine trait for a 4-tuple, defining associated types and methods to manage the rotating buffer behavior for generic types A, B, C, and D. ```rust impl Combine for (A, B, C, D) where A: Content + Copy, B: Content + Copy, C: Content + Copy, D: Content + Copy, { type I = B; type J = C; type K = D; type Previous = ((), A, B, C); fn combine(self, other: &X) -> (B, C, D, &X) { // Implementation details omitted for brevity } fn crawl_back(self) -> ((), A, B, C) { // Implementation details omitted for brevity } } ``` -------------------------------- ### render_field_escaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders a specific field by name or hash, escaping HTML characters. Returns true if the field exists. ```rust fn render_field_escaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result ``` -------------------------------- ### Define Template Struct Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Defines the Template struct, which holds a preprocessed template ready for rendering. It is generic over a lifetime parameter 'tpl. ```rust pub struct Template<'tpl> { /* private fields */ } ``` -------------------------------- ### render_field_inverse Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders a specific field as an inverse section by name or hash. Returns true if the field exists. ```rust fn render_field_inverse( &self, _hash: u64, _name: &str, _section: Section<'_, C>, _encoder: &mut E, ) -> Result where C: ContentSequence, E: Encoder ``` -------------------------------- ### Combine Trait Definition Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.Combine.html Defines the associated types and methods for the Combine trait. ```APIDOC ## Trait Combine ### Summary Helper trait used to rotate a queue of parent `Content`s. Think of this as of a rotating buffer such that: ``` (A, B, C, D).combine(X) -> (B, C, D, X) ``` This allows us to keep track of up to 3 parent contexts. The constraint is implemented so that self-referencing `Content`s don’t blow up the stack on compilation. ### Associated Types * **type I: Content + Copy + Sized** First type for the result tuple * **type J: Content + Copy + Sized** Second type for the result tuple * **type K: Content + Copy + Sized** Third type for the result tuple * **type Previous: ContentSequence** Type when we crawl back one item ### Methods * **fn combine(self, other: &X) -> (Self::I, Self::J, Self::K, &X)** Combines current tuple with a new element. * **fn crawl_back(self) -> Self::Previous** Crawl back to the previous tuple ``` -------------------------------- ### render_field_unescaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Renders a specific field by name or hash without HTML escaping. Returns true if the field exists. ```rust fn render_field_unescaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result ``` -------------------------------- ### Implement TryFrom for T Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Template.html Blanket implementation of the TryFrom trait for attempting to convert type U into type T. The Error type is Infallible. ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### render_field_inverse Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Render a field by the hash or string of its name as an inverse section. ```APIDOC ## fn render_field_inverse( &self, _hash: u64, _name: &str, _section: Section<'_, P>, _encoder: &mut E, ) -> Result<(), E::Error> where P: ContentSequence, E: Encoder ``` -------------------------------- ### render_field_unescaped Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Render a field by the hash or string of its name without any escaping. ```APIDOC ## fn render_field_unescaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### To Owned Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Creates owned data from the Section, usually by cloning. This is part of the ToOwned trait. ```rust fn to_owned(&self) -> T ``` -------------------------------- ### write_escaped Method Source: https://docs.rs/ramhorns/latest/ramhorns/encoding/trait.Encoder.html Implementations of this method should write a string slice to the encoder, escaping special HTML characters such as <, >, and &. ```rust fn write_escaped(&mut self, part: &str) -> Result<(), Self::Error> ``` -------------------------------- ### Content for bool: render_escaped Source: https://docs.rs/ramhorns/latest/ramhorns/trait.Content.html Implementation of render_escaped for the boolean type. ```rust fn render_escaped(&self, encoder: &mut E) -> Result<(), E::Error> ``` -------------------------------- ### render_field_escaped Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.ContentSequence.html Render a field by the hash or string of its name, escaping HTML characters. ```APIDOC ## fn render_field_escaped( &self, _hash: u64, _name: &str, _encoder: &mut E, ) -> Result<(), E::Error> ``` -------------------------------- ### Borrow Mutably Section Source: https://docs.rs/ramhorns/latest/ramhorns/struct.Section.html Mutably borrows the Section. This is a blanket implementation for mutable borrowing. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### Error Enum Variants Source: https://docs.rs/ramhorns/latest/ramhorns/enum.Error.html The Error enum includes variants for IO errors, stack overflows during nested section parsing, issues with unclosed or unopened sections, unclosed tags, disabled partials, illegal partial usage, and file not found errors. ```APIDOC ## Enum Error ### Variants - **Io(Error)**: There was an error with the IO (only happens when parsing a file). - **StackOverflow**: Stack overflow when parsing nested sections. - **UnclosedSection(Box)**: Parser was expecting a tag closing a section `{{/foo}}`, but never found it or found a different one. - **UnopenedSection(Box)**: Similar to above, but happens if `{{/foo}}` happens while no section was open. - **UnclosedTag**: Parser was expecting to find the closing braces of a tag `}}`, but never found it. - **PartialsDisabled**: Partials are not allowed in the given context (e.g. parsing a template from string). - **IllegalPartial(Box)**: Attempted to load a partial outside of the templates folder. - **NotFound(Box)**: The template file with the given name was not found. ``` -------------------------------- ### Combine Trait Definition Source: https://docs.rs/ramhorns/latest/ramhorns/traits/trait.Combine.html Defines the structure and methods for the Combine trait, including associated types for tuple elements and a Previous type, and methods for combining and crawling back. ```rust pub trait Combine { type I: Content + Copy + Sized; type J: Content + Copy + Sized; type K: Content + Copy + Sized; type Previous: ContentSequence; // Required methods fn combine( self, other: &X, ) -> (Self::I, Self::J, Self::K, &X); fn crawl_back(self) -> Self::Previous; } ```