pub struct StaticRcRef<'a, T: ?Sized, const NUM: usize, const DEN: usize> { /* private fields */ }
Expand description

A compile-time reference-counted pointer.

The inherent methods of StaticRc are all associated functions to avoid conflicts with the the methods of the inner type T which are brought into scope by the Deref implementation.

The parameters NUM and DEN DENote the ratio (NUM / DEN) of ownership of the pointer:

  • The ratio is always in the (0, 1] interval, that is: NUM > 0 and NUM <= DEN.
  • When the ratio is equal to 1, that is when NUM == DEN, then the instance has full ownership of the pointee and extra capabilities are unlocked.

Implementations

Constructs a new StaticRcRef<'a, T, N, N>.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 1, 1>;

let mut value = 42;
let rc = Full::new(&mut value);
assert_eq!(42, *rc);

Returns the inner value.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 1, 1>;

let mut value = 42;
let rc = Full::new(&mut value);
let inner: &mut i32 = Full::into_inner(rc);
assert_eq!(42, *inner);

Returns a mutable reference into the given StaticRcRef.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 1, 1>;

let mut value = 42;
let mut rc = Full::new(&mut value);
assert_eq!(42, *Full::get_mut(&mut rc));

Consumes the StaticRcRef, returning the wrapped pointer.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 1, 1>;

let mut value = 42;
let rc = Full::new(&mut value);
let pointer = Full::into_raw(rc);
assert_eq!(&mut value as *mut _, pointer.as_ptr());

Provides a raw pointer to the data.

StaticRcRef is not consumed or affected in any way, the pointer is valid as long as the original value is.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 1, 1>;

let mut value = 42;
let pointer = &mut value as *mut _;

let rc = Full::new(&mut value);
let other_pointer = Full::as_ptr(&rc);

assert_eq!(pointer, other_pointer.as_ptr());

Provides a reference to the data.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 1, 1>;

let mut value = 42;
let rc = Full::new(&mut value);

let r = Full::get_ref(&rc);

assert_eq!(42, *r);

Constructs a StaticRcRef<'a, T, NUM, DEN> from a raw pointer.

The raw pointer must have been previously returned by a call to StaticRcRef<'a, U, N, D>::into_raw:

  • If U is different from T, then specific restrictions on size and alignment apply. See mem::transmute for the restrictions applying to transmuting references.
  • If N / D is different from NUM / DEN, then specific restrictions apply. The user is responsible for ensuring proper management of the ratio of shares, and ultimately that the value is not dropped twice.

Returns true if the two StaticRcRef point to the same allocation.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let (one, two) = Full::split::<1, 1>(rc);

assert!(StaticRcRef::ptr_eq(&one, &two));

Adjusts the NUMerator and DENumerator of the ratio of the instance, preserving the ratio.

Panics

If the compile-time-ratio feature is not used, and the ratio is not preserved; that is N / D <> NUM / DEN.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let rc = Full::adjust::<1, 1>(rc);

assert_eq!(42, *rc);

Reborrows into another StaticRcRef.

The current instance is mutably borrowed for the duration the result can be used.

Example
use static_rc::StaticRcRef;
let mut x = 5;
let rc_full: StaticRcRef<i32, 2, 2> = StaticRcRef::new(&mut x);
let (mut rc1, mut rc2) = StaticRcRef::split::<1, 1>(rc_full);
{
    // Modify without moving `rc1`, `rc2`.
    let rc_borrow1 = StaticRcRef::reborrow(&mut rc1);
    let rc_borrow2 = StaticRcRef::reborrow(&mut rc2);
    let mut rcref_full: StaticRcRef<_, 2, 2> = StaticRcRef::join(rc_borrow1, rc_borrow2);
    *rcref_full = 9;
    // Reborrow ends, can use the original refs again
}
let rc_full: StaticRcRef<_, 2, 2> = StaticRcRef::join(rc1, rc2);
assert_eq!(*rc_full, 9);
assert_eq!(x, 9);

Splits the current instance into two instances with the specified NUMerators.

