pub struct CapsuleInner<G: Html, P: Clone + 'static> { /* private fields */ }
Expand description

The equivalent of TemplateInner for capsules.

Implementation

Really, this is just a wrapper over TemplateInner with the additional methods capsules need. For example, templates have fallback views on their own, they just don’t use them, and there’s no way to set them as an end user. This means Perseus can treat templates and capsules in the same way internally, since they both have the same representation. Types like this are mere convenience wrappers.

Implementations§

source§

impl<G: Html, P: Clone + 'static> CapsuleInner<G, P>

source

pub fn fallback( self, view: impl Fn(Scope<'_>, P) -> View<G> + Send + Sync + 'static ) -> Self

Declares the fallback view to render for this capsule. When Perseus renders a page of your app, it fetches the page itself, along with all the capsules it needs. If the page is ready before all the capsules, then it will be displayed immediately, with fallback views for the capsules that aren’t ready yet. Once they are ready, they will be updated.

This fallback view cannot access any of the state that the capsule generated, but it can access any properties provided to it by the page, along with a translator and the like. This view is fully reactive, it just doesn’t have the state yet.

Warning: if you do not set a fallback view for a capsule, your app will not compile!

source

pub fn empty_fallback(self) -> Self

Sets the fallback for this capsule to be an empty view.

You should be careful using this function in production, since it is very often not what you actually want (especially since empty views have no size, which may compromise your layouts: be sure to test this).

source

pub fn build(self) -> Capsule<G, P>

Builds a full Capsule from this CapsuleInner, consuming it in the process. Once called, the capsule 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 capsule.

source

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

Sets the rendering function to use for capsules that take reactive state. Capsules that do not take state should use .view() 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, P) -> View<G> + Clone + Send + Sync + 'static, S: MakeRx + Serialize + DeserializeOwned + UnreactiveState + 'static, <S as MakeRx>::Rx: AnyFreeze + Clone + MakeUnrx<Unrx = S>,

Sets the rendering function to use for capsules that take unreactive state.

source

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

Sets the rendering function for capsules that take no state. Capsules that do take state should use .view_with_state() instead.

Trait Implementations§

source§

impl<G: Html, P: Clone + 'static> Debug for CapsuleInner<G, P>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<G, P> !RefUnwindSafe for CapsuleInner<G, P>

§

impl<G, P> Send for CapsuleInner<G, P>

§

impl<G, P> Sync for CapsuleInner<G, P>

§

impl<G, P> Unpin for CapsuleInner<G, P>

§

impl<G, P> !UnwindSafe for CapsuleInner<G, P>

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.