File: types.md

package info (click to toggle)
rust-radium 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 160 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Aliases and Type Families

This module provides `RadiumT` aliases that correspond to `AtomicT` from the
standard library, and resolve to `AtomicT` when it exists and `Cell<T>` when it
does not.

In addition, newtype structs `Atom<T>` and `Isotope<T>` correspond to (and
contain) `AtomicT` and `RadiumT`, respectively. These newtypes are designed to
be used in cases where you are generic over a primitive and want to plug it into
a shared-mutable wrapper type without having to specifically name one of the
`AtomicT` or `RadiumT` individual names.

Lastly, the `Radon<T>` newtype struct wraps `Cell<T>` and only implements the
`Radium` API, mirroring `Atom<T>` and `Isotope<T>`. This type exists so that
client crates can switch out types based on a crate feature to disable atomics,
and guarantee that their API will continue to function in every regard (except
for losing `Sync` impls).

## Examples

```rust
use radium::{Radium, types::*};

#[cfg(target_has_atomic = "ptr")]
let a = Atom::new(0usize);

let b = Isotope::new(1usize);

let c = Radon::new(2usize);

// when atomics are not disabled, use best-effort
#[cfg(feature = "atomics")]
pub type MyIsotope<T> = Isotope<T>;

// when atomics are fully disabled, enforce use of `Cell`
#[cfg(not(feature = "atomics"))]
pub type MyIsotope<T> = Radon<T>;
```