pub struct TemplateInner<G: Html> {
    pub is_capsule: bool,
    /* private fields */
}
Expand description

The internal representation of a Perseus template, with all the methods involved in creating and managing it. As this struct is not Clone, it will almost always appear wrapped in a full Template, which allows cloning and passing the template around arbitrarily. As that dereferences to this, you will be able to use any of the methods on this struct on Template.

Fields§

§is_capsule: bool

Whether or not this template is actually a capsule. This impacts significant aspects of internal handling.

There is absolutely no circumstance in which you should ever change this. Ever. You will break your app. Always.

Implementations§

source§

impl<G: Html> TemplateInner<G>

source

pub fn get_path(&self) -> String

Gets the path of the template. This is the root path under which any generated pages will be served. In the simplest case, there will only be one page rendered, and it will occupy that root position.

Note that this will automatically transform index to an empty string.

Note that this will prepend __capsule/ to any capsules automatically.

source

pub fn get_revalidate_interval(&self) -> Option<ComputedDuration>

Gets the interval after which the template will next revalidate.

source

pub fn revalidates(&self) -> bool

Checks if this template can revalidate existing prerendered templates.

source

pub fn revalidates_with_time(&self) -> bool

Checks if this template can revalidate existing prerendered templates after a given time.

source

pub fn revalidates_with_logic(&self) -> bool

Checks if this template can revalidate existing prerendered templates based on some given logic.

source

pub fn uses_incremental(&self) -> bool

Checks if this template can render more templates beyond those paths it explicitly defines.

source

pub fn uses_build_paths(&self) -> bool

Checks if this template is a template to generate paths beneath it.

source

pub fn uses_request_state(&self) -> bool

Checks if this template needs to do anything on requests for it.

source

pub fn uses_build_state(&self) -> bool

Checks if this template needs to do anything at build time.

source

pub fn can_amalgamate_states(&self) -> bool

Checks if this template has custom logic to amalgamate build and request states if both are generated.

source

pub fn is_basic(&self) -> bool

Checks if this template defines no rendering logic whatsoever. Such templates will be rendered using SSG. Basic templates can still modify headers (which could hypothetically be using global state that’s dependent on server-side generation).

source§

impl<G: Html> TemplateInner<G>

source

