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
String(String)
Python string (str
). When parsing, backslash escapes are interpreted.
When formatting, backslash escapes are used to ensure the result is
contains only ASCII chars.
Bytes(Vec<u8>)
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.
Integer(BigInt)
Python integer (int
). Python integers have unlimited precision, so we
use BigInt
.
Float(f64)
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.
Complex(Complex<f64>)
Python complex number (complex
). The Python complex
type contains
two float
values.
Tuple(Vec<Value>)
Python tuple (tuple
).
List(Vec<Value>)
Python list (list
).
Dict(Vec<(Value, Value)>)
Python dictionary (dict
).
Set(Vec<Value>)
Python set (set
).
Boolean(bool)
Python boolean (bool
).
None
Python None
.
Methods
impl Value
[src]
pub fn format_ascii(&self) -> Result<String, FormatError>
[src]
Formats the value as an ASCII string.
pub fn write_ascii<W: Write>(&self, w: &mut W) -> Result<(), FormatError>
[src]
Trait Implementations
impl FromStr for Value
[src]
type Err = ParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, ParseError>
[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
andu
/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]
fn clone(&self) -> Value
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Value
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl PartialEq for Value
[src]
fn eq(&self, __arg_0: &Value) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Value) -> bool
[src]
This method tests for !=
.