AsyncFactoryVecDequeGuard

Struct AsyncFactoryVecDequeGuard 

Source
pub struct AsyncFactoryVecDequeGuard<'a, C: AsyncFactoryComponent>{ /* private fields */ }
Expand description

Provides methods to edit the underlying AsyncFactoryVecDeque.

The changes will be rendered on the widgets after the guard goes out of scope.

Implementations§

Source§

impl<'a, C: AsyncFactoryComponent> AsyncFactoryVecDequeGuard<'a, C>

Source

pub fn drop(self)

Drops the guard and renders all changes.

Use this to transfer full ownership back to the AsyncFactoryVecDeque.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut C>

Tries to get a mutable reference to the model of one element.

Returns None if index is invalid or the async init_model() method hasn’t returned yet.

Source

pub fn back_mut(&mut self) -> Option<&mut C>

Provides a mutable reference to the model of the back element.

Returns None if the deque is empty or the async init_model() method of the last element hasn’t returned yet.

Source

pub fn front_mut(&mut self) -> Option<&mut C>

Provides a mutable reference to the model of the front element.

Returns None if the deque is empty or the async init_model() method of the first element hasn’t returned yet.

Source

pub fn pop_back(&mut self) -> Option<C>

Removes the last element from the AsyncFactoryVecDeque and returns it, or None if it is empty or the async init_model() method of the element hasn’t returned yet.

Examples found in repository?
relm4/examples/factory_async.rs (line 221)
213    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
214        let mut counters_guard = self.counters.guard();
215        match msg {
216            AppMsg::AddCounter => {
217                counters_guard.push_back(self.created_widgets);
218                self.created_widgets = self.created_widgets.wrapping_add(1);
219            }
220            AppMsg::RemoveCounter => {
221                counters_guard.pop_back();
222            }
223            AppMsg::SendFront(index) => {
224                counters_guard.move_front(index.current_index());
225            }
226            AppMsg::MoveDown(index) => {
227                let index = index.current_index();
228                let new_index = index + 1;
229                // Already at the end?
230                if new_index < counters_guard.len() {
231                    counters_guard.move_to(index, new_index);
232                }
233            }
234            AppMsg::MoveUp(index) => {
235                let index = index.current_index();
236                // Already at the start?
237                if index != 0 {
238                    counters_guard.move_to(index, index - 1);
239                }
240            }
241            AppMsg::Remove(index) => {
242                counters_guard.remove(index.current_index());
243            }
244        }
245    }
Source

pub fn pop_front(&mut self) -> Option<C>

Removes the first element from the AsyncFactoryVecDeque and returns it, or None if it is empty or the async init_model() method of the element hasn’t returned yet.

Source

pub fn remove(&mut self, index: usize) -> Option<C>

Removes and returns the element at index from the AsyncFactoryVecDeque. or None if it is empty or the async init_model() method of the element hasn’t returned yet.

Element at index 0 is the front of the queue.

Examples found in repository?
relm4/examples/factory_async.rs (line 242)
213    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
214        let mut counters_guard = self.counters.guard();
215        match msg {
216            AppMsg::AddCounter => {
217                counters_guard.push_back(self.created_widgets);
218                self.created_widgets = self.created_widgets.wrapping_add(1);
219            }
220            AppMsg::RemoveCounter => {
221                counters_guard.pop_back();
222            }
223            AppMsg::SendFront(index) => {
224                counters_guard.move_front(index.current_index());
225            }
226            AppMsg::MoveDown(index) => {
227                let index = index.current_index();
228                let new_index = index + 1;
229                // Already at the end?
230                if new_index < counters_guard.len() {
231                    counters_guard.move_to(index, new_index);
232                }
233            }
234            AppMsg::MoveUp(index) => {
235                let index = index.current_index();
236                // Already at the start?
237                if index != 0 {
238                    counters_guard.move_to(index, index - 1);
239                }
240            }
241            AppMsg::Remove(index) => {
242                counters_guard.remove(index.current_index());
243            }
244        }
245    }
Source

pub fn push_back(&mut self, init: C::Init) -> DynamicIndex

Appends an element at the end of the AsyncFactoryVecDeque.

