#[repr(transparent)]pub struct Encoding(_);
Expand description
Implementations
sourceimpl Encoding
impl Encoding
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(Encoding)
if val
is an Encoding
, None
otherwise.
Examples
use magnus::{eval, encoding::Encoding};
assert!(Encoding::from_value(eval("Encoding::US_ASCII").unwrap()).is_some());
assert!(Encoding::from_value(eval("nil").unwrap()).is_none());
sourcepub fn default_external() -> Self
pub fn default_external() -> Self
Returns the default internal encoding as a Ruby object.
This is the encoding used for anything out-of-process, such as reading from files or sockets.
sourcepub fn default_internal() -> Option<Self>
pub fn default_internal() -> Option<Self>
Returns the default external encoding as a Ruby object.
If set, any out-of-process data is transcoded from the default external encoding to the default internal encoding.
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");
Trait Implementations
sourceimpl From<Encoding> for RbEncoding
impl From<Encoding> for RbEncoding
sourceimpl From<RbEncoding> for Encoding
impl From<RbEncoding> for Encoding
sourcefn from(val: RbEncoding) -> Self
fn from(val: RbEncoding) -> Self
sourceimpl Object for Encoding
impl Object for Encoding
sourcefn define_singleton_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
fn define_singleton_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
self
’s scope. Read moresourcefn ivar_set<T, U>(self, name: T, value: U) -> Result<(), Error>where
T: Into<Id>,
U: Into<Value>,
fn ivar_set<T, U>(self, name: T, value: U) -> Result<(), Error>where
T: Into<Id>,
U: Into<Value>,
sourceimpl TryConvert for Encoding
impl TryConvert for Encoding
sourcefn try_convert(val: Value) -> Result<Self, Error>
fn try_convert(val: Value) -> Result<Self, Error>
val
into Self
.