Skip to main content

LineShape

Struct LineShape 

Source
pub struct LineShape {
    pub blank: bool,
    pub columns: u16,
    pub closer: bool,
    pub unindented: bool,
}
Expand description

The only three facts the indent-guide builder needs about a line, in a Copy struct so it can be produced without materialising the line’s text.

Replaces three separate whole-line predicates (IndentUnit::is_blank, IndentUnit::columns_of, is_closer_line) that each took &str — which forced the caller to allocate a String per line. On the keystroke path that was one allocation per covered line per keystroke, and coverage is the whole document below WINDOW_CAP_LINES.

Fields§

§blank: bool

Every character is ’ ’, ‘\t’ or ‘\r’ — IndentUnit::is_blank.

§columns: u16

Display columns of leading whitespace — IndentUnit::columns_of.

§closer: bool

Non-blank and every non-whitespace character closes something — is_closer_line.

§unindented: bool

Non-blank and starting hard against column 0. The scan_back_to_top_level test; equivalent to !blank && columns == 0, precomputed for clarity at the call site.

Implementations§

Source§

impl LineShape

Source

pub fn from_chars<I: Iterator<Item = char>>(chars: I, unit: &IndentUnit) -> Self

Stream chars (one line, trailing newline optional) into a shape. Allocation-free, and breaks early: once the line is known non-blank and known not-all-closers, no later character can change any field, which is the common case after one or two content characters.

Deliberately mirrors the three predicates byte-for-byte rather than approximating them:

  • indent scanning stops at the first char that is not ’ ’ or ‘\t’, matching columns_of’s break;
  • “blank” tests membership of {' ', '\t', '\r'} rather than Unicode whitespace, matching is_blank (so U+00A0 is content);
  • closer-ness ignores whitespace and tests the same six characters is_closer_line does.
Source

pub fn from_line(line: &str, unit: &IndentUnit) -> Self

Convenience for callers that already hold the text (tests, and any path where the line was materialised for another reason).

Trait Implementations§

Source§

impl Clone for LineShape

Source§

fn clone(&self) -> LineShape

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LineShape

Source§

impl Debug for LineShape

Source§

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

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

impl Eq for LineShape

Source§

impl PartialEq for LineShape

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LineShape

Auto Trait Implementations§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.