pub enum Operand {
String(String),
Float(String),
Number(i32),
}
Expand description
Represents an operand, which can be one of several types.
Variants§
String(String)
A string operand.
Float(String)
A floating-point operand (stored as a string).
Number(i32)
An integer operand.
Implementations§
Source§impl Operand
impl Operand
Sourcepub fn new_string(value: impl Into<String>) -> Self
pub fn new_string(value: impl Into<String>) -> Self
Sourcepub fn new_number(value: i32) -> Self
pub fn new_number(value: i32) -> Self
Sourcepub fn get_string_value(&self) -> Result<&str, OperandError>
pub fn get_string_value(&self) -> Result<&str, OperandError>
Retrieves the value of the operand as a string reference, if applicable.
§Returns
- The value of the operand as a string reference.
§Errors
OperandError::InvalidConversion
if the operand is a number.
§Examples
use gbf_core::operand::Operand;
let operand = Operand::new_string("Hello, world!");
let value = operand.get_string_value().unwrap();
assert_eq!(value, "Hello, world!");
Sourcepub fn get_number_value(&self) -> Result<i32, OperandError>
pub fn get_number_value(&self) -> Result<i32, OperandError>
Retrieves the value of the operand as a number, if applicable.
§Returns
- The value of the operand as a number.
§Errors
OperandError::InvalidConversion
if the operand is a string.
§Examples
use gbf_core::operand::Operand;
let operand = Operand::new_number(42);
let value = operand.get_number_value().unwrap();
assert_eq!(value, 42);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Operand
impl<'de> Deserialize<'de> for Operand
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Operand
impl StructuralPartialEq for Operand
Auto Trait Implementations§
impl Freeze for Operand
impl RefUnwindSafe for Operand
impl Send for Operand
impl Sync for Operand
impl Unpin for Operand
impl UnwindSafe for Operand
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.