TypedListItem

Struct 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>

Source

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.

Examples found in repository?
relm4/examples/typed_column_view.rs (line 181)
170    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
171        match msg {
172            Msg::Append => {
173                // Add 10 items
174                for _ in 0..10 {
175                    self.counter = self.counter.wrapping_add(1);
176                    self.view_wrapper.append(MyListItem::new(self.counter));
177                }
178
179                self.view_wrapper
180                    .iter()
181                    .for_each(|row| println!("item {}", row.borrow().value));
182
183                // Count up the first item
184                let first_item = self.view_wrapper.get(0).unwrap();
185                let first_binding = &mut first_item.borrow_mut().binding;
186                let mut guard = first_binding.guard();
187                *guard += 1;
188            }
189            Msg::Remove => {
190                // Remove the second item
191                self.view_wrapper.remove(1);
192            }
193            Msg::OnlyShowEven(show_only_even) => {
194                // Disable or enable the first filter
195                self.view_wrapper.set_filter_status(0, show_only_even);
196            }
197        }
198    }
More examples
Hide additional examples
relm4/examples/typed_grid_view.rs (line 174)
163    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
164        match msg {
165            Msg::Append => {
166                // Add 10 items
167                for _ in 0..10 {
168                    self.counter = self.counter.wrapping_add(1);
169                    self.grid_view_wrapper.append(MyGridItem::new(self.counter));
170                }
171
172                self.grid_view_wrapper
173                    .iter()
174                    .for_each(|row| println!("item {}", row.borrow().value));
175
176                // Count up the first item
177                let first_item = self.grid_view_wrapper.get(0).unwrap();
178                let first_binding = &mut first_item.borrow_mut().binding;
179                let mut guard = first_binding.guard();
180                *guard += 1;
181            }
182            Msg::Remove => {
183                // Remove the second item
184                self.grid_view_wrapper.remove(1);
185            }
186            Msg::OnlyShowEven(show_only_even) => {
187                // Disable or enable the first filter
188                self.grid_view_wrapper.set_filter_status(0, show_only_even);
189            }
190        }
191    }
relm4/examples/typed_list_view.rs (line 167)
156    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
157        match msg {
158            Msg::Append => {
159                // Add 10 items
160                for _ in 0..10 {
161                    self.counter = self.counter.wrapping_add(1);
162                    self.list_view_wrapper.append(MyListItem::new(self.counter));
163                }
164
165                self.list_view_wrapper
166                    .iter()
167                    .for_each(|row| println!("item {}", row.borrow().value));
168
169                // Count up the first item
170                let first_item = self.list_view_wrapper.get(0).unwrap();
171                let first_binding = &mut first_item.borrow_mut().binding;
172                let mut guard = first_binding.guard();
173                *guard += 1;
174            }
175            Msg::Remove => {
176                // Remove the second item
177                self.list_view_wrapper.remove(1);
178            }
179            Msg::OnlyShowEven(show_only_even) => {
180                // Disable or enable the first filter
181                self.list_view_wrapper.set_filter_status(0, show_only_even);
182            }
183        }
184    }
Source

pub fn borrow_mut(&self) -> RefMut<'_, T>

Mutably borrows the wrapped value.

The borrow lasts until the returned RefMut or all RefMuts 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?
relm4/examples/typed_column_view.rs (line 185)
170    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
171        match msg {
172            Msg::Append => {
173                // Add 10 items
174                for _ in 0..10 {
175                    self.counter = self.counter.wrapping_add(1);
176                    self.view_wrapper.append(MyListItem::new(self.counter));
177                }
178
179                self.view_wrapper
180                    .iter()
181                    .for_each(|row| println!("item {}", row.borrow().value));
182
183                // Count up the first item
184                let first_item = self.view_wrapper.get(0).unwrap();
185                let first_binding = &mut first_item.borrow_mut().binding;
186                let mut guard = first_binding.guard();
187                *guard += 1;
188            }
189            Msg::Remove => {
190                // Remove the second item
191                self.view_wrapper.remove(1);
192            }
193            Msg::OnlyShowEven(show_only_even) => {
194                // Disable or enable the first filter
195                self.view_wrapper.set_filter_status(0, show_only_even);
196            }
197        }
198    }
More examples
Hide additional examples
relm4/examples/typed_grid_view.rs (line 178)
163    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
164        match msg {
165            Msg::Append => {
166                // Add 10 items
167                for _ in 0..10 {
168                    self.counter = self.counter.wrapping_add(1);
169                    self.grid_view_wrapper.append(MyGridItem::new(self.counter));
170                }
171
172                self.grid_view_wrapper
173                    .iter()
174                    .for_each(|row| println!("item {}", row.borrow().value));
175
176                // Count up the first item
177                let first_item = self.grid_view_wrapper.get(0).unwrap();
178                let first_binding = &mut first_item.borrow_mut().binding;
179                let mut guard = first_binding.guard();
180                *guard += 1;
181            }
182            Msg::Remove => {
183                // Remove the second item
184                self.grid_view_wrapper.remove(1);
185            }
186            Msg::OnlyShowEven(show_only_even) => {
187                // Disable or enable the first filter
188                self.grid_view_wrapper.set_filter_status(0, show_only_even);
189            }
190        }
191    }
relm4/examples/typed_list_view.rs (line 171)
156    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
157        match msg {
158            Msg::Append => {
159                // Add 10 items
160                for _ in 0..10 {
161                    self.counter = self.counter.wrapping_add(1);
162                    self.list_view_wrapper.append(MyListItem::new(self.counter));
163                }
164
165                self.list_view_wrapper
166                    .iter()
167                    .for_each(|row| println!("item {}", row.borrow().value));
168
169                // Count up the first item
170                let first_item = self.list_view_wrapper.get(0).unwrap();
171                let first_binding = &mut first_item.borrow_mut().binding;
172                let mut guard = first_binding.guard();
173                *guard += 1;
174            }
175            Msg::Remove => {
176                // Remove the second item
177                self.list_view_wrapper.remove(1);
178            }
179            Msg::OnlyShowEven(show_only_even) => {
180                // Disable or enable the first filter
181                self.list_view_wrapper.set_filter_status(0, show_only_even);
182            }
183        }
184    }

Trait Implementations§

Source§

impl<T: Clone> Clone for TypedListItem<T>

Source§

fn clone(&self) -> TypedListItem<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for TypedListItem<T>

Source§

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

Formats the value using the given formatter. Read more

Auto 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<T> Any for T
where 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 T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

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 T
where U: From<T>,

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, I> Position<(), I> for C

Source§

fn position(&self, _index: &I)

Returns the position. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

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