diff options
author | Katharina Fey <kookie@spacekookie.de> | 2021-01-09 01:16:40 +0100 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2021-01-09 01:48:01 +0100 |
commit | b982e34a7fe68568440c3c17557ed1547b6a9fa6 (patch) | |
tree | 2d7b97bc926498500df1348d1223948d27c5c4c2 | |
parent | 95f76277437140468846fae0885ef05f3fedd150 (diff) |
atomptr: add direct crate docs instead of relying on doc(include)
-rw-r--r-- | development/libs/atomptr/src/lib.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/development/libs/atomptr/src/lib.rs b/development/libs/atomptr/src/lib.rs index 92410fc4bc38..df993b2d6601 100644 --- a/development/libs/atomptr/src/lib.rs +++ b/development/libs/atomptr/src/lib.rs @@ -1,5 +1,33 @@ -#![feature(external_doc)] -#![doc(include = "../README.md")] +//! A safe, strongly typed (generic) atomic pointer abstraction to build +//! datastructures, and lock-free algorithms on top of. Only uses +//! `libstd`. +//! +//! The standard library contains an `AtomicPtr` type, which by itself +//! isn't very ergonomic to use, because it deals with raw pointers. This +//! library assumes that types can always be heap allocated, wrapping them +//! in a `Box<T>`, and provides a nicer (and safe!) abstraction for +//! `std::sync::atomic::AtomicPtr`. Using this crate is fairely +//! self-explanatory: +//! +//! ```rust +//! use atomptr::AtomPtr; +//! +//! struct MyData { name: String } +//! let data = MyData { name: "Kookie".into() }; +//! +//! let a = AtomPtr::new(data); +//! println!("Name is: {}", a.get_ref().name); +//! +//! let old_ref = a.swap(MyData { name: "Bob".into() }); +//! println!("Name now is: {}, was {}", a.get_ref().name, old_ref.name); +//! ``` +//! +//! Note that the type that is returned by `get_ref` and `swap` is +//! `Ref<T>`, which means that the old data is not de-allocated after a +//! swap, before this last reference goes out of scope. You can of course +//! always manually call `drop()` on it. + + use std::sync::{ atomic::{AtomicPtr, Ordering}, |