Struct relm4::factory::AsyncFactoryVecDequeGuard
source · pub struct AsyncFactoryVecDequeGuard<'a, C: AsyncFactoryComponent>where
<C::ParentWidget as FactoryView>::ReturnedWidget: Clone,{ /* 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>where
<C::ParentWidget as FactoryView>::ReturnedWidget: Clone,
impl<'a, C: AsyncFactoryComponent> AsyncFactoryVecDequeGuard<'a, C>where <C::ParentWidget as FactoryView>::ReturnedWidget: Clone,
sourcepub fn drop(self)
pub fn drop(self)
Drops the guard and renders all changes.
Use this to transfer full ownership back to the AsyncFactoryVecDeque
.
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut C>
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.
sourcepub fn back_mut(&mut self) -> Option<&mut C>
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.
sourcepub fn front_mut(&mut self) -> Option<&mut C>
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.
sourcepub fn pop_back(&mut self) -> Option<C>
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?
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());
}
}
}
sourcepub fn pop_front(&mut self) -> Option<C>
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.
sourcepub fn remove(&mut self, index: usize) -> Option<C>
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?
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());
}
}
}
sourcepub fn push_back(&mut self, init: C::Init) -> DynamicIndex
pub fn push_back(&mut self, init: C::Init) -> DynamicIndex
Appends an element at the end of the AsyncFactoryVecDeque
.
Examples found in repository?
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());
}
}
}
sourcepub fn push_front(&mut self, init: C::Init) -> DynamicIndex
pub fn push_front(&mut self, init: C::Init) -> DynamicIndex
Prepends an element to the AsyncFactoryVecDeque
.
sourcepub fn insert(&mut self, index: usize, init: C::Init) -> DynamicIndex
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.
sourcepub fn swap(&mut self, first: usize, second: usize)
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.
sourcepub fn move_to(&mut self, current_position: usize, target: usize)
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?
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());
}
}
}
sourcepub fn move_front(&mut self, current_position: usize)
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?
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());
}
}
}
sourcepub fn move_back(&mut self, current_position: usize)
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.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all components from the AsyncFactoryVecDeque
.
sourcepub fn iter_mut(
&mut self
) -> impl Iterator<Item = Option<&mut C>> + DoubleEndedIterator + ExactSizeIterator + FusedIterator
pub fn iter_mut( &mut self ) -> impl Iterator<Item = Option<&mut C>> + DoubleEndedIterator + 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>>§
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the AsyncFactoryVecDeque
.
Examples found in repository?
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());
}
}
}
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the AsyncFactoryVecDeque
is empty.
sourcepub fn broadcast(&self, msg: C::Input)where
C::Input: Clone,
pub fn broadcast(&self, msg: C::Input)where C::Input: Clone,
Send clone of a message to all of the elements.
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 fn widget(&self) -> &C::ParentWidget
pub fn widget(&self) -> &C::ParentWidget
Returns the widget all components are attached to.
Examples found in repository?
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 }
}
sourcepub fn iter(
&self
) -> impl Iterator<Item = Option<&C>> + DoubleEndedIterator + ExactSizeIterator + FusedIterator
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
.