Skip to main content

SharedVecRef

Struct SharedVecRef 

Source
pub struct SharedVecRef<T> { /* private fields */ }
Expand description

A reference to SharedVec that can be sent to other threads.

Dropping a SharedVecRef leaks the heap allocation it points to. When the panic-on-drop feature is enabled, dropping it will panic:

let mut values = manual_share::SharedVec::from_vec(vec![1]);
values.borrow();

// forget SharedVecMut to make sure the panic is not caused by dropping it first.
std::mem::forget(values);

// panic here due to dropping ShareVecRef

Use SharedVec::try_return to consume it without causing panic.

let mut values = manual_share::SharedVec::from_vec(vec![1]);
let reference = values.borrow();
values.try_return(reference).unwrap();

Implementations§

Source§

impl<T> SharedVecRef<T>

Source

pub fn as_slice(&self) -> &[T]

View the referenced data as a slice.

let mut values = manual_share::SharedVec::from_vec(vec![1, 2, 3]);
let reference = values.borrow();
assert_eq!(reference.as_slice(), &[1, 2, 3]);
values.try_return(reference).unwrap();

Trait Implementations§

Source§

impl<T: Debug> Debug for SharedVecRef<T>

Source§

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

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

impl<T> Drop for SharedVecRef<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Sync + Send> Send for SharedVecRef<T>

Source§

impl<T: Sync> Sync for SharedVecRef<T>

Auto Trait Implementations§

§

impl<T> Freeze for SharedVecRef<T>

§

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

§

impl<T> Unpin for SharedVecRef<T>

§

impl<T> UnsafeUnpin for SharedVecRef<T>

§

impl<T> UnwindSafe for SharedVecRef<T>
where T: RefUnwindSafe,

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.