SignalVec

Struct SignalVec 

Source
pub struct SignalVec<T: 'static> { /* private fields */ }
Expand description

A reactive Vec. This is more effective than using a Signal<Vec> because it allows fine grained reactivity within the Vec.

Implementations§

Source§

impl<T: 'static> SignalVec<T>

Source

pub fn new() -> Self

Create a new empty SignalVec.

Source

pub fn with_values(values: Vec<T>) -> Self

Create a new SignalVec with existing values from a Vec.

Source

pub fn changes(&self) -> &Rc<RefCell<Vec<VecDiff<T>>>>

Get the current pending changes that will be applied to the SignalVec.

Source

pub fn inner_signal(&self) -> &Signal<RefCell<Vec<T>>>

Returns the inner backing Signal used to store the data. This method should used with care as unintentionally modifying the Vec will not trigger any updates and cause potential future problems.

Source

pub fn replace(&self, values: Vec<T>)

Source

pub fn insert(&self, index: usize, value: T)

Source

pub fn update(&self, index: usize, value: T)

Source

pub fn remove(&self, index: usize)

Source

pub fn swap(&self, index1: usize, index2: usize)

Source

pub fn push(&self, value: T)

Source

pub fn pop(&self)

Source

pub fn clear(&self)

Source

pub fn map<U: Clone>(&self, f: impl Fn(&T) -> U + 'static) -> SignalVec<U>

Creates a derived SignalVec.

§Example
use maple_core::prelude::*;

let my_vec = SignalVec::with_values(vec![1, 2, 3]);
let squared = my_vec.map(|x| *x * *x);

assert_eq!(*squared.inner_signal().get().borrow(), vec![1, 4, 9]);

my_vec.push(4);
assert_eq!(*squared.inner_signal().get().borrow(), vec![1, 4, 9, 16]);

my_vec.swap(0, 1);
assert_eq!(*squared.inner_signal().get().borrow(), vec![4, 1, 9, 16]);
Source§

impl SignalVec<TemplateResult>

Source

pub fn template_list(&self) -> TemplateList

Create a TemplateList from the SignalVec.

Source§

impl<T: 'static + Clone> SignalVec<T>

Source

pub fn to_vec(&self) -> Vec<T>

Create a Vec from a SignalVec. The returned Vec is cloned from the data which requires T to be Clone.

§Example
use maple_core::prelude::*;

let signal = SignalVec::with_values(vec![1, 2, 3]);
assert_eq!(signal.to_vec(), vec![1, 2, 3]);

Trait Implementations§

Source§

impl<T: 'static> Clone for SignalVec<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: 'static> Default for SignalVec<T>

Source§

fn default() -> Self

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

impl From<SignalVec<TemplateResult>> for TemplateList

Source§

fn from(templates: SignalVec<TemplateResult>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for SignalVec<T>

§

impl<T> !RefUnwindSafe for SignalVec<T>

§

impl<T> !Send for SignalVec<T>

§

impl<T> !Sync for SignalVec<T>

§

impl<T> Unpin for SignalVec<T>

§

impl<T> !UnwindSafe for SignalVec<T>

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

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

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.