RopeBinding

Struct RopeBinding 

Source
pub struct RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Unpin + Clone + PartialEq + Default,
{ /* private fields */ }
Expand description

A rope binding binds a vector of cells and attributes

It’s also possible to use a normal Binding<Vec<_>> for this purpose. A rope binding has a couple of advantages though: it can handle very large collections of items and it can notify only the relevant changes instead of always notifying the entire structure.

Rope bindings are ideal for representing text areas in user interfaces, but can be used for any collection data structure.

Implementations§

Source§

impl<Cell, Attribute> RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Source

pub fn from_mutable(binding: &RopeBindingMut<Cell, Attribute>) -> Self

Generates a rope binding by tracking a mutable binding

Source

pub fn from_stream<S>(stream: S) -> Self
where S: 'static + Stream<Item = RopeAction<Cell, Attribute>> + Unpin + Send,

Creates a new rope binding from a stream of changes

Source

pub fn computed<TFn, TValueIter>(calculate_value: TFn) -> Self
where TFn: 'static + Send + Fn() -> TValueIter, TValueIter: IntoIterator<Item = Cell>,

Creates a rope binding that entirely replaces its set of cells by following a computed value (the attributes will always have their default values when using this method)

Source

pub fn len(&self) -> usize

Returns the number of cells in this rope

Source

pub fn read_cells<'a>( &'a self, range: Range<usize>, ) -> impl 'a + Iterator<Item = Cell>

Reads the cell values for a range in this rope

Source

pub fn read_attributes<'a>(&'a self, pos: usize) -> (Attribute, Range<usize>)

Returns the attributes set at the specified location and their extent

Source§

impl<Cell, Attribute> RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq + Hash + Ord + Eq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Source

pub fn computed_difference<TFn: 'static + Send + Fn() -> TValueIter, TValueIter: IntoIterator<Item = Cell>>( calculate_value: TFn, ) -> Self

Similar to computed, but instead of always replacing the entire rope, replaces only the sections that are different between the two values.

This currently stores up to three copies of the list of cells (generally only two, but up to three while computing diffs). This is not efficient for sending edits, but useful when they’re not easily known. Use RopeBindingMut to send edits as they arrive instead.

In spite of this, this is still useful when updating something like a user interface where only the changes should be sent to the user, or for generating edit lists when the data source is not already formatted in a suitable form.

Trait Implementations§

Source§

impl<Cell, Attribute> Bound for RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Trait implemented by something that is bound to a value

Source§

fn get(&self) -> AttributedRope<Cell, Attribute>

Retrieves the value stored by this binding

Source§

type Value = AttributedRope<Cell, Attribute>

Source§

fn watch( &self, what: Arc<dyn Notifiable>, ) -> Arc<dyn Watcher<AttributedRope<Cell, Attribute>>>

Creates a watcher: this provides a way to retrieve the value stored in this binding, and will call the notification function if the value has changed since it was last read. Read more
Source§

impl<Cell, Attribute> BoundRope<Cell, Attribute> for RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Source§

fn follow_changes(&self) -> RopeStream<Cell, Attribute>

Creates a stream that follows the changes to this rope

Source§

fn follow_changes_retained(&self) -> RopeStream<Cell, Attribute>

Creates a stream that follows the changes to this rope

The stream will continue even if the rope binding is dropped (this is possible for RopeBinding as RopeBinding itself might be following a stream)

Source§

impl<Cell, Attribute> Changeable for RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Source§

fn when_changed(&self, what: Arc<dyn Notifiable>) -> Box<dyn Releasable>

Supplies a function to be notified when this item is changed

This event is only fired after the value has been read since the most recent change. Note that this means if the value is never read, this event may never fire. This behaviour is desirable when deferring updates as it prevents large cascades of ‘changed’ events occurring for complicated dependency trees.

The releasable that’s returned has keep_alive turned off by default, so be sure to store it in a variable or call keep_alive() to keep it around (if the event never seems to fire, this is likely to be the problem)

Source§

impl<Cell, Attribute> Clone for RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Source§

fn clone(&self) -> RopeBinding<Cell, Attribute>

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<Cell, Attribute> Drop for RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Cell, Attribute> From<&RopeBindingMut<Cell, Attribute>> for RopeBinding<Cell, Attribute>
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default,

Source§

fn from( mut_binding: &RopeBindingMut<Cell, Attribute>, ) -> RopeBinding<Cell, Attribute>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Cell, Attribute> Freeze for RopeBinding<Cell, Attribute>

§

impl<Cell, Attribute> !RefUnwindSafe for RopeBinding<Cell, Attribute>

§

impl<Cell, Attribute> Send for RopeBinding<Cell, Attribute>

§

impl<Cell, Attribute> Sync for RopeBinding<Cell, Attribute>

§

impl<Cell, Attribute> Unpin for RopeBinding<Cell, Attribute>

§

impl<Cell, Attribute> !UnwindSafe for RopeBinding<Cell, Attribute>

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<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<Cell, Attribute, TRope> BoundRopeExt<Cell, Attribute> for TRope
where Cell: 'static + Send + Unpin + Clone + PartialEq, Attribute: 'static + Send + Sync + Clone + Unpin + PartialEq + Default, TRope: BoundRope<Cell, Attribute>,

Source§

fn chain<OtherRope>(&self, other: &OtherRope) -> RopeBinding<Cell, Attribute>
where OtherRope: BoundRope<Cell, Attribute>,

Returns a new rope that concatenates the contents of this rope and another one
Source§

fn map<NewCell, MapFn>(&self, map_fn: MapFn) -> RopeBinding<NewCell, Attribute>
where MapFn: 'static + Send + Fn(Cell) -> NewCell, NewCell: 'static + Send + Unpin + Clone + PartialEq,

Returns a new rope that maps the values of the cells to new values
Source§

impl<TBinding> BoundValueComputeExt for TBinding
where TBinding: 'static + Clone + Bound,

Source§

fn compute<TResultValue, TComputeFn>( &self, map_fn: TComputeFn, ) -> BindRef<TResultValue>
where TResultValue: 'static + Clone + Send, TComputeFn: 'static + Send + Sync + Fn(&TBinding) -> TResultValue,

Transforms the value of this binding using a compute function Read more
Source§

impl<TBinding> BoundValueMapExt for TBinding
where TBinding: 'static + Clone + Bound,

Source§

type Value = <TBinding as Bound>::Value

Source§

fn map_binding<TMapValue, TMapFn>( &self, map_fn: TMapFn, ) -> MapBinding<TBinding, TMapValue, TMapFn>
where TMapValue: 'static + Clone + Send, TMapFn: 'static + Send + Sync + Fn(<TBinding as BoundValueMapExt>::Value) -> TMapValue,

Transforms the value of this binding using a mapping function 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, 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<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.