pub struct AsyncFactoryVecDeque<C: AsyncFactoryComponent>where
    <C::ParentWidget as FactoryView>::ReturnedWidget: Clone,{ /* private fields */ }
Expand description

A container similar to VecDeque that can be used to store data associated with components that implement AsyncFactoryComponent.

To access mutable methods of the factory, create a guard using Self::guard.

Implementations§

source§

impl<C: AsyncFactoryComponent> AsyncFactoryVecDeque<C>where <C::ParentWidget as FactoryView>::ReturnedWidget: Clone,

source

pub fn new( widget: C::ParentWidget, parent_sender: &Sender<C::ParentInput> ) -> Self

Creates a new AsyncFactoryVecDeque.

Examples found in repository?
relm4/examples/factory_async.rs (line 202)
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
    fn init(
        counter: Self::Init,
        root: &Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let counters = AsyncFactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
        let model = App {
            created_widgets: counter,
            counters,
        };

        let counter_box = model.counters.widget();
        let widgets = view_output!();

        ComponentParts { model, widgets }
    }
source

pub fn guard(&mut self) -> AsyncFactoryVecDequeGuard<'_, C>

Provides a AsyncFactoryVecDequeGuard that can be used to edit the factory.

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

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

pub fn len(&self) -> usize

Returns the number of elements in the AsyncFactoryVecDeque.

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

Returns the widget all components are attached to.

Examples found in repository?
relm4/examples/factory_async.rs (line 208)
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
    fn init(
        counter: Self::Init,
        root: &Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let counters = AsyncFactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
        let model = App {
            created_widgets: counter,
            counters,
        };

        let counter_box = model.counters.widget();
        let widgets = view_output!();

        ComponentParts { model, widgets }
    }
source

pub fn iter( &self ) -> impl Iterator<Item = Option<&C>> + DoubleEndedIterator + 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<C: Debug + AsyncFactoryComponent> Debug for AsyncFactoryVecDeque<C>where <C::ParentWidget as FactoryView>::ReturnedWidget: Clone, C::ParentWidget: Debug, C::ParentInput: Debug,

source§

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

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

impl<C: AsyncFactoryComponent> Drop for AsyncFactoryVecDeque<C>where <C::ParentWidget as FactoryView>::ReturnedWidget: Clone,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere 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 Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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> Position<()> for C

source§

fn position(&self, _index: usize)

Returns the position. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · 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