Skip to main content

Arc

Struct Arc 

Source
pub struct Arc<T: Poolable> { /* private fields */ }
Expand description

A poolable drop-in replacement for std::sync::Arc.

This Arc pools its allocations, reducing overhead when frequently creating and destroying Arc instances. When the last strong reference is dropped, the allocation is returned to the pool instead of being freed.

§Example

use poolshark::global::arc::Arc;
use poolshark::global::RawPool;

let pool: RawPool<Arc<String>> = RawPool::new(1024, 1);
let arc1 = Arc::new(&pool, "hello".to_string());
let arc2 = arc1.clone();  // Reference counting works normally
drop(arc1);
drop(arc2);  // Returns to pool when last reference drops

§Differences from std::sync::Arc

  • Requires a pool to be created from
  • Returns to pool when dropped (if strong_count == 1)
  • Slightly larger memory footprint (stores pool pointer)

Implementations§

Source§

impl<T: Poolable> Arc<T>

Source

pub fn new(pool: &RawPool<Self>, v: T) -> Self

Allocate a new arc from the specified pool.

Returns an arc containing v.

Source

pub fn get_mut(&mut self) -> Option<&mut T>

Get a mutable reference to the inner value if the Arc is unique.

Returns None if the Arc is not unique (strong_count > 1).

Source

pub fn strong_count(&self) -> usize

Return the strong reference count of the arc.

Source

pub fn as_ptr(&self) -> *const (WeakPool<Self>, T)

Return the arc as a raw pointer.

Source§

impl<T: Poolable + Clone> Arc<T>

Source

pub fn make_mut<'a>(&'a mut self) -> &'a mut T

Get a mutable reference to the inner value, cloning if necessary.

If the Arc is not unique, this will clone the inner value.

Source§

impl<T: Poolable + Clone> Arc<T>

Source

pub fn downgrade(&self) -> Weak<T>

Downgrade the Arc to a weak pointer.

Source

pub fn weak_count(&self) -> usize

Return the weak reference count of the arc.

Trait Implementations§

Source§

impl<T: Clone + Poolable> Clone for Arc<T>

Source§

fn clone(&self) -> Arc<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Poolable + Debug> Debug for Arc<T>

Source§

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

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

impl<T: Poolable> Deref for Arc<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: Poolable> Drop for Arc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: Poolable + Eq> Eq for Arc<T>

Source§

impl<T: Poolable + Hash> Hash for Arc<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Poolable + Ord> Ord for Arc<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: Poolable + PartialEq> PartialEq for Arc<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: Poolable + PartialOrd> PartialOrd for Arc<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Poolable> RawPoolable for Arc<T>

Source§

fn empty(pool: WeakPool<Self>) -> Self

allocate a new empty object and set it’s pool pointer to pool
Source§

fn capacity(&self) -> usize

return the capacity of the collection
Source§

fn reset(&mut self)

empty the collection and reset it to its default state so it can be put back in the pool
Source§

fn really_drop(self)

Actually drop the inner object, don’t put it back in the pool, make sure you do not call both this method and the drop implementation that puts the object back in the pool!

Auto Trait Implementations§

§

impl<T> Freeze for Arc<T>

§

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

§

impl<T> Send for Arc<T>
where T: Sync + Send,

§

impl<T> Sync for Arc<T>
where T: Sync + Send,

§

impl<T> Unpin for Arc<T>

§

impl<T> UnsafeUnpin for Arc<T>

§

impl<T> UnwindSafe for Arc<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.