Enum py_literal::Value [−][src]
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
contains only ASCII chars.
Python byte sequence (bytes
). When parsing, backslash escapes are
interpreted. When formatting, backslash escapes are used to ensure the
result 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.
Python complex number (complex
). The Python complex
type contains
two float
values.
Python tuple (tuple
).
Python list (list
).
Python dictionary (dict
).
Python set (set
).
Boolean(bool)
Python boolean (bool
).
Python None
.
Implementations
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]
impl Value
[src]
pub fn is_string(&self) -> bool
[src]
Returns true
if self
is Value::String
. Returns false
otherwise.
pub fn as_string(&self) -> Option<&String>
[src]
If self
is Value::String
, returns the associated string. Returns None
otherwise.
pub fn is_bytes(&self) -> bool
[src]
Returns true
if self
is Value::Bytes
. Returns false
otherwise.
pub fn as_bytes(&self) -> Option<&Vec<u8>>
[src]
If self
is Value::Bytes
, returns the associated bytes. Returns None
otherwise.
pub fn is_integer(&self) -> bool
[src]
Returns true
if self
is Value::Integer
. Returns false
otherwise.
pub fn as_integer(&self) -> Option<&BigInt>
[src]
If self
is Value::Integer
, returns the associated integer. Returns None
otherwise.
pub fn is_float(&self) -> bool
[src]
Returns true
if self
is Value::Float
. Returns false
otherwise.
pub fn as_float(&self) -> Option<f64>
[src]
If self
is Value::Float
, returns the associated float. Returns None
otherwise.
pub fn is_complex(&self) -> bool
[src]
Returns true
if self
is Value::Complex
. Returns false
otherwise.
pub fn as_complex(&self) -> Option<Complex<f64>>
[src]
If self
is Value::Complex
, returns the associated complex number. Returns None
otherwise.
pub fn is_tuple(&self) -> bool
[src]
Returns true
if self
is Value::Tuple
. Returns false
otherwise.
pub fn as_tuple(&self) -> Option<&Vec<Value>>
[src]
If self
is Value::Tuple
, returns the associated data. Returns None
otherwise.
pub fn is_list(&self) -> bool
[src]
Returns true
if self
is Value::List
. Returns false
otherwise.
pub fn as_list(&self) -> Option<&Vec<Value>>
[src]
If self
is Value::List
, returns the associated data. Returns None
otherwise.
pub fn is_dict(&self) -> bool
[src]
Returns true
if self
is Value::Dict
. Returns false
otherwise.
pub fn as_dict(&self) -> Option<&Vec<(Value, Value)>>
[src]
If self
is Value::Dict
, returns the associated data. Returns None
otherwise.
pub fn is_set(&self) -> bool
[src]
Returns true
if self
is Value::Set
. Returns false
otherwise.
pub fn as_set(&self) -> Option<&Vec<Value>>
[src]
If self
is Value::Set
, returns the associated data. Returns None
otherwise.
pub fn is_boolean(&self) -> bool
[src]
Returns true
if self
is Value::Boolean
. Returns false
otherwise.
pub fn as_boolean(&self) -> Option<bool>
[src]
If self
is Value::Boolean
, returns the associated data. Returns None
otherwise.
pub fn is_none(&self) -> bool
[src]
Returns true
if self
is Value::None
. Returns false
otherwise.
Trait Implementations
impl Clone for Value
[src]
impl Debug for Value
[src]
impl Display for Value
[src]
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
[src]
Formats the value as a Python literal.
Currently, this just calls self.format_ascii()
, but that may change
in the future.
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 PartialEq<Value> for Value
[src]
impl StructuralPartialEq for Value
[src]
Auto Trait Implementations
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,