-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathlib.rs
More file actions
76 lines (66 loc) · 2.3 KB
/
lib.rs
File metadata and controls
76 lines (66 loc) · 2.3 KB
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
76
//! Safely coordinate concurrent components.
//!
//! # Status
//!
//! Stability varies by primitive. See [README](https://github.com/commonwarexyz/monorepo#stability) for details.
#![doc(
html_logo_url = "https://commonware.xyz/imgs/rustdoc_logo.svg",
html_favicon_url = "https://commonware.xyz/favicon.ico"
)]
commonware_macros::stability_scope!(BETA {
/// Feedback from submitting work to a bounded endpoint.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Feedback {
/// The work was accepted within the configured capacity.
Ok,
/// The submission exceeded configured capacity but was handled by the overflow policy.
Backoff,
/// The endpoint is closed.
Closed,
}
impl Feedback {
/// Returns `true` when the endpoint handled the submission.
pub const fn accepted(self) -> bool {
matches!(self, Self::Ok | Self::Backoff)
}
}
/// Feedback from endpoints that may reject work under backpressure.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Unreliable<T> {
/// Endpoint outcome from the submission attempt.
Outcome(T),
/// The work was rejected by the endpoint.
Rejected,
}
impl<T> Unreliable<T> {
/// Wrap an outcome for an operation that may reject work.
pub const fn new(outcome: T) -> Self {
Self::Outcome(outcome)
}
/// Create a rejected result.
pub const fn rejected() -> Self {
Self::Rejected
}
/// Returns `true` when the operation was rejected before producing an outcome.
pub const fn is_rejected(&self) -> bool {
matches!(self, Self::Rejected)
}
/// Returns the outcome when the operation was not rejected.
pub fn outcome(self) -> Option<T> {
match self {
Self::Outcome(outcome) => Some(outcome),
Self::Rejected => None,
}
}
}
impl Unreliable<Feedback> {
/// Returns `true` when the endpoint handled the submission.
pub const fn accepted(self) -> bool {
match self {
Self::Outcome(feedback) => feedback.accepted(),
Self::Rejected => false,
}
}
}
pub mod mailbox;
});