pub struct ExLine { /* private fields */ }Expand description
The : line — its text and the caret editing it, as ONE value.
They are one value because they have an invariant between them —
caret <= text.chars().count() — and a struct with private fields is the
only place an invariant like that can be maintained once rather than at
every mutation site.
That is not a hypothetical. The first version of the ex-line caret kept
the two as sibling fields of the enum variant, and clear_minibuffer
emptied the text while leaving the caret where it was. No test could see
it, because a caret past the end is silently clamped by Ruler instead of
panicking — the only report was warning: unused variable: caret, which
is the compiler saying “you destructured the invariant’s other half and
did nothing with it”.
§Wire shape
#[serde(flatten)]ed into ModalState::Command, and text is renamed to
minibuffer, so the published schema is unchanged by this refactor:
{"mode": "Command", "minibuffer": "wq", "caret": 2}. escriba-api
publishes it, so the encapsulation is internal only.
Implementations§
Source§impl ExLine
impl ExLine
Sourcepub fn push_str(&mut self, s: &str)
pub fn push_str(&mut self, s: &str)
Append a raw fragment and park the caret at the end.
Appends rather than inserting on purpose: its caller is the command
registry’s __quit__ sentinel handshake, which is writing a fragment
the user did not type.
Sourcepub fn move_caret(&mut self, to: CaretMove)
pub fn move_caret(&mut self, to: CaretMove)
Move the caret.
Sourcepub fn backspace(&mut self) -> Option<char>
pub fn backspace(&mut self) -> Option<char>
Delete the char BEFORE the caret (<BS>), returning it.
Deleting before the caret and deleting the tail are the same operation only while the caret sits at the end — exactly the assumption that made the search prompt’s shadow diverge from the typed prompt.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ExLine
impl<'de> Deserialize<'de> for ExLine
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ExLine
Source§impl JsonSchema for ExLine
impl JsonSchema for ExLine
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read more