Struct source_span::Layout[][src]

pub struct Layout<M: Metrics> { /* fields omitted */ }

Text layout.

Keep track of the byte index of each line in a UTF8-encoded so it can be indexed by cursor position.

Implementations

impl<M: Metrics> Layout<M>[src]

pub fn new(metrics: M) -> Layout<M>[src]

Create a new empty layout from a given metrics.

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

Get the layout’s span.

pub fn from<Chars: Iterator<Item = char>>(chars: Chars, metrics: M) -> Layout<M>[src]

Create a new layout from a char iterator.

pub fn try_from<E, Chars: Iterator<Item = Result<char, E>>>(
    chars: Chars,
    metrics: M
) -> Result<Layout<M>, E>
[src]

Try to create a new layout from an unreliable char iterator.

pub fn push(&mut self, c: char)[src]

Extend the layout with a new character.

pub fn byte_index(&self, str: &str, position: Position) -> Option<usize>[src]

Get the byte index mapping to the given position in the input string slice.

It is assumed that the input string slice matches the layout. Otherwise, the returned index may not point to an UTF8 character boundary nor even be in the slice bounds.

pub fn span_slice<'a>(&self, str: &'a str, span: Span) -> &'a str[src]

Get the sub slice of the input string matching the given span.

Trait Implementations

impl<M: Metrics> Extend<char> for Layout<M>[src]

Auto Trait Implementations

impl<M> RefUnwindSafe for Layout<M> where
    M: RefUnwindSafe

impl<M> Send for Layout<M> where
    M: Send

impl<M> Sync for Layout<M> where
    M: Sync

impl<M> Unpin for Layout<M> where
    M: Unpin

impl<M> UnwindSafe for Layout<M> where
    M: UnwindSafe

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