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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! # Blocking `PinList`
//!
//! This version of PinList uses a [`BlockingMutex`] to mediate access to nodes.
//!
//! This allows for [pinned] [`Node<T>`]s to be attached to the list, and to allow
//! access to nodes of this list through a shared `&PinList`.
//!
//! Nodes are automatically removed when dropped, and nodes must be pinned when
//! added to the [`PinList`], meaning they cannot be safely forgotten.
//!
//! [`BlockingMutex`]: mutex::BlockingMutex
//! [pinned]: https://doc.rust-lang.org/stable/std/pin/index.html
//!
//! ## Examples
//!
//! A [`PinList`] may be created either as a static, or as an item that can be moved
//! around as part of another structure. As a static, it would look like this:
//!
//! ```rust
//! # // only works with `_docs` active so we have the CS impl
//! # #[cfg(feature = "_docs")]
//! # fn example() {
//! use core::pin::pin;
//! use pinlist::blocking::{PinList, Node};
//! use mutex::raw_impls::cs::CriticalSectionRawMutex as CsRm;
//!
//! // Our LIST contains all attached nodes
//! static LIST: PinList<CsRm, u64> = PinList::new();
//!
//! // Create the nodes for the list
//! let node_a = Node::new_for(&LIST, 123);
//! let node_b = Node::new_for(&LIST, 456);
//!
//! // Pin the nodes, and attach them to the list
//! let node_a = pin!(node_a);
//! let node_b = pin!(node_b);
//! let hdl_a = node_a.attach();
//! let hdl_b = node_b.attach();
//!
//! // Access can be made through the handle, while holding the lock
//! assert_eq!(123, hdl_a.with_lock(|a| *a));
//! assert_eq!(456, hdl_b.with_lock(|b| *b));
//!
//! // We can access all items through the list
//! let items = LIST.with_iter(|n| n.copied().collect::<Vec<_>>());
//! assert_eq!(&[123, 456], items.as_slice());
//!
//! // We can create an ephemeral item...
//! {
//! let node_c = Node::new_for(&LIST, 789);
//! let node_c = pin!(node_c);
//!
//! // Node C is not added until we attach
//! let items = LIST.with_iter(|n| n.copied().collect::<Vec<_>>());
//! assert_eq!(&[123, 456], items.as_slice());
//!
//! let _hdl_c = node_c.attach();
//! let items = LIST.with_iter(|n| n.copied().collect::<Vec<_>>());
//! assert_eq!(&[123, 456, 789], items.as_slice());
//! // node_c is dropped here
//! }
//!
//! // We can see node_c has been removed
//! let items = LIST.with_iter(|n| n.copied().collect::<Vec<_>>());
//! assert_eq!(&[123, 456], items.as_slice());
//! # }
//! # #[cfg(feature = "_docs")]
//! # example();
//! ```
pub use ;
pub use ;