Skip to main content

Slot

Struct Slot 

Source
pub struct Slot<'s> { /* private fields */ }
Expand description

What a parent puts in one of a component’s slots.

§Example

use ferrovue::render::{slot_into, Slot};

let body = |out: &mut String| out.push_str("<p>three new messages</p>");
let slot = Slot::new(&body);

// What a component's `<slot>` outlet does with it: the content between fragment markers.
let mut out = String::new();
slot_into(&mut out, Some(slot), Some(&mut |out: &mut String| out.push_str("nothing here")));
assert_eq!(out, "<!--[--><p>three new messages</p><!--]-->");

Implementations§

Source§

impl<'s> Slot<'s>

Source

pub fn new(render: &'s dyn Fn(&mut String)) -> Self

Content for a slot: another component’s render, or markup the caller already holds. The slot’s fallback never replaces it, even when the closure writes nothing, as a component in a slot is always content to Vue; to show the fallback, give the slot None.

The closure’s output is written as it is, unescaped: escape any text it writes with escape_into.

§Example
use ferrovue::render::{slot_into, Slot};

let name = "<Ada>";
let content = |out: &mut String| {
    out.push_str("<b>");
    ferrovue::core::escape_into(out, name);
    out.push_str("</b>");
};
let mut out = String::new();
slot_into(&mut out, Some(Slot::new(&content)), None);
assert_eq!(out, "<!--[--><b>&lt;Ada&gt;</b><!--]-->");

// Empty content is still content: the fallback does not show.
let nothing = |_: &mut String| {};
out.clear();
slot_into(&mut out, Some(Slot::new(&nothing)), Some(&mut |out: &mut String| out.push_str("fallback")));
assert_eq!(out, "<!--[--><!--]-->");
Source

pub fn render_to(&self, out: &mut String)

Write the content alone, without fragment markers, as <RouterView> does with the page it shows. Generated code calls it for a component’s router_view slot.

§Example
let page = |out: &mut String| out.push_str("<h1>Home</h1>");
let mut out = String::from("<main>");
ferrovue::render::Slot::new(&page).render_to(&mut out);
out.push_str("</main>");
assert_eq!(out, "<main><h1>Home</h1></main>");

Trait Implementations§

Source§

impl<'s> Clone for Slot<'s>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'s> Copy for Slot<'s>

Source§

impl Debug for Slot<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'s> !RefUnwindSafe for Slot<'s>

§

impl<'s> !Send for Slot<'s>

§

impl<'s> !Sync for Slot<'s>

§

impl<'s> !UnwindSafe for Slot<'s>

§

impl<'s> Forget for Slot<'s>

§

impl<'s> Freeze for Slot<'s>

§

impl<'s> Unpin for Slot<'s>

§

impl<'s> UnsafeUnpin for Slot<'s>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more