pub struct Preview {
pub name: &'static str,
pub build: fn() -> Result<Email>,
}Expand description
A mailer action shown at /ocre/dev/mailers in ocre dev, rendered with sample data, like Rails’ mailer previews.
name reads mailer/action; build returns the email, usually by
calling the action with sample arguments. ocre g mailer adds one per
action to PREVIEWS in src/mailers/mod.rs. Nothing is sent: the page
shows the headers, the HTML (inline images included) and the text.
§Examples
use ocre::mail::{Email, Preview};
fn welcome(to: &str) -> ocre::Result<Email> {
Ok(Email::new(to, "Welcome", "Hello"))
}
static PREVIEWS: &[Preview] = &[Preview::new("user/welcome", || welcome("ada@example.com"))];
assert_eq!(PREVIEWS[0].name, "user/welcome");Fields§
§name: &'static strmailer/action, e.g. user/welcome; the page’s URL is /ocre/dev/mailers/preview/<name>.
build: fn() -> Result<Email>Builds the email with sample data.
Implementations§
Source§impl Preview
impl Preview
Sourcepub const fn new(name: &'static str, build: fn() -> Result<Email>) -> Self
pub const fn new(name: &'static str, build: fn() -> Result<Email>) -> Self
A preview named mailer/action, built by build.
§Examples
let preview = ocre::mail::Preview::new("user/welcome", || Ok(ocre::mail::Email::new("ada@example.com", "Hi", "Hello")));
assert_eq!((preview.build)().unwrap().subject, "Hi");Trait Implementations§
Auto Trait Implementations§
impl Freeze for Preview
impl RefUnwindSafe for Preview
impl Send for Preview
impl Sync for Preview
impl Unpin for Preview
impl UnsafeUnpin for Preview
impl UnwindSafe for Preview
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more