Panics

If the compile-time-ratio feature is not used, and the ratio is not preserved; that is A + B <> NUM.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let (one, two) = Full::split::<1, 1>(rc);

assert_eq!(42, *one);
assert_eq!(42, *two);

Splits the current instance into DIM instances with the specified Numerators.

Panics

If the compile-time-ratio feature is not used, and the ratio is not preserved; that is N * DIM <> NUM.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let array = Full::split_array::<1, 2>(rc);

assert_eq!(42, *array[0]);
assert_eq!(42, *array[1]);

Joins two instances into a single instance.

Panics

If the two instances do no point to the same allocation, as determined by StaticRcRef::ptr_eq.

If the compile-time-ratio feature is not used and the ratio is not preserved; that is A + B <> NUM.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let (one, two) = Full::split::<1, 1>(rc);
let rc = Full::join(one, two);

assert_eq!(42, *rc);

Joins two instances into a single instance without checking whether they point to the same allocation.

Unless compile-time-ratio is activated, the ratios are checked nevertheless.

Safety

The caller must guarantee that those instances point to the same allocation.

Panics

If the compile-time-ratio feature is not used and the ratio is not preserved; that is A + B <> NUM.

In debug, if the two instances do no point to the same allocation, as determined by StaticRcRef::ptr_eq.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let (one, two) = Full::split::<1, 1>(rc);
let rc = unsafe { Full::join_unchecked(one, two) };

assert_eq!(42, *rc);

Joins DIM instances into a single instance.

Panics

If all instances do not point to the same allocation, as determined by StaticRcRef::ptr_eq.

If the compile-time-ratio feature is not used and the ratio is not preserved; that is N * DIM <> NUM.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let array = Full::split_array::<1, 2>(rc);
let rc = Full::join_array(array);

assert_eq!(42, *rc);

Joins DIM instances into a single instance.

Panics

If the compile-time-ratio feature is not used and the ratio is not preserved; that is N * DIM <> NUM.

In debug, if all instances do not point to the same allocation, as determined by StaticRcRef::ptr_eq.

Example
use static_rc::StaticRcRef;

type Full<'a> = StaticRcRef<'a, i32, 2, 2>;

let mut value = 42;
let rc = Full::new(&mut value);
let array = Full::split_array::<1, 2>(rc);
let rc = unsafe { Full::join_array_unchecked(array) };

assert_eq!(42, *rc);

