#[repr(transparent)]pub struct Flonum(_);
Expand description
Implementations§
source§impl Flonum
impl Flonum
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(Flonum)
if val
is a Flonum
, None
otherwise.
Examples
use magnus::{eval, Flonum};
assert!(Flonum::from_value(eval("1.7272337110188893e-77").unwrap()).is_some());
// representable as a Float, but Flonum does not have enough precision
assert!(Flonum::from_value(eval("1.7272337110188890e-77").unwrap()).is_none());
sourcepub fn from_f64(n: f64) -> Result<Self, RFloat>
pub fn from_f64(n: f64) -> Result<Self, RFloat>
Create a new Flonum
from a f64.
Returns Ok(Flonum)
if n
can be represented as a Flonum
, otherwise
returns Err(RFloat)
.
Examples
use magnus::{eval, Flonum};
assert!(Flonum::from_f64(1.7272337110188893e-77).is_ok());
// representable as a Float, but Flonum does not have enough precision
assert!(Flonum::from_f64(1.7272337110188890e-77).is_err());
Methods from Deref<Target = Value>§
sourcepub unsafe fn to_s(&self) -> Result<Cow<'_, str>, Error>
pub unsafe fn to_s(&self) -> Result<Cow<'_, str>, Error>
Convert self
to a Rust string.
Safety
This may return a direct view of memory owned and managed by Ruby. Ruby may modify or free the memory backing the returned str, the caller must ensure this does not happen.
This can be used safely by immediately calling
into_owned
on the return value.
Examples
use magnus::{eval, QTRUE};
let value = QTRUE;
// safe as we neve give Ruby a chance to free the string.
let s = unsafe { value.to_s() }.unwrap().into_owned();
assert_eq!(s, "true");
sourcepub unsafe fn classname(&self) -> Cow<'_, str>
pub unsafe fn classname(&self) -> Cow<'_, str>
Return the name of self
’s class.
Safety
Ruby may modify or free the memory backing the returned str, the caller must ensure this does not happen.
This can be used safely by immediately calling
into_owned
on the return value.
Examples
use magnus::{eval, RHash};
let value = RHash::new();
// safe as we never give Ruby a chance to free the string.
let s = unsafe { value.classname() }.into_owned();
assert_eq!(s, "Hash");