Span

Struct Span 

Source
pub struct Span {
    pub start: SpanValue,
    pub end: SpanValue,
}
Expand description

The Span type represents an area of a file.

Fields§

§start: SpanValue

The start of the Span (Inclusive)

§end: SpanValue

The end of the Span (Exclusive)

Implementations§

Source§

impl Span

Source

pub fn new() -> Self

Creates a new Span. This span will start and end at the 0th character, making it have a length of zero.

Source

pub fn new_from(start: SpanValue, end: SpanValue) -> Self

Creates a new Span from a pair of start and end indexes.

§Panics

Panics if start is greater than end, since spans can’t have a negative length.

Source

pub fn grow_front(&mut self, amount: SpanValue)

Grows the span from the front. This moves the end value up by amount.

Source

pub fn with_grow_front(&self, amount: SpanValue) -> Self

Returns a span that is grown from the front. This moves the end value up by amount.

Source

pub fn grow_back(&mut self, amount: SpanValue)

Grows the span from the back. This moves the start value back by amount.

§Panics

Panics if the start of the span is less than amount, since spans can’t have a negative start value,

Source

pub fn with_grow_back(&self, amount: SpanValue) -> Self

Returns a span that is grown from the back. This moves the start value back by amount.

§Panics

Panics if the start of the span is less than amount, since spans can’t have a negative start value,

Source

pub fn shrink_back(&mut self, amount: SpanValue)

Shrinks the span from the back. This moves the start value up by amount.

§Panics

Panics if the size of the Span is less than amount, since a Span’s size can’t be negative.

Source

pub fn with_shrink_back(&self, amount: SpanValue) -> Self

Returns a span that is shrunk from the back. This moves the start value up by amount.

§Panics

Panics if the size of the Span is less than amount, since a Span’s size can’t be negative.

Source

pub fn shrink_front(&mut self, amount: SpanValue)

Shrinks the span from the front. This moves the end value back by amount.

§Panics

This method will panic if the size of the Span is less than amount, since a Span’s size can’t be negative.

Source

pub fn with_shrink_front(&self, amount: SpanValue) -> Self

Returns a span shrunk from the front. This moves the end value back by amount.

§Panics

This method will panic if the size of the Span is less than amount, since a Span’s size can’t be negative.

Source

pub fn is_empty(&self) -> bool

Checks if a Span’s size is 0. Returns true if 0, and false if anything else.

Source

pub fn len(&self) -> SpanValue

Gets the length of a Span.

Source

pub fn reset(&mut self) -> Self

Resets self by changing the start to be the end, plus 1, and changing the end to be the start. The function also returns the old span.

Source

pub fn apply<'a>(&self, string: &'a str) -> &'a str

Applies the span to string, with start and end corresponding to char indexes.

§Panics

Panics if string is shorter than the end of the span.

Source

pub fn apply_bytes<'a>(&self, string: &'a str) -> &'a str

Applies the span to string, with start and end corresponding to byte indexes.

§Panics

Panics if string is shorter than the end of the span.

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

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 Debug for Span

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Span

Source§

fn default() -> Span

Returns the “default value” for a type. Read more
Source§

impl From<Range<usize>> for Span

Source§

fn from(value: Range<SpanValue>) -> Self

Converts to this type from the input type.
Source§

impl From<Span> for Range<SpanValue>

Source§

fn from(val: Span) -> Self

Converts to this type from the input type.
Source§

impl Hash for Span

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Span

Source§

fn eq(&self, other: &Span) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Span

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Span

Source§

impl Eq for Span

Source§

impl StructuralPartialEq for Span

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnwindSafe for Span

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<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, 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.