FerroList
struct · ferroui-base · v0.5.0
struct FerroList<T>
A notifying list.
Enumeration works on a snapshot, so the list may be modified from within an enumeration or a change notification. The snapshot shares storage with the list and is only copied if the list is modified while it is alive.
The list is a reference object: the value is a shared handle, clones refer to the same list and handles compare by identity.
Members
ptr_eqnewfrom_itemsadd_collection_changedremove_collection_changedhas_collection_changed_subscriberscountis_emptycapacityset_capacityreset_behaviorset_reset_behaviorvalidateset_validatevalidatorset_validatorgettry_getsetsnapshotto_vecfor_eachaddadd_rangeinsertinsert_rangemove_itemmove_rangeremove_atremove_rangeclearcopy_toget_rangeensure_capacitycontainsindex_ofremoveremove_all
ptr_eq
fn ptr_eq(self: &Self, other: &Self) -> bool
Whether two handles refer to the same list.
new
fn new() -> Self
Creates an empty list.
from_items
fn from_items(items: impl IntoIterator<Item = T>) -> Self
Creates a list with initial items.
add_collection_changed
fn add_collection_changed(self: &Self, handler: Rc<CollectionChangedHandler<T>>) -> u64
Subscribes to changes. Returns a token for
remove_collection_changed.
remove_collection_changed
fn remove_collection_changed(self: &Self, token: u64) -> bool
Unsubscribes a handler.
has_collection_changed_subscribers
fn has_collection_changed_subscribers(self: &Self) -> bool
Whether anything is subscribed to changes, typed or untyped.
count
fn count(self: &Self) -> usize
The number of items in the list.
is_empty
fn is_empty(self: &Self) -> bool
capacity
fn capacity(self: &Self) -> usize
The number of items the list can hold before its storage grows.
set_capacity
fn set_capacity(self: &Self, capacity: usize)
Sets the number of items the list can hold before its storage grows.
Panics
Panics if capacity is less than the number of items, as the
managed original throws.
reset_behavior
fn reset_behavior(self: &Self) -> ResetBehavior
The reset behavior of the list.
set_reset_behavior
fn set_reset_behavior(self: &Self, value: ResetBehavior)
validate
fn validate(self: &Self) -> Option<Rc<dyn Fn(&T) -> ()>>
where T: 'static
The validation routine that is invoked for every item before it is added to the list.
set_validate
fn set_validate(self: &Self, value: Option<Rc<dyn Fn(&T) -> ()>>)
where T: 'static
Sets a validation routine that is invoked for every item before it is added to the list; it rejects an item by panicking.
validator
fn validator(self: &Self) -> Option<Rc<dyn IFerroListItemValidator<T>>>
where T: 'static
The validator that is invoked for every item before it is added to the list.
set_validator
fn set_validator(self: &Self, value: Option<Rc<dyn IFerroListItemValidator<T>>>)
get
fn get(self: &Self, index: usize) -> T
The item at index. Panics if out of range.
try_get
fn try_get(self: &Self, index: usize) -> Option<T>
The item at index, if in range.
set
fn set(self: &Self, index: usize, value: T)
where T: PartialEq
Replaces the item at index.
snapshot
fn snapshot(self: &Self) -> Rc<Vec<T>>
A snapshot of the items. It stays valid and unchanged if the list is modified.
to_vec
fn to_vec(self: &Self) -> Vec<T>
Copies the items into a vector.
for_each
fn for_each(self: &Self, f: impl FnMut(&T) -> ())
Calls f for each item of a snapshot of the list.
add
fn add(self: &Self, item: T)
Adds an item to the collection.
add_range
fn add_range(self: &Self, items: impl IntoIterator<Item = T>)
Adds multiple items to the collection.
insert
fn insert(self: &Self, index: usize, item: T)
Inserts an item at the specified index.
insert_range
fn insert_range(self: &Self, index: usize, items: impl IntoIterator<Item = T>)
Inserts multiple items at the specified index.
move_item
fn move_item(self: &Self, old_index: usize, new_index: usize)
Moves an item to a new index.
move_range
fn move_range(self: &Self, old_index: usize, count: usize, new_index: usize)
Moves multiple items to a new index.
remove_at
fn remove_at(self: &Self, index: usize)
Removes the item at the specified index.
remove_range
fn remove_range(self: &Self, index: usize, count: usize)
Removes a range of elements from the collection.
clear
fn clear(self: &Self)
Removes all items from the collection.
copy_to
fn copy_to(self: &Self, array: &mut [T], array_index: usize)
Copies the items into array, starting at array_index.
Panics
Panics if array is too small, as the managed original throws.
get_range
fn get_range(self: &Self, index: usize, count: usize) -> Vec<T>
Gets a range of items from the collection.
ensure_capacity
fn ensure_capacity(self: &Self, capacity: usize)
Ensures that the capacity of the list is at least capacity.
contains
fn contains(self: &Self, item: &T) -> bool
Tests whether the collection contains an item.
index_of
fn index_of(self: &Self, item: &T) -> Option<usize>
The index of an item in the collection.
remove
fn remove(self: &Self, item: &T) -> bool
Removes an item from the collection. Returns true if it was present.
remove_all
fn remove_all(self: &Self, items: impl IntoIterator<Item = T>)
Removes multiple items from the collection.
Each run of adjacent items that are removed is notified as one removal, from the end of the list to its start.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedErasedDestructorIntoEitherWeakEventSenderClonePartialEqDebugDefaultINotifyCollectionChangedINotifyPropertyChangedIFerroList<T>IFerroReadOnlyList<T>MarkupTypedValueTypeRegistration
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.