Trait mas_templates::TemplateContext

source ·
pub trait TemplateContext: Serialize {
    // Required method
    fn sample(now: DateTime<Utc>, rng: &mut impl Rng) -> Vec<Self>
       where Self: Sized;

    // Provided methods
    fn with_session(self, current_session: BrowserSession) -> WithSession<Self>
       where Self: Sized { ... }
    fn maybe_with_session(
        self,
        current_session: Option<BrowserSession>,
    ) -> WithOptionalSession<Self>
       where Self: Sized { ... }
    fn with_csrf<C>(self, csrf_token: C) -> WithCsrf<Self>
       where Self: Sized,
             C: ToString { ... }
    fn with_language(self, lang: DataLocale) -> WithLanguage<Self>
       where Self: Sized { ... }
    fn with_captcha(self, captcha: Option<CaptchaConfig>) -> WithCaptcha<Self>
       where Self: Sized { ... }
}
Expand description

Helper trait to construct context wrappers

Required Methods§

source

fn sample(now: DateTime<Utc>, rng: &mut impl Rng) -> Vec<Self>
where Self: Sized,

Generate sample values for this context type

This is then used to check for template validity in unit tests and in the CLI (cargo run -- templates check)

Provided Methods§

source

fn with_session(self, current_session: BrowserSession) -> WithSession<Self>
where Self: Sized,

Attach a user session to the template context

source

fn maybe_with_session( self, current_session: Option<BrowserSession>, ) -> WithOptionalSession<Self>
where Self: Sized,

Attach an optional user session to the template context

source

fn with_csrf<C>(self, csrf_token: C) -> WithCsrf<Self>
where Self: Sized, C: ToString,

Attach a CSRF token to the template context

source

fn with_language(self, lang: DataLocale) -> WithLanguage<Self>
where Self: Sized,

Attach a language to the template context

source

fn with_captcha(self, captcha: Option<CaptchaConfig>) -> WithCaptcha<Self>
where Self: Sized,

Attach a CAPTCHA configuration to the template context

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TemplateContext for ()

source§

fn sample(_now: DateTime<Utc>, _rng: &mut impl Rng) -> Vec<Self>
where Self: Sized,

Implementors§

source§

impl TemplateContext for ApiDocContext

source§

impl TemplateContext for AppContext

source§

impl TemplateContext for CompatSsoContext

source§

impl TemplateContext for ConsentContext

source§

impl TemplateContext for DeviceConsentContext

source§

impl TemplateContext for DeviceLinkContext

source§

impl TemplateContext for EmailAddContext

source§

impl TemplateContext for EmailRecoveryContext

source§

impl TemplateContext for EmailVerificationContext

source§

impl TemplateContext for EmailVerificationPageContext

source§

impl TemplateContext for EmptyContext

source§

impl TemplateContext for ErrorContext

source§

impl TemplateContext for IndexContext

source§

impl TemplateContext for LoginContext

source§

impl TemplateContext for NotFoundContext

source§

impl TemplateContext for PolicyViolationContext

source§

impl TemplateContext for ReauthContext

source§

impl TemplateContext for RecoveryExpiredContext

source§

impl TemplateContext for RecoveryFinishContext

source§

impl TemplateContext for RecoveryProgressContext

source§

impl TemplateContext for RecoveryStartContext

source§

impl TemplateContext for RegisterContext

source§

impl TemplateContext for UpstreamExistingLinkContext

source§

impl TemplateContext for UpstreamRegister

source§

impl<T: TemplateContext> TemplateContext for FormPostContext<T>

source§

impl<T: TemplateContext> TemplateContext for WithCaptcha<T>

source§

impl<T: TemplateContext> TemplateContext for WithCsrf<T>

source§

impl<T: TemplateContext> TemplateContext for WithLanguage<T>

source§

impl<T: TemplateContext> TemplateContext for WithOptionalSession<T>

source§

impl<T: TemplateContext> TemplateContext for WithSession<T>