pub enum Type {
Int(i32),
Float(f64),
String(String),
}
Expand description
Represents different types that can be used in mathematical operations.
Variants§
Int(i32)
Represents a 32-bit signed integer.
Float(f64)
Represents a 64-bit floating-point number.
String(String)
Represents a String.
Implementations§
Source§impl Type
impl Type
Sourcepub fn get_type(&self) -> &str
pub fn get_type(&self) -> &str
Returns the type information associated with the variant of the Type
enum.
§Arguments
self
- A reference to theType
enum instance.
§Returns
A string slice representing the type of the enum variant:
- If the variant is
Type::Int
, the return value is “i32” representing a 32-bit signed integer type. - If the variant is
Type::Float
, the return value is “f64” representing a 64-bit floating-point type. - If the variant is
Type::String
, the return value is “String” indicating a string type.
§Example
use my_little_eval::type_enum::Type;
let int_type = Type::Int(42);
let float_type = Type::Float(3.14);
let string_type = Type::String("Hello, World!".to_string());
assert_eq!(int_type.get_type(), "i32");
assert_eq!(float_type.get_type(), "f64");
assert_eq!(string_type.get_type(), "String");
Trait Implementations§
Source§impl PartialOrd for Type
impl PartialOrd for Type
impl StructuralPartialEq for Type
Auto Trait Implementations§
impl Freeze for Type
impl RefUnwindSafe for Type
impl Send for Type
impl Sync for Type
impl Unpin for Type
impl UnwindSafe for Type
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