Struct magnus::value::StaticSymbol
source · [−]#[repr(transparent)]pub struct StaticSymbol(_);
Expand description
Implementations
sourceimpl StaticSymbol
impl StaticSymbol
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(StaticSymbol)
if val
is a StaticSymbol
, None
otherwise.
Examples
use magnus::{eval, StaticSymbol};
assert!(StaticSymbol::from_value(eval(":foo").unwrap()).is_some());
assert!(StaticSymbol::from_value(eval(r#""bar""#).unwrap()).is_none());
assert!(StaticSymbol::from_value(eval(r#""baz".to_sym"#).unwrap()).is_none());
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 neve give Ruby a chance to free the string.
let s = unsafe { value.classname() }.into_owned();
assert_eq!(s, "Hash");
sourcepub fn try_convert<T>(&self) -> Result<T, Error> where
T: TryConvert,
pub fn try_convert<T>(&self) -> Result<T, Error> where
T: TryConvert,
Convert self
to the Rust type T
.
See the types that TryConvert
is implemented on for what this
method can convert to.
Examples
use magnus::{eval, Value};
assert_eq!(eval::<Value>("42").unwrap().try_convert::<i64>().unwrap(), 42);
assert_eq!(eval::<Value>("1.23").unwrap().try_convert::<i64>().unwrap(), 1);
assert_eq!(eval::<Value>("1").unwrap().try_convert::<f64>().unwrap(), 1.0);
assert_eq!(eval::<Value>("nil").unwrap().try_convert::<Option<i64>>().unwrap(), None);
assert_eq!(eval::<Value>("42").unwrap().try_convert::<Option<i64>>().unwrap(), Some(42));
Trait Implementations
sourceimpl Clone for StaticSymbol
impl Clone for StaticSymbol
sourcefn clone(&self) -> StaticSymbol
fn clone(&self) -> StaticSymbol
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for StaticSymbol
impl Debug for StaticSymbol
sourceimpl Deref for StaticSymbol
impl Deref for StaticSymbol
sourceimpl Display for StaticSymbol
impl Display for StaticSymbol
sourceimpl From<&'_ str> for StaticSymbol
impl From<&'_ str> for StaticSymbol
sourceimpl From<Id> for StaticSymbol
impl From<Id> for StaticSymbol
sourceimpl From<StaticSymbol> for Symbol
impl From<StaticSymbol> for Symbol
sourcefn from(s: StaticSymbol) -> Self
fn from(s: StaticSymbol) -> Self
Converts to this type from the input type.
sourceimpl From<StaticSymbol> for Value
impl From<StaticSymbol> for Value
sourcefn from(val: StaticSymbol) -> Self
fn from(val: StaticSymbol) -> Self
Converts to this type from the input type.
sourceimpl From<StaticSymbol> for Id
impl From<StaticSymbol> for Id
sourcefn from(sym: StaticSymbol) -> Self
fn from(sym: StaticSymbol) -> Self
Converts to this type from the input type.
sourceimpl From<String> for StaticSymbol
impl From<String> for StaticSymbol
sourceimpl TryConvert for StaticSymbol
impl TryConvert for StaticSymbol
sourcefn try_convert(val: &Value) -> Result<Self, Error>
fn try_convert(val: &Value) -> Result<Self, Error>
Convert val
into Self
.
impl Copy for StaticSymbol
Auto Trait Implementations
impl RefUnwindSafe for StaticSymbol
impl Send for StaticSymbol
impl Sync for StaticSymbol
impl Unpin for StaticSymbol
impl UnwindSafe for StaticSymbol
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more