Expand description
This crate enables the creation of functions, methods, traits or even structs generic over mutability.
The main use case is allowing crates to write pairs of getter functions of the form
ⓘ
fn get<'a>(&'a T, ...) -> &'a U
fn get_mut<'a>(&'a mut T, ...) -> &'a mut U
as a single function
ⓘ
fn get_gen<'a, M: Mutability>(GenRef<'a, M, T>, ...) -> GenRef<'a, M, U>
The main items of this crate are the GenRef
struct, which represents a safe reference (like &
and &mut
) that is generic over mutability; and the Mutability
trait, which is used as a bound on generic mutability parameters.
Macros§
- field
- Maps a
GenRef
over field access and indexing. - gen_mut
- This macro simplifies the implementation of generically mutable APIs, where the mutable and the shared code paths are (mostly) identical. It has the following syntax:
Structs§
- GenRef
- This is the main type of this crate.
It is the generic-mutability equivalent of safe reference types (
&
and&mut
). - IsMutable
- The existence of a value of this type guarantees that a specific mutability parameter
M
isMutable
. Unsafe code may rely on this guarantee. You can obtain this value by matching overM::mutability()
. - IsShared
- The existence of a value of this type guarantees that a specific mutability parameter
M
isShared
. Unsafe code may rely on this guarantee. You can obtain this value by matching overM::mutability()
.
Enums§
- Mutability
Enum - This enum makes it possible to
match
over a mutability parameter. Not to be confused with theMutability
trait, which is used as a bound for mutability parameters; andShared
andMutable
, which are values of the mutability parameters. - Mutable
- Represents the mutability of a mutable (unique) reference,
&mut T
. - Shared
- Represents the mutability of a shared reference,
&T
.
Traits§
- GenRef
Methods - This trait allows you to call associated functions of
GenRef
with method syntax. - Mutability
- This trait is used as a bound on generic mutability parameters.