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
use RwLock;
use Arc;
/// A convenience type alias for `Arc<RwLock<T>>`.
///
/// # Example
///
/// ```
/// use std::sync::Arc;
/// use std::sync::RwLock;
/// use xrcf::shared::Shared;
///
/// let lock = Shared::new(42.into());
/// assert_eq!(*lock.try_read().unwrap(), 42);
/// ```
/// can also be used together with [SharedExt].
pub type Shared<T> = ;
/// A convenience trait around [RwLock].
///
/// This trait makes using [RwLock] less verbose. It has two benefits. One is
/// obviously that it saves a lot of typing. Another one is that one-liners are
/// particularly powerful in Rust due to when variables are freed, see
/// <https://xrcf.org/blog/iterators/> for more information.
///
/// Regarding the lost access to error handling (now it just always crashes),
/// that's for now the default behavior until the project starts to support
/// multithreading. Until that feature is introduced, any blocking should crash
/// since it will hang anyway.
///
/// # Example
///
/// With this trait and with `Shared`:
/// ```
/// use std::sync::Arc;
/// use std::sync::RwLock;
/// use xrcf::shared::Shared;
/// use xrcf::shared::SharedExt;
///
/// let lock = Shared::new(42.into());
/// assert_eq!(*lock.rd(), 42);
/// ```
/// Without this trait:
/// ```
/// use std::sync::Arc;
/// use std::sync::RwLock;
///
/// let lock = Arc::new(RwLock::new(42));
/// assert_eq!(*lock.try_read().unwrap(), 42);
/// ```
/// Just another test that runs even if the docstrings would not.