pub struct SyntaxReference {
pub value: String,
pub raw: Option<String>,
}Expand description
A reference read from a document, together with the text it was written as.
Equality, hashing, ordering and Display use the
value only, so 1 and '1' are equal references and a
LiNo<SyntaxReference> formats exactly like the LiNo<String> with the
same values. raw and quote say how the
reference was written.
§Examples
use links_notation::{LiNo, SyntaxReference, parse_lino_to_syntax_links};
let links = parse_lino_to_syntax_links("(t 1 '1')").unwrap();
let LiNo::Link { values, .. } = &links[0] else { unreachable!() };
let (LiNo::Ref(bare), LiNo::Ref(quoted)) = (&values[1], &values[2]) else {
unreachable!()
};
assert_eq!(bare, quoted);
assert_eq!(bare.raw.as_deref(), Some("1"));
assert_eq!(quoted.raw.as_deref(), Some("'1'"));
assert_eq!((bare.quote(), quoted.quote()), (None, Some('\'')));
assert_eq!(quoted.to_string(), "1");
assert_eq!(SyntaxReference::from("x").raw, None);Fields§
§value: StringWhat the reference means: its delimiters and escapes resolved and a
versioned literal decoded. This is the ID parse_lino_to_links reads.
raw: Option<String>The reference exactly as the document wrote it: quotes, doubled quote
runs and ~1{...} literal syntax included, and the line breaks of a
multi-line quoted reference. Taken from the document as the caller
passed it, comments included. None for a reference built in code.
Implementations§
Source§impl SyntaxReference
impl SyntaxReference
Sourcepub fn new(value: impl Into<String>) -> Self
pub fn new(value: impl Into<String>) -> Self
A reference that was not read from a document, so it has no raw text.
Sourcepub fn with_raw(value: impl Into<String>, raw: impl Into<String>) -> Self
pub fn with_raw(value: impl Into<String>, raw: impl Into<String>) -> Self
A reference with the text it was written as.
Sourcepub fn quote(&self) -> Option<char>
pub fn quote(&self) -> Option<char>
The delimiter the reference was written between: ', " or `
when it was quoted, and None when it was bare, a versioned literal, or
not read from a document. See reference_quote.
Trait Implementations§
Source§impl Clone for SyntaxReference
impl Clone for SyntaxReference
Source§impl Debug for SyntaxReference
impl Debug for SyntaxReference
Source§impl Default for SyntaxReference
impl Default for SyntaxReference
Source§impl Display for SyntaxReference
Writes the value, unescaped, the way a String
ID is written: a LiNo quotes it where the notation needs quotes, so a
LiNo<SyntaxReference> prints exactly what the LiNo<String> prints.
impl Display for SyntaxReference
Writes the value, unescaped, the way a String
ID is written: a LiNo quotes it where the notation needs quotes, so a
LiNo<SyntaxReference> prints exactly what the LiNo<String> prints.