generic_mutability/lib.rs
1#![no_std]
2#![deny(clippy::undocumented_unsafe_blocks)]
3#![deny(clippy::multiple_unsafe_ops_per_block)]
4#![deny(clippy::missing_safety_doc)]
5#![deny(unsafe_op_in_unsafe_fn)]
6
7//! This crate enables the creation of functions, methods, traits or even structs generic over mutability.
8//!
9//! The main use case is allowing crates to write pairs of getter functions of the form
10//! ```rust,ignore
11//! fn get<'a>(&'a T, ...) -> &'a U
12//! fn get_mut<'a>(&'a mut T, ...) -> &'a mut U
13//! ```
14//! as a single function
15//! ```rust,ignore
16//! fn get_gen<'a, M: Mutability>(GenRef<'a, M, T>, ...) -> GenRef<'a, M, U>
17//! ```
18//!
19//! 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*.
20
21mod genref;
22mod macros;
23mod mutability;
24
25pub use genref::genref_methods::GenRefMethods;
26pub use genref::GenRef;
27pub use mutability::{IsMutable, IsShared, Mutability, MutabilityEnum, Mutable, Shared};