pub struct Value { /* private fields */ }
Expand description
A NaN-tagged value supporting f64, i32, u32, booleans, null and arbitrary pointers.
§Usage
The Value
type can be constructed from f64
, bool
, i32
, u32
, i64
, ()
and pointers to arbitrary T
:
use nanoval::Value;
let double = Value::from(3.14);
let integer = Value::from(42);
let boolean = Value::from(true);
let null = Value::from(());
let pointee = 42;
let pointer = Value::try_from(&pointee as *const i32).unwrap();
The constructed value can be converted back to the original type:
assert_eq!(double.as_f64(), Some(3.14));
assert_eq!(integer.as_int(), Some(42));
assert_eq!(boolean.as_bool(), Some(true));
assert!(null.is_null());
assert_eq!(pointer.as_pointer::<i32>(), Some(&pointee as *const i32));
Implementations§
Source§impl Value
impl Value
Sourcepub const fn is_f64(self) -> bool
pub const fn is_f64(self) -> bool
Is this value a f64? Valid f64 are not NaN, or if they are, they have a specific bit pattern.
Sourcepub const fn is_pointer(self) -> bool
pub const fn is_pointer(self) -> bool
Is this value a pointer?
Sourcepub const fn as_pointer<T>(self) -> Option<*const T>
pub const fn as_pointer<T>(self) -> Option<*const T>
Get the value as a pointer.
Sourcepub fn as_f64_unchecked(self) -> f64
pub fn as_f64_unchecked(self) -> f64
Sourcepub const unsafe fn as_int_unchecked(self) -> i64
pub const unsafe fn as_int_unchecked(self) -> i64
Sourcepub const unsafe fn as_bool_unchecked(self) -> bool
pub const unsafe fn as_bool_unchecked(self) -> bool
Sourcepub const unsafe fn as_pointer_unchecked<T>(self) -> *const T
pub const unsafe fn as_pointer_unchecked<T>(self) -> *const T
Trait Implementations§
impl Copy for Value
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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