Struct magnus::value::BoxValue

source ·
pub struct BoxValue<T>(/* private fields */);
Expand description

Protects a Ruby Value from the garbage collector.

See also gc::register_mark_object for a value that should be permanently excluded from garbage collection.

Implementations§

source§

impl<T> BoxValue<T>
where T: ReprValue,

source

pub fn new(val: T) -> Self

Create a new BoxValue.

§Examples
use magnus::{eval, gc, value::BoxValue, RString, Value};

fn box_value() -> BoxValue<RString> {
    BoxValue::new(RString::new("foo"))
}

let boxed = box_value();

// run garbage collector
gc::start();

// boxed is still useable
let result: String = eval!(r#"foo + "bar""#, foo = boxed).unwrap();

assert_eq!(result, "foobar");

Trait Implementations§

source§

impl<T> AsMut<T> for BoxValue<T>

source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T> AsRef<T> for BoxValue<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Debug for BoxValue<T>
where T: ReprValue,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Deref for BoxValue<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for BoxValue<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T> Display for BoxValue<T>
where T: ReprValue,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Drop for BoxValue<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> IntoValue for BoxValue<T>
where T: ReprValue,

source§

fn into_value_with(self, _: &Ruby) -> Value

Convert self into Value.
source§

fn into_value(self) -> Value

Convert self into Value. Read more
source§

unsafe fn into_value_unchecked(self) -> Value

Convert self into Value. Read more
source§

impl<T> IntoValueFromNative for BoxValue<T>
where T: ReprValue,

Auto Trait Implementations§

§

impl<T> Freeze for BoxValue<T>

§

impl<T> RefUnwindSafe for BoxValue<T>
where T: RefUnwindSafe,

§

impl<T> Send for BoxValue<T>
where T: Send,

§

impl<T> Sync for BoxValue<T>
where T: Sync,

§

impl<T> Unpin for BoxValue<T>

§

impl<T> UnwindSafe for BoxValue<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Inspect for T
where T: Debug,

source§

fn inspect(&self) -> String

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> BlockReturn for T
where T: BlockReturn,

source§

impl<T> ReturnValue for T
where T: ReturnValue,