pub enum Constant {
None,
Bool(bool),
Str(String),
Bytes(Vec<u8>),
Int(BigInt),
Tuple(Vec<Constant>),
Float(f64),
Complex {
real: f64,
imag: f64,
},
Ellipsis,
}
Variants§
None
Bool(bool)
Str(String)
Bytes(Vec<u8>)
Int(BigInt)
Tuple(Vec<Constant>)
Float(f64)
Complex
Ellipsis
Implementations§
Source§impl Constant
impl Constant
Sourcepub fn as_bool(&self) -> Option<&bool>
pub fn as_bool(&self) -> Option<&bool>
Returns Some
if self
is a reference of variant Bool
, and None
otherwise.
Sourcepub fn as_mut_bool(&mut self) -> Option<&mut bool>
pub fn as_mut_bool(&mut self) -> Option<&mut bool>
Returns Some
if self
is a mutable reference of variant Bool
, and None
otherwise.
Sourcepub fn expect_bool(self) -> bool
pub fn expect_bool(self) -> bool
Sourcepub fn as_str(&self) -> Option<&String>
pub fn as_str(&self) -> Option<&String>
Returns Some
if self
is a reference of variant Str
, and None
otherwise.
Sourcepub fn as_mut_str(&mut self) -> Option<&mut String>
pub fn as_mut_str(&mut self) -> Option<&mut String>
Returns Some
if self
is a mutable reference of variant Str
, and None
otherwise.
Sourcepub fn expect_str(self) -> String
pub fn expect_str(self) -> String
Sourcepub fn as_bytes(&self) -> Option<&Vec<u8>>
pub fn as_bytes(&self) -> Option<&Vec<u8>>
Returns Some
if self
is a reference of variant Bytes
, and None
otherwise.
Sourcepub fn as_mut_bytes(&mut self) -> Option<&mut Vec<u8>>
pub fn as_mut_bytes(&mut self) -> Option<&mut Vec<u8>>
Returns Some
if self
is a mutable reference of variant Bytes
, and None
otherwise.
Sourcepub fn expect_bytes(self) -> Vec<u8> ⓘ
pub fn expect_bytes(self) -> Vec<u8> ⓘ
Sourcepub fn bytes(self) -> Option<Vec<u8>>
pub fn bytes(self) -> Option<Vec<u8>>
Returns Some
if self
is of variant Bytes
, and None
otherwise.
Sourcepub fn as_int(&self) -> Option<&BigInt>
pub fn as_int(&self) -> Option<&BigInt>
Returns Some
if self
is a reference of variant Int
, and None
otherwise.
Sourcepub fn as_mut_int(&mut self) -> Option<&mut BigInt>
pub fn as_mut_int(&mut self) -> Option<&mut BigInt>
Returns Some
if self
is a mutable reference of variant Int
, and None
otherwise.
Sourcepub fn expect_int(self) -> BigInt
pub fn expect_int(self) -> BigInt
Sourcepub fn as_tuple(&self) -> Option<&Vec<Constant>>
pub fn as_tuple(&self) -> Option<&Vec<Constant>>
Returns Some
if self
is a reference of variant Tuple
, and None
otherwise.
Sourcepub fn as_mut_tuple(&mut self) -> Option<&mut Vec<Constant>>
pub fn as_mut_tuple(&mut self) -> Option<&mut Vec<Constant>>
Returns Some
if self
is a mutable reference of variant Tuple
, and None
otherwise.
Sourcepub fn expect_tuple(self) -> Vec<Constant>
pub fn expect_tuple(self) -> Vec<Constant>
Sourcepub fn tuple(self) -> Option<Vec<Constant>>
pub fn tuple(self) -> Option<Vec<Constant>>
Returns Some
if self
is of variant Tuple
, and None
otherwise.
Sourcepub fn as_float(&self) -> Option<&f64>
pub fn as_float(&self) -> Option<&f64>
Returns Some
if self
is a reference of variant Float
, and None
otherwise.
Sourcepub fn as_mut_float(&mut self) -> Option<&mut f64>
pub fn as_mut_float(&mut self) -> Option<&mut f64>
Returns Some
if self
is a mutable reference of variant Float
, and None
otherwise.
Sourcepub fn expect_float(self) -> f64
pub fn expect_float(self) -> f64
Sourcepub fn float(self) -> Option<f64>
pub fn float(self) -> Option<f64>
Returns Some
if self
is of variant Float
, and None
otherwise.
Sourcepub const fn is_complex(&self) -> bool
pub const fn is_complex(&self) -> bool
Returns true
if self
is of variant Complex
.
Sourcepub const fn is_ellipsis(&self) -> bool
pub const fn is_ellipsis(&self) -> bool
Returns true
if self
is of variant Ellipsis
.
Trait Implementations§
Source§impl Parse for Constant
impl Parse for Constant
fn lex_starts_at( source: &str, offset: TextSize, ) -> SoftKeywordTransformer<Lexer<Chars<'_>>>
fn parse_tokens( lxr: impl IntoIterator<Item = Result<(Tok, TextRange), LexicalError>>, source_path: &str, ) -> Result<Constant, BaseError<ParseErrorType>>
fn parse( source: &str, source_path: &str, ) -> Result<Self, BaseError<ParseErrorType>>
fn parse_without_path(source: &str) -> Result<Self, BaseError<ParseErrorType>>
fn parse_starts_at( source: &str, source_path: &str, offset: TextSize, ) -> Result<Self, BaseError<ParseErrorType>>
impl StructuralPartialEq for Constant
Auto Trait Implementations§
impl Freeze for Constant
impl RefUnwindSafe for Constant
impl Send for Constant
impl Sync for Constant
impl Unpin for Constant
impl UnwindSafe for Constant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more