Skip to main content

Literal

Enum Literal 

Source
pub enum Literal {
    Text(String),
    Name(String),
    Flag(bool),
    Int(i64),
    Float(f64),
    Verbatim(String),
}
Expand description

A property’s value, as a form file writes it.

Smaller than KDL’s own set, because a .dform property is one of these and nothing else. The spelling is part of it: role=primary and text="primary" hold the same string and are not the same line, so Name and Text are separate.

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

Source

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.

Source

pub fn name(name: impl Into<String>) -> Self

See Literal::text. A bare name.

Trait Implementations§

Source§

impl Clone for Literal

Source§

fn clone(&self) -> Literal

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Literal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Literal

Source§

fn eq(&self, other: &Literal) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Literal

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrows as dyn Any.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Mutably borrows as dyn Any.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.