pub struct Layout<M: Metrics> { /* private fields */ }
Expand description
Text layout.
Keep track of the byte index of each line in a UTF8-encoded so it can be indexed by cursor position.
Implementations§
Source§impl<M: Metrics> Layout<M>
impl<M: Metrics> Layout<M>
Sourcepub fn from<Chars: Iterator<Item = char>>(chars: Chars, metrics: M) -> Layout<M>
pub fn from<Chars: Iterator<Item = char>>(chars: Chars, metrics: M) -> Layout<M>
Create a new layout from a char
iterator.
Sourcepub fn try_from<E, Chars: Iterator<Item = Result<char, E>>>(
chars: Chars,
metrics: M,
) -> Result<Layout<M>, E>
pub fn try_from<E, Chars: Iterator<Item = Result<char, E>>>( chars: Chars, metrics: M, ) -> Result<Layout<M>, E>
Try to create a new layout from an unreliable char
iterator.
Sourcepub fn byte_index(&self, str: &str, position: Position) -> Option<usize>
pub fn byte_index(&self, str: &str, position: Position) -> Option<usize>
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.
Sourcepub fn span_slice<'a>(&self, str: &'a str, span: Span) -> &'a str
pub fn span_slice<'a>(&self, str: &'a str, span: Span) -> &'a str
Get the sub slice of the input string matching the given span.
Trait Implementations§
Source§impl<M: Metrics> Extend<char> for Layout<M>
impl<M: Metrics> Extend<char> for Layout<M>
Source§fn extend<Chars: IntoIterator<Item = char>>(&mut self, chars: Chars)
fn extend<Chars: IntoIterator<Item = char>>(&mut self, chars: Chars)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Auto Trait Implementations§
impl<M> Freeze for Layout<M>where
M: Freeze,
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more