pub enum Literal {
Text(String),
Name(String),
Flag(bool),
Int(i64),
Float(f64),
Verbatim(String),
}Expand description
Variants§
Text(String)
A quoted string: text="Save".
Name(String)
A bare name, which is how an enum is written: role=primary.
Quoted anyway if the name is not something KDL would read back bare, so this can never produce a file that stops parsing.
Flag(bool)
#true or #false.
Int(i64)
A whole number.
Float(f64)
A real number.
Verbatim(String)
Exactly this text, character for character, as it stood in the file.
What Form::apply hands back for a value it replaced, and the reason
undo is byte-exact rather than merely correct: 1_000, 0x10, 70.0
and #"a raw string"# are all values a typed variant could carry, and
none of them would be written the same way twice.
One built by hand is checked: it has to be the text of a single value.
Implementations§
Source§impl Literal
impl Literal
Sourcepub fn text(text: impl Into<String>) -> Self
pub fn text(text: impl Into<String>) -> Self
The spelling is the difference, and the file keeps it: role=primary
and text="primary" hold the same string and are not the same line.
let mut form = Form::parse(r#"form "F" version=1 width=99 height=99 { label "Hi" x=0 y=0 w=9 h=9 }"#)?;
form.apply(Edit::property(&[0], "text", Some(Literal::text("Hello"))))?;
form.apply(Edit::property(&[0], "role", Some(Literal::name("primary"))))?;
assert!(form.text().contains(r#"text="Hello""#), "{}", form.text());
assert!(form.text().contains("role=primary"), "{}", form.text());A quoted string.
Sourcepub fn name(name: impl Into<String>) -> Self
pub fn name(name: impl Into<String>) -> Self
See Literal::text.
A bare name.