Struct sycamore::view::View

pub struct View<G>
where G: GenericNode,
{ /* private fields */ }
Expand description

Represents an UI view. Usually constructed using the view! macro or using the builder API.

§Example

let my_view: View<G> = view! {
    div {
        p { "A view." }
    }
};

Implementations§

§

impl<G> View<G>
where G: GenericNode,

pub fn new_node(node: G) -> View<G>

Create a new View from a raw node.

pub fn new_dyn(f: impl FnMut() -> View<G> + 'static) -> View<G>

Create a new dynamic View from a FnMut.

pub fn new_fragment(fragment: Vec<View<G>>) -> View<G>

Create a new View fragment from a Vec of Views.

pub fn empty() -> View<G>

Create a new View with a blank marker node

Note that this is different from an empty view fragment. Instead, this is a single marker (dummy) node.

pub fn as_node(&self) -> Option<&G>

Try to cast to a GenericNode, or None if wrong type.

pub fn as_fragment(&self) -> Option<&[View<G>]>

Try to cast to a slice representing the view fragment, or None if wrong type.

pub fn as_dyn(&self) -> Option<ReadSignal<View<G>>>

Try to cast to the underlying [RcSignal] for a dynamic view, or None if wrong type.

pub fn is_node(&self) -> bool

Returns true if the view is a single node. Note that if the view is a fragment containing only a single child node, this will still return false.

To check whether the View only contains a single node, use .flatten().len() == 1 instead.

pub fn is_fragment(&self) -> bool

Returns true if the view is a view fragment.

pub fn is_dyn(&self) -> bool

Returns true if the view is a dynamic view.

pub fn flatten(self) -> Vec<G>

Returns a recursively flattened Vec of raw nodes.

If the current view is dynamic or is a fragment containing dynamic views, the dynamic views will be accessed reactively.

Trait Implementations§

§

impl<G> Clone for View<G>
where G: Clone + GenericNode,

§

fn clone(&self) -> View<G>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl<G> Debug for View<G>
where G: GenericNode,

§

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

Formats the value using the given formatter. Read more
§

impl<G> Default for View<G>
where G: GenericNode,

§

fn default() -> View<G>

Returns the “default value” for a type. Read more
source§

impl<G: GenericNode> ElementBuilderOrView<G> for View<G>

source§

fn into_view(self) -> View<G>

Convert into a View.
§

impl<G> From<View<G>> for Children<G>
where G: GenericNode,

§

fn from(view: View<G>) -> Children<G>

Converts to this type from the input type.
§

impl<G> ToView<G> for View<G>
where G: GenericNode,

§

fn to_view(&self) -> View<G>

Tautology of converting a View into a View. This allows us to interpolate views into other views.

Auto Trait Implementations§

§

impl<G> Freeze for View<G>
where G: Hash + Eq + PartialEq + Clone + Debug + 'static + Freeze,

§

impl<G> !RefUnwindSafe for View<G>

§

impl<G> !Send for View<G>

§

impl<G> !Sync for View<G>

§

impl<G> Unpin for View<G>
where G: Hash + Eq + PartialEq + Clone + Debug + 'static + Unpin,

§

impl<G> !UnwindSafe for View<G>

Blanket Implementations§

§

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

§

fn value(&self) -> T

Get the reactive value. For example, with Signal, this just calls get.
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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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<T> ToOwned for T
where T: Clone,

§

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>,

§

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 T
where 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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