Skip to main content

Component

Trait Component 

Source
pub trait Component: Send + Sync {
    // Required method
    fn render(&self) -> Node;

    // Provided methods
    fn plain_text(&self) -> Option<String> { ... }
    fn subject(&self) -> Option<&str> { ... }
}
Expand description

The core trait for all Ferrum Email components.

Components are composable building blocks for email templates. Each component defines how it renders to a Node tree, which the renderer then converts to email-safe HTML.

§Examples

use ferrum_email_core::{Component, Node, node::Element, node::Tag};

struct HelloEmail {
    name: String,
}

impl Component for HelloEmail {
    fn render(&self) -> Node {
        Node::text(format!("Hello, {}!", self.name))
    }

    fn subject(&self) -> Option<&str> {
        Some("Hello!")
    }
}

Required Methods§

Source

fn render(&self) -> Node

Render this component into a Node tree.

Provided Methods§

Source

fn plain_text(&self) -> Option<String>

Optional: provide a custom plain text version.

If None, the renderer will auto-extract plain text from the node tree.

Source

fn subject(&self) -> Option<&str>

The email subject line. Only meaningful on top-level email components.

Implementors§