Enum py_literal::Value [] [src]

pub enum Value {
    String(String),
    Bytes(Vec<u8>),
    Integer(BigInt),
    Float(f64),
    Complex(Complex<f64>),
    Tuple(Vec<Value>),
    List(Vec<Value>),
    Dict(Vec<(Value, Value)>),
    Set(Vec<Value>),
    Boolean(bool),
    None,
}

Python literal.

This type should be able to express everything that Python's ast.literal_eval() can evaluate, except for operators. Similar to literal_eval(), addition and subtraction of numbers is supported in the parser. However, binary addition and subtraction operators cannot be formatted using Value.

Variants

Python string (str). When parsing, backslash escapes are interpreted. When formatting, backslash escapes are used to ensure the result is contains only ASCII chars.

Python byte sequence (bytes). When parsing, backslash escapes are interpreted. When formatting, backslash escapes are used to ensure the result is contains only ASCII chars.

Python integer (int). Python integers have unlimited precision, so we use BigInt.

Python floating-point number (float). The representation and precision of the Python float type varies by the machine where the program is executing, but f64 should be good enough.

Python complex number (complex). The Python complex type contains two float values.

Python tuple (tuple).

Python list (list).

Python dictionary (dict).

Python set (set).

Python boolean (bool).

Python None.

Methods

impl Value
[src]

[src]

Formats the value as an ASCII string.

[src]

Writes the value as ASCII.

This implementation performs a lot of small writes. If individual writes are expensive (e.g. if the writer is a TcpStream), it would be a good idea to wrap the writer in a BufWriter before passing it to .write_ascii().

Trait Implementations

impl FromStr for Value
[src]

The associated error which can be returned from parsing.

[src]

Parses a Value from a Python literal. The goal is for the parser to support everything ast.literal_eval() does. A few things haven't been implemented yet:

  • r/R and u/U prefixes for string and bytes literals.
  • string literal concatenation
  • newlines (except in string literals)
  • parentheses (except as tuple delimiters)
  • Unicode name escapes in strings (\N{name})

Note that the parser is limited to Python literals, not the full Python AST, so many things are not supported, such as:

  • identifiers
  • formatted string literals (f/F prefix)
  • binary operators (except for + and - on numeric literals)
  • function calls

impl Clone for Value
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Value
[src]

[src]

Formats the value using the given formatter. Read more

impl PartialEq for Value
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Display for Value
[src]

[src]

Formats the value as a Python literal.

Currently, this just calls self.format_ascii(), but that may change in the future.

Auto Trait Implementations

impl Send for Value

impl Sync for Value