[][src]Struct json_peek::util::Span

pub struct Span {
    pub start: usize,
    pub end: usize,
}

General position information of string

let a = Span::new(1, 5);
let b = Span::from(1..=5);

assert_eq!(a, b);
let span = Span::new(2, 4);
span.trim(1); // Equal to: Span::new(3, 3);

Fields

start: usizeend: usize

Methods

impl Span[src]

pub const fn new(start: usize, end: usize) -> Span[src]

pub const fn range(&self) -> RangeInclusive<usize>[src]

Get the range of this Span

pub const fn start_point(&self) -> Span[src]

Create a point out of the start position of this Span

pub const fn end_point(&self) -> Span[src]

Create a point out of the end position of this Span

pub const fn is_point(&self) -> bool[src]

Zero-width Span is considered to be a point

pub const fn trim(&self, offset: usize) -> Span[src]

Shrink the size of Span by some offset from both size

Does not check for overflow

let span = Span::new(2, 4);

assert_eq!(span.trim(1), Span::new(3, 3));
assert_eq!(span.trim(2), Span::new(4, 2));

You can cause integer underflow/overflow with this method if not careful.

let span = Span::new(0, 4);
span.trim(5); // <- will panic!!

pub fn from_span(left: Span, right: Span) -> Span[src]

Create Span from two other Spans This function will construct the biggest possible Span

let a = Span::new(1, 5);
let b = Span::new(4, 10);
 
assert_eq!(Span::from_span(a, b), Span::new(1, 10));

pub const fn test() -> Span[src]

Span value for testing purpose

Trait Implementations

impl Add<Span> for Span[src]

type Output = Span

The resulting type after applying the + operator.

impl Add<usize> for Span[src]

type Output = Span

The resulting type after applying the + operator.

impl AddAssign<Span> for Span[src]

impl AddAssign<usize> for Span[src]

impl Clone for Span[src]

impl Copy for Span[src]

impl Debug for Span[src]

impl Default for Span[src]

impl Display for Span[src]

impl Eq for Span[src]

impl From<RangeInclusive<usize>> for Span[src]

impl Hash for Span[src]

impl PartialEq<Span> for Span[src]

impl StructuralEq for Span[src]

impl StructuralPartialEq for Span[src]

impl Sub<Span> for Span[src]

type Output = Span

The resulting type after applying the - operator.

impl Sub<usize> for Span[src]

type Output = Span

The resulting type after applying the - operator.

impl SubAssign<usize> for Span[src]

Auto Trait Implementations

impl RefUnwindSafe for Span

impl Send for Span

impl Sync for Span

impl Unpin for Span

impl UnwindSafe for Span

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> ToString for T where
    T: Display + ?Sized
[src]

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 type returned in the event of a conversion error.