pub fn head<V: Into<GeneratorResult<View<SsrNode>>>>( self, val: impl Fn(Scope<'_>) -> V + Send + Sync + 'static ) -> Self

Sets the document <head> rendering function to use. The [View] produced by this will only be rendered on the engine-side, and will not be reactive (since it only contains metadata).

This is for heads that do not require state. Those that do should use .head_with_state() instead.

source

pub fn head(self, _val: impl Fn() + 'static) -> Self

Sets the document <head> rendering function to use. The [View] produced by this will only be rendered on the engine-side, and will not be reactive (since it only contains metadata).

This is for heads that do not require state. Those that do should use .head_with_state() instead.

source

pub fn set_headers<V: Into<GeneratorResult<HeaderMap>>>( self, val: impl Fn(Scope<'_>) -> V + Send + Sync + 'static ) -> Self

Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting does not need state.

source

pub fn set_headers(self, _val: impl Fn() + 'static) -> Self

Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting does not need state.

source

pub fn build_paths_fn<V: Into<GeneratorResult<BuildPaths>>>( self, val: impl GetBuildPathsUserFnType<V> + Clone + Send + Sync + 'static ) -> Self

Enables the build paths strategy with the given function.

source

pub fn build_paths_fn(self, _val: impl Fn() + 'static) -> Self

Enables the build paths strategy with the given function.

source

pub fn incremental_generation(self) -> Self

Enables the incremental generation strategy.

source

pub fn incremental_generation(self) -> Self

Enables the incremental generation strategy.

source

pub fn build_state_fn<S, B, V>( self, val: impl GetBuildStateUserFnType<S, B, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,

Enables the build state strategy with the given function.

source

pub fn build_state_fn(self, _val: impl Fn() + 'static) -> Self

Enables the build state strategy with the given function.

source

pub fn request_state_fn<S, B, V>( self, val: impl GetRequestStateUserFnType<S, B, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,

Enables the request state strategy with the given function.

source

pub fn request_state_fn(self, _val: impl Fn() + 'static) -> Self

Enables the request state strategy with the given function.

source

pub fn should_revalidate_fn<B, V>( self, val: impl ShouldRevalidateUserFnType<B, V> + Clone + Send + Sync + 'static ) -> Selfwhere B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<bool>>,

Enables the revalidation strategy (logic variant) with the given function.

source

pub fn should_revalidate_fn(self, _val: impl Fn() + 'static) -> Self

Enables the revalidation strategy (logic variant) with the given function.

source

pub fn revalidate_after<I: PerseusDuration>(self, val: I) -> Self

Enables the revalidation strategy (time variant). This takes a time string of a form like 1w for one week.

  • s: second,
  • m: minute,
  • h: hour,
  • d: day,
  • w: week,
  • M: month (30 days used here, 12M ≠ 1y!),
  • y: year (365 days always, leap years ignored, if you want them add them as days)
source

pub fn revalidate_after<I: PerseusDuration>(self, _val: I) -> Self

Enables the revalidation strategy (time variant). This takes a time string of a form like 1w for one week.

  • s: second,
  • m: minute,
  • h: hour,
  • d: day,
  • w: week,
  • M: month (30 days used here, 12M ≠ 1y!),
  • y: year (365 days always, leap years ignored, if you want them add them as days)
source

pub fn amalgamate_states_fn<S, B, V>( self, val: impl AmalgamateStatesUserFnType<S, B, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + Send + Sync + 'static, B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,

Enables state amalgamation with the given function. State amalgamation allows you to have one template generate state at both build time and request time. The function you provide here is responsible for rationalizing the two into one single state to be sent to the client, and this will be run just after the request state function completes.

source

pub fn amalgamate_states_fn(self, _val: impl Fn() + 'static) -> Self

Enables state amalgamation with the given function. State amalgamation allows you to have one template generate state at both build time and request time. The function you provide here is responsible for rationalizing the two into one single state to be sent to the client, and this will be run just after the request state function completes.

source

pub fn allow_rescheduling(self) -> Self

Allow the building of this page’s templates to be rescheduled from build-tim to request-time.

A page whose state isn’t generated at request-tim and isn’t revalidated can be rendered at build-time, unless it depends on capsules that don’t have those properties. If a page that could be rendered at build-time were to render with a widget that revalidates later, that prerender would be invalidated later, leading to render errors. If that situation arises, and this hasn’t been set, building will return an error.

If you receive one of those errors, it’s almost always absolutely fine to enable this, as the performance hit will usually be negligible. If you notice a substantial difference though, you may wish to reconsider.

source§

impl<G: Html> TemplateInner<G>

source

pub fn view_with_state<I, F>(self, val: F) -> Selfwhere F: for<'app, 'child> Fn(BoundedScope<'app, 'child>, &'child I) -> View<G> + Send + Sync + 'static, I: MakeUnrx + AnyFreeze + Clone, I::Unrx: MakeRx<Rx = I> + Serialize + DeserializeOwned + Send + Sync + Clone + 'static,

Sets the template rendering function to use, if the template takes state. Templates that do not take state should use .template() instead.

The closure wrapping this performs will automatically handle suspense state.

source

pub fn view_with_unreactive_state<F, S>(self, val: F) -> Selfwhere F: Fn(Scope<'_>, S) -> View<G> + Send + Sync + 'static, S: MakeRx + Serialize + DeserializeOwned + UnreactiveState + 'static, <S as MakeRx>::Rx: AnyFreeze + Clone + MakeUnrx<Unrx = S>,

Sets the template rendering function to use, if the template takes unreactive state.

source

pub fn view<F>(self, val: F) -> Selfwhere F: Fn(Scope<'_>) -> View<G> + Send + Sync + 'static,

Sets the template rendering function to use for templates that take no state. Templates that do take state should use .template_with_state() instead.

source

pub fn head_with_state<S, V>( self, val: impl Fn(Scope<'_>, S) -> V + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + 'static, V: Into<GeneratorResult<View<SsrNode>>>,

Sets the document <head> rendering function to use. The [View] produced by this will only be rendered on the engine-side, and will not be reactive (since it only contains metadata).

This is for heads that do require state. Those that do not should use .head() instead.

source

pub fn head_with_state(self, _val: impl Fn() + 'static) -> Self

Sets the document <head> rendering function to use. The [View] produced by this will only be rendered on the engine-side, and will not be reactive (since it only contains metadata).

This is for heads that do require state. Those that do not should use .head() instead.

source

pub fn set_headers_with_state<S, V>( self, val: impl Fn(Scope<'_>, S) -> V + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + 'static, V: Into<GeneratorResult<HeaderMap>>,

Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting requires knowing the state.

source

pub fn set_headers_with_state(self, _val: impl Fn() + 'static) -> Self

Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting requires knowing the state.

source§

impl<G: Html> TemplateInner<G>

source

pub fn build(self) -> Template<G>

Builds a full Template from this TemplateInner, consuming it in the process. Once called, the template cannot be modified anymore, and it will be placed into a smart pointer, allowing it to be cloned freely with minimal costs.

You should call this just before you return your template.

Trait Implementations§

source§

impl<G: Html> Debug for TemplateInner<G>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<G> !RefUnwindSafe for TemplateInner<G>

§

impl<G> Send for TemplateInner<G>

§

impl<G> Sync for TemplateInner<G>

§

impl<G> Unpin for TemplateInner<G>

§

impl<G> !UnwindSafe for TemplateInner<G>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.