pub enum Shape {
Text(Text),
Template(Template),
Pattern(Regex),
}Expand description
A unit’s shape.
Variants§
Text(Text)
text: what the text must equal, or the frontmatter key whose value
it must equal.
Template(Template)
template: the text written with typed holes.
Pattern(Regex)
pattern: a regex the text must match somewhere.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn regex(&self) -> Option<&Regex>
pub fn regex(&self) -> Option<&Regex>
The shape’s regex, whose named groups are the keys it can capture;
none for text.
Sourcepub fn matches(
&self,
text: &str,
value: impl Fn(&str) -> Option<String>,
) -> bool
pub fn matches( &self, text: &str, value: impl Fn(&str) -> Option<String>, ) -> bool
Whether text, squashed, has this shape. value resolves a
{ from: <key> } text to the frontmatter value, squashed.
Sourcepub fn captures<'t>(&self, text: &'t str) -> Option<Captures<'t>>
pub fn captures<'t>(&self, text: &'t str) -> Option<Captures<'t>>
The groups the shape captures from text.
Sourcepub fn failure(&self, text: &str) -> String
pub fn failure(&self, text: &str) -> String
Why text does not have this shape, as a finding continues a
sentence that opens with the text: does not match … or fails at column …. text names the shape of a literal.
Sourcepub fn failure_quoting(&self, text: &str, quote: &Quote<'_>) -> String
pub fn failure_quoting(&self, text: &str, quote: &Quote<'_>) -> String
As failure, for a text that a format grammar read in another
spelling: the column and the text found of a template come from
quote, the text as written.
Sourcepub fn read_with(&self, read: &dyn Fn(&str) -> String) -> Shape
pub fn read_with(&self, read: &dyn Fn(&str) -> String) -> Shape
The shape as a format grammar reads it: each literal text read
through read, which reads a text in the grammar’s spelling, a
template read whole with each hole as a placeholder, and a pattern
and a frontmatter key as they are.