Examples found in repository?
relm4/examples/factory_async.rs (line 217)
213    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
214        let mut counters_guard = self.counters.guard();
215        match msg {
216            AppMsg::AddCounter => {
217                counters_guard.push_back(self.created_widgets);
218                self.created_widgets = self.created_widgets.wrapping_add(1);
219            }
220            AppMsg::RemoveCounter => {
221                counters_guard.pop_back();
222            }
223            AppMsg::SendFront(index) => {
224                counters_guard.move_front(index.current_index());
225            }
226            AppMsg::MoveDown(index) => {
227                let index = index.current_index();
228                let new_index = index + 1;
229                // Already at the end?
230                if new_index < counters_guard.len() {
231                    counters_guard.move_to(index, new_index);
232                }
233            }
234            AppMsg::MoveUp(index) => {
235                let index = index.current_index();
236                // Already at the start?
237                if index != 0 {
238                    counters_guard.move_to(index, index - 1);
239                }
240            }
241            AppMsg::Remove(index) => {
242                counters_guard.remove(index.current_index());
243            }
244        }
245    }
Source

pub fn push_front(&mut self, init: C::Init) -> DynamicIndex

Prepends an element to the AsyncFactoryVecDeque.

Source

pub fn insert(&mut self, index: usize, init: C::Init) -> DynamicIndex

Inserts an element at index within the AsyncFactoryVecDeque, shifting all elements with indices greater than or equal to index towards the back.

Element at index 0 is the front of the queue.

§Panics

Panics if index is greater than AsyncFactoryVecDeque’s length.

Source

pub fn swap(&mut self, first: usize, second: usize)

Swaps elements at indices first and second.

first and second may be equal.

Element at index 0 is the front of the queue.

§Panics

Panics if either index is out of bounds.

Source

pub fn move_to(&mut self, current_position: usize, target: usize)

Moves an element at index current_position to target, shifting all elements between these positions.

current_position and target may be equal.

Element at index 0 is the front of the queue.

§Panics

Panics if either index is out of bounds.

Examples found in repository?
relm4/examples/factory_async.rs (line 231)
213    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
214        let mut counters_guard = self.counters.guard();
215        match msg {
216            AppMsg::AddCounter => {
217                counters_guard.push_back(self.created_widgets);
218                self.created_widgets = self.created_widgets.wrapping_add(1);
219            }
220            AppMsg::RemoveCounter => {
221                counters_guard.pop_back();
222            }
223            AppMsg::SendFront(index) => {
224                counters_guard.move_front(index.current_index());
225            }
226            AppMsg::MoveDown(index) => {
227                let index = index.current_index();
228                let new_index = index + 1;
229                // Already at the end?
230                if new_index < counters_guard.len() {
231                    counters_guard.move_to(index, new_index);
232                }
233            }
234            AppMsg::MoveUp(index) => {
235                let index = index.current_index();
236                // Already at the start?
237                if index != 0 {
238                    counters_guard.move_to(index, index - 1);
239                }
240            }
241            AppMsg::Remove(index) => {
242                counters_guard.remove(index.current_index());
243            }
244        }
245    }
Source

pub fn move_front(&mut self, current_position: usize)

Moves an element at index current_position to the front, shifting all elements between these positions.

§Panics

Panics if index is out of bounds.

Examples found in repository?
relm4/examples/factory_async.rs (line 224)
213    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
214        let mut counters_guard = self.counters.guard();
215        match msg {
216            AppMsg::AddCounter => {
217                counters_guard.push_back(self.created_widgets);
218                self.created_widgets = self.created_widgets.wrapping_add(1);
219            }
220            AppMsg::RemoveCounter => {
221                counters_guard.pop_back();
222            }
223            AppMsg::SendFront(index) => {
224                counters_guard.move_front(index.current_index());
225            }
226            AppMsg::MoveDown(index) => {
227                let index = index.current_index();
228                let new_index = index + 1;
229                // Already at the end?
230                if new_index < counters_guard.len() {
231                    counters_guard.move_to(index, new_index);
232                }
233            }
234            AppMsg::MoveUp(index) => {
235                let index = index.current_index();
236                // Already at the start?
237                if index != 0 {
238                    counters_guard.move_to(index, index - 1);
239                }
240            }
241            AppMsg::Remove(index) => {
242                counters_guard.remove(index.current_index());
243            }
244        }
245    }
Source

pub fn move_back(&mut self, current_position: usize)

Moves an element at index current_position to the back, shifting all elements between these positions.

§Panics

Panics if index is out of bounds.

Source

