[][src]Struct core_extensions::slices::SliceBias

pub struct SliceBias {
    pub start: BiasDirection,
    pub end: BiasDirection,
}

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]

impl From<(BiasDirection,)> for SliceBias[src]

impl From<BiasDirection> for SliceBias[src]

impl PartialEq<SliceBias> for SliceBias[src]

impl StructuralEq for SliceBias[src]

impl StructuralPartialEq for SliceBias[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The error type returned when the conversion fails.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.