@@ -61,6 +61,7 @@ pub mod sparse;
6161/// ```
6262pub trait VectorView < T : ?Sized > {
6363 fn len ( & self ) -> usize ;
64+ fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
6465 fn at ( & self , i : usize ) -> & T ;
6566
6667 /// Returns a refernce to the `i`-th entry of the vector view, causing
@@ -70,16 +71,16 @@ pub trait VectorView<T: ?Sized> {
7071 ///
7172 /// Same as for [`slice::get_unchecked()`]. More concretely, calling this method with an
7273 /// out-of-bounds index is undefined behavior even if the resulting reference is not used.
73- unsafe fn at_unchecked < ' a > ( & self , i : usize ) -> & T { self . at ( i) }
74+ unsafe fn at_unchecked ( & self , i : usize ) -> & T { self . at ( i) }
7475
7576 /// Calls `op` with `self` if this vector view supports sparse access.
7677 /// Otherwise, `()` is returned.
7778 ///
7879 /// This is basically a workaround that enables users to specialize on
7980 /// `V: VectorViewSparse`, even though specialization currently does not support
8081 /// this.
81- fn specialize_sparse < ' a , Op : SparseVectorViewOperation < T > > ( & ' a self , _op : Op ) -> Result < Op :: Output < ' a > , ( ) > {
82- Err ( ( ) )
82+ fn specialize_sparse < ' a , Op : SparseVectorViewOperation < T > > ( & ' a self , _op : Op ) -> Option < Op :: Output < ' a > > {
83+ None
8384 }
8485
8586 /// Returns an iterator over all elements in this vector.
@@ -341,7 +342,7 @@ impl<T: ?Sized, V: ?Sized + VectorView<T>> VectorView<T> for Box<V> {
341342
342343 unsafe fn at_unchecked ( & self , i : usize ) -> & T { unsafe { ( * * self ) . at_unchecked ( i) } }
343344
344- fn specialize_sparse < ' a , Op : SparseVectorViewOperation < T > > ( & ' a self , op : Op ) -> Result < Op :: Output < ' a > , ( ) > {
345+ fn specialize_sparse < ' a , Op : SparseVectorViewOperation < T > > ( & ' a self , op : Op ) -> Option < Op :: Output < ' a > > {
345346 ( * * self ) . specialize_sparse ( op)
346347 }
347348
@@ -383,7 +384,7 @@ impl<T: ?Sized, V: ?Sized + VectorView<T>> VectorView<T> for &V {
383384
384385 unsafe fn at_unchecked ( & self , i : usize ) -> & T { unsafe { ( * * self ) . at_unchecked ( i) } }
385386
386- fn specialize_sparse < ' b , Op : SparseVectorViewOperation < T > > ( & ' b self , op : Op ) -> Result < Op :: Output < ' b > , ( ) > {
387+ fn specialize_sparse < ' b , Op : SparseVectorViewOperation < T > > ( & ' b self , op : Op ) -> Option < Op :: Output < ' b > > {
387388 ( * * self ) . specialize_sparse ( op)
388389 }
389390
@@ -412,7 +413,7 @@ impl<T: ?Sized, V: ?Sized + VectorView<T>> VectorView<T> for &mut V {
412413
413414 unsafe fn at_unchecked ( & self , i : usize ) -> & T { unsafe { ( * * self ) . at_unchecked ( i) } }
414415
415- fn specialize_sparse < ' b , Op : SparseVectorViewOperation < T > > ( & ' b self , op : Op ) -> Result < Op :: Output < ' b > , ( ) > {
416+ fn specialize_sparse < ' b , Op : SparseVectorViewOperation < T > > ( & ' b self , op : Op ) -> Option < Op :: Output < ' b > > {
416417 ( * * self ) . specialize_sparse ( op)
417418 }
418419
@@ -488,7 +489,7 @@ pub trait VectorViewMut<T: ?Sized>: VectorView<T> {
488489 ///
489490 /// Same as for [`slice::get_unchecked_mut()`]. More concretely, calling this method with an
490491 /// out-of-bounds index is undefined behavior even if the resulting reference is not used.
491- unsafe fn at_unchecked_mut < ' a > ( & mut self , i : usize ) -> & mut T { self . at_mut ( i) }
492+ unsafe fn at_unchecked_mut ( & mut self , i : usize ) -> & mut T { self . at_mut ( i) }
492493}
493494
494495/// A trait for [`VectorViewMut`]s that support swapping of two elements.
@@ -533,6 +534,7 @@ pub trait SwappableVectorViewMut<T: ?Sized>: VectorViewMut<T> {
533534/// ```
534535pub trait VectorFn < T > {
535536 fn len ( & self ) -> usize ;
537+ fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
536538 fn at ( & self , i : usize ) -> T ;
537539
538540 /// Produces an iterator over the elements of this [`VectorFn`].
0 commit comments