pub fn clear(&mut self)

Remove all components from the AsyncFactoryVecDeque.

Source

pub fn iter_mut( &mut self, ) -> impl DoubleEndedIterator<Item = Option<&mut C>> + ExactSizeIterator + FusedIterator

Returns an iterator over the components that returns mutable references.

Each item will be Some if the async init_model() method of the item returned and otherwise None.

Methods from Deref<Target = AsyncFactoryVecDeque<C>>§

Source

pub fn len(&self) -> usize

Returns the number of elements in the AsyncFactoryVecDeque.

Examples found in repository?
relm4/examples/factory_async.rs (line 230)
213    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
214        let mut counters_guard = self.counters.guard();
215        match msg {
216            AppMsg::AddCounter => {
217                counters_guard.push_back(self.created_widgets);
218                self.created_widgets = self.created_widgets.wrapping_add(1);
219            }
220            AppMsg::RemoveCounter => {
221                counters_guard.pop_back();
222            }
223            AppMsg::SendFront(index) => {
224                counters_guard.move_front(index.current_index());
225            }
226            AppMsg::MoveDown(index) => {
227                let index = index.current_index();
228                let new_index = index + 1;
229                // Already at the end?
230                if new_index < counters_guard.len() {
231                    counters_guard.move_to(index, new_index);
232                }
233            }
234            AppMsg::MoveUp(index) => {
235                let index = index.current_index();
236                // Already at the start?
237                if index != 0 {
238                    counters_guard.move_to(index, index - 1);
239                }
240            }
241            AppMsg::Remove(index) => {
242                counters_guard.remove(index.current_index());
243            }
244        }
245    }
Source

pub fn is_empty(&self) -> bool

Returns true if the AsyncFactoryVecDeque is empty.

Source

pub fn send(&self, index: usize, msg: C::Input)

Send a message to one of the elements.

Source

pub fn broadcast(&self, msg: C::Input)
where C::Input: Clone,

Send clone of a message to all of the elements.

Source

pub fn get(&self, index: usize) -> Option<&C>

Tries to get an immutable reference to the model of one element.

Returns None if index is invalid or the async init_model() method hasn’t returned yet.

Source

pub fn back(&self) -> Option<&C>

Provides a reference to the model of the back element.

Returns None if index is invalid or the async init_model() method of the last element hasn’t returned yet.

Source

pub fn front(&self) -> Option<&C>

Provides a reference to the model of the front element.

Returns None if index is invalid or the async init_model() method of the first element hasn’t returned yet.

Source

pub fn widget(&self) -> &C::ParentWidget

Returns the widget all components are attached to.

Examples found in repository?
relm4/examples/factory_async.rs (line 207)
187    fn init(
188        counter: Self::Init,
189        root: Self::Root,
190        sender: ComponentSender<Self>,
191    ) -> ComponentParts<Self> {
192        let counters = AsyncFactoryVecDeque::builder().launch_default().forward(
193            sender.input_sender(),
194            |output| match output {
195                CounterOutput::SendFront(index) => AppMsg::SendFront(index),
196                CounterOutput::MoveUp(index) => AppMsg::MoveUp(index),
197                CounterOutput::MoveDown(index) => AppMsg::MoveDown(index),
198                CounterOutput::Remove(index) => AppMsg::Remove(index),
199            },
200        );
201
202        let model = App {
203            created_widgets: counter,
204            counters,
205        };
206
207        let counter_box = model.counters.widget();
208        let widgets = view_output!();
209
210        ComponentParts { model, widgets }
211    }
Source

pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = Option<&C>> + ExactSizeIterator + FusedIterator

Returns an iterator over the components.

Each item will be Some if the async init_model() method of the item returned and otherwise None.

Trait Implementations§

Source§

impl<'a, C: Debug + AsyncFactoryComponent> Debug for AsyncFactoryVecDequeGuard<'a, C>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<C: AsyncFactoryComponent> Deref for AsyncFactoryVecDequeGuard<'_, C>

Source§

type Target = AsyncFactoryVecDeque<C>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<C: AsyncFactoryComponent> Drop for AsyncFactoryVecDequeGuard<'_, C>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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<C> AsyncPosition<()> for C

Source§

fn position(_index: usize)

Returns the position. 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.

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<C, I> Position<(), I> for C

Source§

fn position(&self, _index: &I)

Returns the position. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
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