[−][src]Struct core_extensions::slices::SliceBias
What directions SliceExt::slice_lossy[_mut] is biased towards.
For str
this has the effect of going in those directions if
the start/end bound is between char boundaries.
For [T]
this has no effect and
it is recommended to use ()
as a parameter instead.
Example
use core_extensions::SliceExt; use core_extensions::slices::SliceBias; let word="niño"; assert_eq!( word.char_indices().collect::<Vec<_>>(), &[(0,'n'),(1,'i'),(2,'ñ'),(4,'o')] ); assert_eq!(word.slice_lossy(0..1000 ,() ),word); assert_eq!(word.slice_lossy(10..10000 ,() ),""); assert_eq!(word.slice_lossy(0 ..4 ,() ),"niñ"); assert_eq!(word.slice_lossy(0 ..3 ,() ),"niñ"); assert_eq!(word.slice_lossy(0 ..2 ,() ),"ni"); assert_eq!(word.slice_lossy(3 ..3 ,() ),"ñ"); assert_eq!(word.slice_lossy(3 ..4 ,() ),"ñ"); assert_eq!(word.slice_lossy(2 ..3 ,() ),"ñ"); assert_eq!(word.slice_lossy(0..1000 ,SliceBias::OUT),word); assert_eq!(word.slice_lossy(10..10000 ,SliceBias::OUT),""); assert_eq!(word.slice_lossy(0 ..4 ,SliceBias::OUT),"niñ"); assert_eq!(word.slice_lossy(0 ..3 ,SliceBias::OUT),"niñ"); assert_eq!(word.slice_lossy(0 ..2 ,SliceBias::OUT),"ni"); assert_eq!(word.slice_lossy(3 ..3 ,SliceBias::OUT),"ñ"); assert_eq!(word.slice_lossy(3 ..4 ,SliceBias::OUT),"ñ"); assert_eq!(word.slice_lossy(2 ..3 ,SliceBias::OUT),"ñ"); assert_eq!(word.slice_lossy(0 ..10000 ,SliceBias::IN),word); assert_eq!(word.slice_lossy(10..10000 ,SliceBias::IN),""); assert_eq!(word.slice_lossy(0 ..4 ,SliceBias::IN),"niñ"); assert_eq!(word.slice_lossy(0 ..3 ,SliceBias::IN),"ni"); assert_eq!(word.slice_lossy(0 ..2 ,SliceBias::IN),"ni"); assert_eq!(word.slice_lossy(3 ..3 ,SliceBias::IN),""); assert_eq!(word.slice_lossy(3 ..4 ,SliceBias::IN),""); assert_eq!(word.slice_lossy(2 ..3 ,SliceBias::IN),""); assert_eq!(word.slice_lossy(0..1000 ,SliceBias::LEFT),word); assert_eq!(word.slice_lossy(10..10000 ,SliceBias::LEFT),""); assert_eq!(word.slice_lossy(0 ..4 ,SliceBias::LEFT),"niñ"); assert_eq!(word.slice_lossy(0 ..3 ,SliceBias::LEFT),"ni"); assert_eq!(word.slice_lossy(0 ..2 ,SliceBias::LEFT),"ni"); assert_eq!(word.slice_lossy(3 ..3 ,SliceBias::LEFT),""); assert_eq!(word.slice_lossy(3 ..4 ,SliceBias::LEFT),"ñ"); assert_eq!(word.slice_lossy(2 ..3 ,SliceBias::LEFT),""); assert_eq!(word.slice_lossy(0..1000 ,SliceBias::RIGHT),word); assert_eq!(word.slice_lossy(10..10000 ,SliceBias::RIGHT),""); assert_eq!(word.slice_lossy(0 ..4 ,SliceBias::RIGHT),"niñ"); assert_eq!(word.slice_lossy(0 ..3 ,SliceBias::RIGHT),"niñ"); assert_eq!(word.slice_lossy(0 ..2 ,SliceBias::RIGHT),"ni"); assert_eq!(word.slice_lossy(3 ..3 ,SliceBias::RIGHT),""); assert_eq!(word.slice_lossy(3 ..4 ,SliceBias::RIGHT),""); assert_eq!(word.slice_lossy(2 ..3 ,SliceBias::RIGHT),"ñ");
Fields
start: BiasDirection
bias of the start bound
end: BiasDirection
bias of the end bound
Implementations
impl SliceBias
[src]
pub const IN: Self
[src]
Biased inwards,start bounds go right,end bounds go left.
pub const OUT: Self
[src]
Biased outwards,start bounds go left,end bounds go right.
pub const LEFT: Self
[src]
Biased leftwards,both bounds go left.
pub const RIGHT: Self
[src]
Biased rightwards.both bounds go right.
Trait Implementations
impl Clone for SliceBias
[src]
impl Copy for SliceBias
[src]
impl Debug for SliceBias
[src]
impl Eq for SliceBias
[src]
impl From<()> for SliceBias
[src]
impl From<(BiasDirection, BiasDirection)> for SliceBias
[src]
pub fn from((start, end): (BiasDirection, BiasDirection)) -> Self
[src]
impl From<(BiasDirection,)> for SliceBias
[src]
pub fn from((dir): (BiasDirection,)) -> Self
[src]
impl From<BiasDirection> for SliceBias
[src]
pub fn from(dir: BiasDirection) -> Self
[src]
impl PartialEq<SliceBias> for SliceBias
[src]
impl StructuralEq for SliceBias
[src]
impl StructuralPartialEq for SliceBias
[src]
Auto Trait Implementations
impl RefUnwindSafe for SliceBias
[src]
impl Send for SliceBias
[src]
impl Sync for SliceBias
[src]
impl Unpin for SliceBias
[src]
impl UnwindSafe for SliceBias
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The error type returned when the conversion fails.
pub fn try_into(Self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,