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: boolEvery character is ’ ’, ‘\t’ or ‘\r’ — IndentUnit::is_blank.
columns: u16Display columns of leading whitespace — IndentUnit::columns_of.
closer: boolNon-blank and every non-whitespace character closes something —
is_closer_line.
unindented: boolNon-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
impl LineShape
Sourcepub fn from_chars<I: Iterator<Item = char>>(chars: I, unit: &IndentUnit) -> Self
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’sbreak; - “blank” tests membership of
{' ', '\t', '\r'}rather than Unicode whitespace, matchingis_blank(so U+00A0 is content); - closer-ness ignores whitespace and tests the same six
characters
is_closer_linedoes.
Sourcepub fn from_line(line: &str, unit: &IndentUnit) -> Self
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§
impl Copy for LineShape
impl Eq for LineShape
impl StructuralPartialEq for LineShape
Auto Trait Implementations§
impl Freeze for LineShape
impl RefUnwindSafe for LineShape
impl Send for LineShape
impl Sync for LineShape
impl Unpin for LineShape
impl UnsafeUnpin for LineShape
impl UnwindSafe for LineShape
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.