Struct relm4::typed_view::TypedListItem
source · pub struct TypedListItem<T> { /* private fields */ }
Expand description
And item of a list::TypedListView
.
The interface is very similar to std::cell::RefCell
.
Ownership is calculated at runtime, so you have to borrow the
value explicitly which might panic if done incorrectly.
Implementations§
source§impl<T: 'static> TypedListItem<T>
impl<T: 'static> TypedListItem<T>
sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Immutably borrows the wrapped value.
The borrow lasts until the returned Ref
exits scope. Multiple
immutable borrows can be taken out at the same time.
§Panics
Panics if the value is currently mutably borrowed.
For a non-panicking variant, use
try_borrow
.
sourcepub fn borrow_mut(&self) -> RefMut<'_, T>
pub fn borrow_mut(&self) -> RefMut<'_, T>
Mutably borrows the wrapped value.
The borrow lasts until the returned RefMut
or all RefMut
s derived
from it exit scope. The value cannot be borrowed while this borrow is
active.
§Panics
Panics if the value is currently borrowed.
For a non-panicking variant, use
try_borrow_mut
.
Examples found in repository?
examples/typed_column_view.rs (line 181)
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
Msg::Append => {
// Add 10 items
for _ in 0..10 {
self.counter = self.counter.wrapping_add(1);
self.view_wrapper.append(MyListItem::new(self.counter));
}
// Count up the first item
let first_item = self.view_wrapper.get(0).unwrap();
let first_binding = &mut first_item.borrow_mut().binding;
let mut guard = first_binding.guard();
*guard += 1;
}
Msg::Remove => {
// Remove the second item
self.view_wrapper.remove(1);
}
Msg::OnlyShowEven(show_only_even) => {
// Disable or enable the first filter
self.view_wrapper.set_filter_status(0, show_only_even);
}
}
}
More examples
examples/typed_grid_view.rs (line 174)
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
Msg::Append => {
// Add 10 items
for _ in 0..10 {
self.counter = self.counter.wrapping_add(1);
self.grid_view_wrapper.append(MyGridItem::new(self.counter));
}
// Count up the first item
let first_item = self.grid_view_wrapper.get(0).unwrap();
let first_binding = &mut first_item.borrow_mut().binding;
let mut guard = first_binding.guard();
*guard += 1;
}
Msg::Remove => {
// Remove the second item
self.grid_view_wrapper.remove(1);
}
Msg::OnlyShowEven(show_only_even) => {
// Disable or enable the first filter
self.grid_view_wrapper.set_filter_status(0, show_only_even);
}
}
}
examples/typed_list_view.rs (line 167)
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
Msg::Append => {
// Add 10 items
for _ in 0..10 {
self.counter = self.counter.wrapping_add(1);
self.list_view_wrapper.append(MyListItem::new(self.counter));
}
// Count up the first item
let first_item = self.list_view_wrapper.get(0).unwrap();
let first_binding = &mut first_item.borrow_mut().binding;
let mut guard = first_binding.guard();
*guard += 1;
}
Msg::Remove => {
// Remove the second item
self.list_view_wrapper.remove(1);
}
Msg::OnlyShowEven(show_only_even) => {
// Disable or enable the first filter
self.list_view_wrapper.set_filter_status(0, show_only_even);
}
}
}
Trait Implementations§
source§impl<T: Clone> Clone for TypedListItem<T>
impl<T: Clone> Clone for TypedListItem<T>
source§fn clone(&self) -> TypedListItem<T>
fn clone(&self) -> TypedListItem<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<T> Freeze for TypedListItem<T>
impl<T> !RefUnwindSafe for TypedListItem<T>
impl<T> !Send for TypedListItem<T>
impl<T> !Sync for TypedListItem<T>
impl<T> Unpin for TypedListItem<T>
impl<T> !UnwindSafe for TypedListItem<T>
Blanket Implementations§
source§impl<C> AsyncPosition<()> for C
impl<C> AsyncPosition<()> for C
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more