Struct magnus::value::StaticSymbol
source · #[repr(transparent)]pub struct StaticSymbol(_);
Expand description
Implementations§
source§impl 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());
sourcepub fn new<T: Into<Id>>(name: T) -> Self
pub fn new<T: Into<Id>>(name: T) -> Self
Create a new StaticSymbol.
Examples
use magnus::{eval, StaticSymbol};
let sym = StaticSymbol::new("example");
let result: bool = eval!(":example == sym", sym).unwrap();
assert!(result);
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");
Trait Implementations§
source§impl Clone for StaticSymbol
impl Clone for StaticSymbol
source§fn clone(&self) -> StaticSymbol
fn clone(&self) -> StaticSymbol
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for StaticSymbol
impl Debug for StaticSymbol
source§impl Deref for StaticSymbol
impl Deref for StaticSymbol
source§impl Display for StaticSymbol
impl Display for StaticSymbol
source§impl EncodingCapable for StaticSymbol
impl EncodingCapable for StaticSymbol
source§impl From<&str> for StaticSymbol
impl From<&str> for StaticSymbol
source§impl From<Id> for StaticSymbol
impl From<Id> for StaticSymbol
source§impl From<StaticSymbol> for Id
impl From<StaticSymbol> for Id
source§fn from(sym: StaticSymbol) -> Self
fn from(sym: StaticSymbol) -> Self
Converts to this type from the input type.
source§impl From<StaticSymbol> for Symbol
impl From<StaticSymbol> for Symbol
source§fn from(s: StaticSymbol) -> Self
fn from(s: StaticSymbol) -> Self
Converts to this type from the input type.
source§impl From<StaticSymbol> for Value
impl From<StaticSymbol> for Value
source§fn from(val: StaticSymbol) -> Self
fn from(val: StaticSymbol) -> Self
Converts to this type from the input type.