pub struct AsyncFactoryVecDeque<C: AsyncFactoryComponent>{ /* 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>
impl<C: AsyncFactoryComponent> AsyncFactoryVecDeque<C>
Sourcepub fn builder() -> AsyncFactoryVecDequeBuilder<C>
pub fn builder() -> AsyncFactoryVecDequeBuilder<C>
Creates a new AsyncFactoryVecDequeBuilder.
Examples found in repository?
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 }Sourcepub fn guard(&mut self) -> AsyncFactoryVecDequeGuard<'_, C>
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?
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 }Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the AsyncFactoryVecDeque.
Examples found in repository?
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 }Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the AsyncFactoryVecDeque is empty.
Sourcepub fn get(&self, index: usize) -> Option<&C>
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.
Sourcepub fn back(&self) -> Option<&C>
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.
Sourcepub fn front(&self) -> Option<&C>
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.
Sourcepub const fn widget(&self) -> &C::ParentWidget
pub const fn widget(&self) -> &C::ParentWidget
Returns the widget all components are attached to.
Examples found in repository?
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 }Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = Option<&C>> + ExactSizeIterator + FusedIterator
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.