Skip to main content

concurrent_intrusive_collections/
error.rs

1use std::fmt;
2
3/// A rejected push, retaining ownership of the unpublished node.
4pub enum PushError<T> {
5    /// The collection was closed. The node can be reused or dropped.
6    Closed(Box<T>),
7}
8
9impl<T> PushError<T> {
10    /// Recovers ownership of the rejected node.
11    pub fn into_inner(self) -> Box<T> {
12        match self {
13            Self::Closed(node) => node,
14        }
15    }
16}
17
18impl<T> fmt::Debug for PushError<T> {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            Self::Closed(node) => f
22                .debug_tuple("Closed")
23                .field(&(node.as_ref() as *const T))
24                .finish(),
25        }
26    }
27}
28
29impl<T> fmt::Display for PushError<T> {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        f.write_str("collection is closed")
32    }
33}
34
35impl<T> std::error::Error for PushError<T> {}
36
37/// The result of an operation that did not find a node.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum PopError {
40    /// No node was found, and the collection was observed open.
41    ///
42    /// For a sharded collection this describes a scan, not an atomic snapshot of
43    /// all shards. A concurrent push can make another node available.
44    Empty,
45    /// The collection was observed empty and closed.
46    Closed,
47}
48
49impl fmt::Display for PopError {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        f.write_str(match self {
52            Self::Empty => "collection is empty",
53            Self::Closed => "collection is closed and empty",
54        })
55    }
56}
57
58impl std::error::Error for PopError {}