Struct relm4::factory::collections::FactoryVec
source · [−]pub struct FactoryVec<Data> where
Data: FactoryPrototype, { /* private fields */ }
Implementations
sourceimpl<Data> FactoryVec<Data> where
Data: FactoryPrototype,
impl<Data> FactoryVec<Data> where
Data: FactoryPrototype,
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new FactoryVec
.
Examples found in repository
More examples
Additional examples can be found in:
sourcepub fn from_vec(data: Vec<Data>) -> Self
pub fn from_vec(data: Vec<Data>) -> Self
Initialize a new FactoryVec
with a normal Vec
.
sourcepub fn as_slice(&self) -> &[Data]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn as_slice(&self) -> &[Data]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Get a slice of the internal data of a FactoryVec
.
sourcepub fn into_vec(self) -> Vec<Data>
pub fn into_vec(self) -> Vec<Data>
Get the internal data of the FactoryVec
.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all data from the FactoryVec
.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length as amount of elements stored in this type.
Examples found in repository
relm4-examples/libadwaita/examples/advent_calendar.rs (line 140)
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Update => {
// Check all entries
for i in 0..self.calendar_entries.len() {
// If counter > 1, count down
let needs_update = self.calendar_entries.get(i).unwrap().time_left != 0;
if needs_update {
let entry = self.calendar_entries.get_mut(i).unwrap();
entry.time_left = entry.time_left.saturating_sub(1);
}
}
}
}
true
}
More examples
relm4-examples/libadwaita/examples/sudoku_solver.rs (line 76)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Solve => {
let content = self.to_line_string();
let sudoku = Sudoku::from_str_line(content.as_str()).unwrap();
if let Some(solution) = sudoku.solve_one() {
self.from_string(solution.to_string());
}
}
AppMsg::Clear => {
for index in 0..self.values.len() {
if let Some(v) = self.values.get_mut(index) {
v.value = 0;
}
}
}
AppMsg::Update(index, value) => {
if let Some(v) = self.values.get_mut(index) {
v.value = value;
}
}
}
true
}
sourcepub fn push(&mut self, data: Data)
pub fn push(&mut self, data: Data)
Insert an element at the end of a FactoryVec
.
Examples found in repository
relm4-examples/examples/to_do.rs (lines 85-88)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::SetCompleted((index, completed)) => {
if let Some(task) = self.tasks.get_mut(index) {
task.completed = completed;
}
}
AppMsg::AddEntry(name) => {
self.tasks.push(Task {
name,
completed: false,
});
}
}
true
}
More examples
relm4-examples/examples/grid_factory.rs (lines 94-96)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.data.push(Data {
counter: self.counter,
});
self.counter += 1;
}
AppMsg::Remove => {
self.data.pop();
}
AppMsg::Clicked(index) => {
if let Some(data) = self.data.get_mut(index) {
data.counter = data.counter.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/factory_manual.rs (lines 32-34)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/stack_factory.rs (lines 32-34)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/factory.rs (lines 32-34)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/entry.rs (lines 40-42)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::AddCounters => {
let text = self.entry.text();
if let Ok(v) = text.parse::<i32>() {
if v.is_positive() {
// add as many counters as user entered
for _ in 0..v {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
} else if v.is_negative() {
// remove counters
for _ in v..0 {
self.counters.pop();
}
}
// clearing the entry value clears the entry widget
self.entry.set_text("");
}
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
Additional examples can be found in:
sourcepub fn pop(&mut self) -> Option<Data>
pub fn pop(&mut self) -> Option<Data>
Remove an element at the end of a FactoryVec
.
Examples found in repository
relm4-examples/examples/grid_factory.rs (line 100)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.data.push(Data {
counter: self.counter,
});
self.counter += 1;
}
AppMsg::Remove => {
self.data.pop();
}
AppMsg::Clicked(index) => {
if let Some(data) = self.data.get_mut(index) {
data.counter = data.counter.wrapping_sub(1);
}
}
}
true
}
More examples
relm4-examples/examples/factory_manual.rs (line 38)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/stack_factory.rs (line 38)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/factory.rs (line 38)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/entry.rs (line 48)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::AddCounters => {
let text = self.entry.text();
if let Ok(v) = text.parse::<i32>() {
if v.is_positive() {
// add as many counters as user entered
for _ in 0..v {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
} else if v.is_negative() {
// remove counters
for _ in v..0 {
self.counters.pop();
}
}
// clearing the entry value clears the entry widget
self.entry.set_text("");
}
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/entry_tracker.rs (line 54)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
self.reset();
match msg {
AppMsg::Modify(value) => {
self.entry = value;
if let Ok(v) = self.entry.parse::<i32>() {
if v.is_positive() {
// add as many counters as user entered
for _ in 0..v {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
} else if v.is_negative() {
// remove counters
for _ in v..0 {
self.counters.pop();
}
}
// clearing the entry value clears the entry widget,
// as it is tracked in view! if empty
self.entry.clear();
}
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
sourcepub fn get(&self, index: usize) -> Option<&Data>
pub fn get(&self, index: usize) -> Option<&Data>
Get a reference to data stored at index
.
Examples found in repository
relm4-examples/libadwaita/examples/advent_calendar.rs (line 142)
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Update => {
// Check all entries
for i in 0..self.calendar_entries.len() {
// If counter > 1, count down
let needs_update = self.calendar_entries.get(i).unwrap().time_left != 0;
if needs_update {
let entry = self.calendar_entries.get_mut(i).unwrap();
entry.time_left = entry.time_left.saturating_sub(1);
}
}
}
}
true
}
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut Data>
pub fn get_mut(&mut self, index: usize) -> Option<&mut Data>
Get a mutable reference to data stored at index
.
Assumes that the data will be modified and the corresponding widget needs to be updated.
Examples found in repository
relm4-examples/libadwaita/examples/sudoku_solver.rs (line 50)
≺ ≻
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
fn from_string(&mut self, input: String) {
for (i, v) in input.chars().enumerate() {
if v != '.' {
let value = v.to_string().parse().unwrap();
if let Some(v) = self.values.get_mut(i) {
v.value = value;
}
}
}
}
}
impl Model for AppModel {
type Msg = AppMsg;
type Widgets = AppWidgets;
type Components = ();
}
impl AppUpdate for AppModel {
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Solve => {
let content = self.to_line_string();
let sudoku = Sudoku::from_str_line(content.as_str()).unwrap();
if let Some(solution) = sudoku.solve_one() {
self.from_string(solution.to_string());
}
}
AppMsg::Clear => {
for index in 0..self.values.len() {
if let Some(v) = self.values.get_mut(index) {
v.value = 0;
}
}
}
AppMsg::Update(index, value) => {
if let Some(v) = self.values.get_mut(index) {
v.value = value;
}
}
}
true
}
More examples
relm4-examples/examples/to_do.rs (line 80)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::SetCompleted((index, completed)) => {
if let Some(task) = self.tasks.get_mut(index) {
task.completed = completed;
}
}
AppMsg::AddEntry(name) => {
self.tasks.push(Task {
name,
completed: false,
});
}
}
true
}
relm4-examples/examples/grid_factory.rs (line 103)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.data.push(Data {
counter: self.counter,
});
self.counter += 1;
}
AppMsg::Remove => {
self.data.pop();
}
AppMsg::Clicked(index) => {
if let Some(data) = self.data.get_mut(index) {
data.counter = data.counter.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/factory_manual.rs (line 41)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/stack_factory.rs (line 41)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
relm4-examples/examples/factory.rs (line 41)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Add => {
self.counters.push(Counter {
value: self.created_counters,
});
self.created_counters += 1;
}
AppMsg::Remove => {
self.counters.pop();
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.get_mut(index) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
true
}
Additional examples can be found in:
sourceimpl<Data, View> FactoryVec<Data> where
Data: FactoryPrototype<Factory = Self, View = View>,
View: FactoryView<Data::Root>,
impl<Data, View> FactoryVec<Data> where
Data: FactoryPrototype<Factory = Self, View = View>,
View: FactoryView<Data::Root>,
sourcepub fn iter(&self) -> Iter<'_, Data>
pub fn iter(&self) -> Iter<'_, Data>
Get an immutable iterator for this type
Examples found in repository
relm4-examples/libadwaita/examples/sudoku_solver.rs (line 35)
33 34 35 36 37 38 39 40 41 42 43 44
fn to_line_string(&self) -> String {
let mut res = String::new();
for v in self.values.iter() {
let string = match v.value {
0 => String::from("."),
v @ 1..=9 => format!("{v}"),
v => panic!("{v} is not defined"),
};
res.push_str(string.as_str())
}
res
}
Trait Implementations
sourceimpl<Data: Debug> Debug for FactoryVec<Data> where
Data: FactoryPrototype,
Data::Widgets: Debug,
Data::View: Debug,
Data::Root: Debug,
impl<Data: Debug> Debug for FactoryVec<Data> where
Data: FactoryPrototype,
Data::Widgets: Debug,
Data::View: Debug,
Data::Root: Debug,
sourceimpl<Data: Default> Default for FactoryVec<Data> where
Data: FactoryPrototype,
Data::Widgets: Default,
Data::View: Default,
Data::Root: Default,
impl<Data: Default> Default for FactoryVec<Data> where
Data: FactoryPrototype,
Data::Widgets: Default,
Data::View: Default,
Data::Root: Default,
sourcefn default() -> FactoryVec<Data>
fn default() -> FactoryVec<Data>
Returns the “default value” for a type. Read more
sourceimpl<Data, View> Factory<Data, View> for FactoryVec<Data> where
Data: FactoryPrototype<Factory = Self, View = View>,
View: FactoryView<Data::Root>,
impl<Data, View> Factory<Data, View> for FactoryVec<Data> where
Data: FactoryPrototype<Factory = Self, View = View>,
View: FactoryView<Data::Root>,
Auto Trait Implementations
impl<Data> !RefUnwindSafe for FactoryVec<Data>
impl<Data> Send for FactoryVec<Data> where
Data: Send,
<<Data as FactoryPrototype>::View as FactoryView<<Data as FactoryPrototype>::Root>>::Root: Send,
<Data as FactoryPrototype>::Widgets: Send,
impl<Data> !Sync for FactoryVec<Data>
impl<Data> Unpin for FactoryVec<Data> where
Data: Unpin,
<<Data as FactoryPrototype>::View as FactoryView<<Data as FactoryPrototype>::Root>>::Root: Unpin,
<Data as FactoryPrototype>::Widgets: Unpin,
impl<Data> UnwindSafe for FactoryVec<Data> where
Data: UnwindSafe,
<<Data as FactoryPrototype>::View as FactoryView<<Data as FactoryPrototype>::Root>>::Root: UnwindSafe,
<Data as FactoryPrototype>::Widgets: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more