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>
impl<'s> Slot<'s>
Sourcepub fn new(render: &'s dyn Fn(&mut String)) -> Self
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><Ada></b><!--]-->");
// Empty content is still content: the fallback does not show.
let nothing = |_: &mut String| {};
out.clear();
slot_into(&mut out, Some(Slot::new(¬hing)), Some(&mut |out: &mut String| out.push_str("fallback")));
assert_eq!(out, "<!--[--><!--]-->");Sourcepub fn render_to(&self, out: &mut String)
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§
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.