[][src]Struct rebound::value::Value

pub struct Value<'a> { /* fields omitted */ }

A Value represents a value with an erased type. It may be owned or borrowed. The Value will have at most the lifetime of the value it was created from.

An owned Value will safely drop the contained object when it dies, while a borrowed Value will not.

A Value may be borrowed out as a concrete type, though an attempt to do so as a type not the same as the input type will result in a failure at runtime.

Implementations

impl<'a> Value<'a>[src]

pub unsafe fn from_ptr_owned<T: ?Sized + Reflected + 'a>(
    val: *mut T
) -> Value<'a>
[src]

Create a new owned Value from a pointer, with a lifetime no greater than that of the provided type.

Safety

Similar to Box::from_raw, this function may result in a double-free if called more than once with the same pointer.

pub fn from_ref<T: ?Sized + Reflected>(val: &T) -> Value<'_>[src]

Create a new borrowed Value from a reference, with a lifetime no greater than that of the provided reference.

pub unsafe fn raw_meta(&self) -> *mut ()[src]

Get a pointer to the raw backing metadata of this Value

Safety

Similar to pointer::as_ref, the pointer returned by this function may outlive the borrowed Value, it is the user's responsibility to not use it past the lifetime of this Value.

pub unsafe fn raw_ptr(&self) -> *mut ()[src]

Get the raw backing pointer of this Value

Safety

Similar to pointer::as_ref, the pointer returned by this function may outlive the borrowed Value, it is the user's responsibility to not use it past the lifetime of this Value.

pub fn ty(&self) -> Type[src]

Get the Type of this Value

pub unsafe fn try_cast<T: Reflected>(self) -> Result<T, (Self, Error)>[src]

Attempt to move the contained T out of this Value in a fallible manner.

Errors

Safety

If this Value contains data which may not live forever, there is no way to ensure that the provided T does not outlive 'a. As such, it is the user's responsibility to not move data out of this value in a way which gives it a lifetime longer than its original.

pub unsafe fn cast<T: Reflected>(self) -> T[src]

Attempt to move the contained T out of this Value, panicking on failure. This will panic in all the cases that Value::try_cast would return an Err value.

Safety

See Value::try_cast

pub fn try_borrow<T: ?Sized + Reflected>(&self) -> Result<&T, Error>[src]

Attempt to immutably borrow the T contained by this Value in a fallible manner.

This will fail if the T isn't the same as the type of this value with Error::WrongType

Example

let int = Value::from(1);

// Succeeds
let i = int.try_borrow::<i32>();
// Fails
let i = int.try_borrow::<&str>();

pub fn borrow<T: ?Sized + Reflected>(&self) -> &T[src]

Attempt to immutably borrow the T contained in this value, panicking on failure. This will panic in all the cases that Value::try_borrow would return an Err value.

Example

let bool = Value::from(true);

// Succeeds
let b = bool.borrow::<bool>();
// Panics
let b = bool.borrow::<char>();

pub fn try_borrow_mut<T: ?Sized + Reflected>(&mut self) -> Result<&mut T, Error>[src]

Attempt to mutably borrow the T contained by this Value in a fallible manner.

This will fail if the T isn't the same as the type of this Value with Error::WrongType

Example

let mut char = Value::from('a');

// Succeeds
let c = char.try_borrow_mut::<char>()
    .unwrap();
*c = 'b';
// Fails
let c = char.try_borrow_mut::<i32>()
    .unwrap();
*c = 2;

pub fn borrow_mut<T: ?Sized + Reflected>(&mut self) -> &mut T[src]

Attempt to mutably borrow the T contained in this value, panicking on failure. This will panic in all the cases that Value::try_borrow_mut would return an Err value.

let mut str = Value::from("a string");

// Succeeds
let s = str.borrow_mut::<&str>();
// Fails
let s = str.borrow_mut::<&i32>();

pub fn as_ref(&self) -> Result<Value<'_>, Error>[src]

If this Value is not a reference Type, get a Value containing an immutable reference to the data contained within this Value. A convenience function for operations that expect a reference to data you own.

pub fn as_mut(&mut self) -> Result<Value<'_>, Error>[src]

If this Value is not a reference Type, get a Value containing a mutable reference to the data contained within this Value. A convenience function for operations that expect a mutable reference to data you own.

Trait Implementations

impl<'a> Debug for Value<'a>[src]

impl<'a> Drop for Value<'a>[src]

impl<'a, T: Reflected + 'a> From<T> for Value<'a>[src]

impl<'a> Pointer for Value<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Value<'a>[src]

impl<'a> !Send for Value<'a>[src]

impl<'a> !Sync for Value<'a>[src]

impl<'a> Unpin for Value<'a>[src]

impl<'a> UnwindSafe for Value<'a>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.