Attempts to downcast Self to a concrete type.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Formats the value using the given formatter. Read more
Removes and returns an element from the end of the iterator. Read more
Returns the nth element from the end of the iterator. Read more
🔬This is a nightly-only experimental API. (iter_advance_by)
Advances the iterator from the back by n elements. Read more
This is the reverse version of Iterator::try_fold(): it takes elements starting from the back of the iterator. Read more
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. Read more
Searches for an element of an iterator from the back that satisfies a predicate. Read more
Returns the exact remaining length of the iterator. Read more
🔬This is a nightly-only experimental API. (exact_size_is_empty)
Returns true if the iterator is empty. Read more
Converts to this type from the input type.
The type of value produced on completion.
Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The type of the elements being iterated over.
Advances the iterator and returns the next value. Read more
Returns the bounds on the remaining length of the iterator. Read more
Returns the nth element of the iterator. Read more
Consumes the iterator, returning the last element. Read more
🔬This is a nightly-only experimental API. (iter_next_chunk)
Advances the iterator and returns an array containing the next N values. Read more
Consumes the iterator, counting the number of iterations and returning it. Read more
🔬This is a nightly-only experimental API. (iter_advance_by)
Advances the iterator by n elements. Read more
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
Takes two iterators and creates a new iterator over both in sequence. Read more
‘Zips up’ two iterators into a single iterator of pairs. Read more
🔬This is a nightly-only experimental API. (iter_intersperse)
Creates a new iterator which places an item generated by separator between adjacent items of the original iterator. Read more
Takes a closure and creates an iterator which calls that closure on each element. Read more
Calls a closure on each element of an iterator. Read more
Creates an iterator which uses a closure to determine if an element should be yielded. Read more
Creates an iterator that both filters and maps. Read more
Creates an iterator which gives the current iteration count as well as the next value. Read more
Creates an iterator which can use the peek and peek_mut methods to look at the next element of the iterator without consuming it. See their documentation for more information. Read more
Creates an iterator that skips elements based on a predicate. Read more
Creates an iterator that yields elements based on a predicate. Read more
Creates an iterator that both yields elements based on a predicate and maps. Read more
Creates an iterator that skips the first n elements. Read more
Creates an iterator that yields the first n elements, or fewer if the underlying iterator ends sooner. Read more
An iterator adapter similar to fold that holds internal state and produces a new iterator. Read more
Creates an iterator that works like map, but flattens nested structure. Read more
Creates an iterator which ends after the first None. Read more
Does something with each element of an iterator, passing the value on. Read more
Borrows an iterator, rather than consuming it. Read more
Transforms an iterator into a collection. Read more
🔬This is a nightly-only experimental API. (iter_collect_into)
Collects all the items from an iterator into a collection. Read more
Consumes an iterator, creating two collections from it. Read more
🔬This is a nightly-only experimental API. (iter_is_partitioned)
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return true precede all those that return false. Read more
An iterator method that applies a function as long as it returns successfully, producing a single, final value. Read more
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. Read more
Folds every element into an accumulator by applying an operation, returning the final result. Read more
Reduces the elements to a single one, by repeatedly applying a reducing operation. Read more
🔬This is a nightly-only experimental API. (iterator_try_reduce)
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. Read more
Tests if every element of the iterator matches a predicate. Read more
Tests if any element of the iterator matches a predicate. Read more
Searches for an element of an iterator that satisfies a predicate. Read more
Applies function to the elements of iterator and returns the first non-none result. Read more
🔬This is a nightly-only experimental API. (try_find)
Applies function to the elements of iterator and returns the first true result or the first error. Read more
Searches for an element in an iterator, returning its index. Read more
Returns the element that gives the maximum value from the specified function. Read more
Returns the element that gives the maximum value with respect to the specified comparison function. Read more
Returns the element that gives the minimum value from the specified function. Read more
Returns the element that gives the minimum value with respect to the specified comparison function. Read more
Converts an iterator of pairs into a pair of containers. Read more
Creates an iterator which copies all of its elements. Read more
Creates an iterator which clones all of its elements. Read more
🔬This is a nightly-only experimental API. (iter_array_chunks)
Returns an iterator over N elements of the iterator at a time. Read more
Sums the elements of an iterator. Read more
Iterates over the entire iterator, multiplying all the elements Read more
🔬This is a nightly-only experimental API. (iter_order_by)
Lexicographically compares the elements of this Iterator with those of another with respect to the specified comparison function. Read more
Lexicographically compares the elements of this Iterator with those of another. Read more
🔬This is a nightly-only experimental API. (iter_order_by)
Lexicographically compares the elements of this Iterator with those of another with respect to the specified comparison function. Read more
Determines if the elements of this Iterator are equal to those of another. Read more
🔬This is a nightly-only experimental API. (iter_order_by)
Determines if the elements of this Iterator are equal to those of another with respect to the specified equality function. Read more
Determines if the elements of this Iterator are unequal to those of another. Read more
Determines if the elements of this Iterator are lexicographically less than those of another. Read more
Determines if the elements of this Iterator are lexicographically less or equal to those of another. Read more
Determines if the elements of this Iterator are lexicographically greater than those of another. Read more
Determines if the elements of this Iterator are lexicographically greater than or equal to those of another. Read more
🔬This is a nightly-only experimental API. (is_sorted)
Checks if the elements of this iterator are sorted using the given comparator function. Read more
🔬This is a nightly-only experimental API. (is_sorted)
Checks if the elements of this iterator are sorted using the given key extraction function. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The output that the future will produce on completion.
Which kind of future are we turning this into?
Creates a future from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.