clone_behavior/
speed.rs

1mod sealed {
2    #[expect(unnameable_types, reason = "This is intentional, and creates a sealed trait")]
3    pub trait Sealed {}
4}
5
6
7use self::sealed::Sealed;
8
9
10/// Trait for indicating the overhead and/or time complexity of a cloning operation.
11pub trait Speed: Sealed {}
12
13/// Indicates that a cloning operation is:
14/// - constant time
15/// - nonblocking (atomic operations may be fine, but acquiring a lock is not)
16/// - at most the overhead of a few atomic operations
17/// - generally, deserving of being called near-instant in speed.
18///
19/// The nightly-only [`UseCloned`](https://doc.rust-lang.org/std/clone/trait.UseCloned.html) trait
20/// provides additional constraints, that may be worth considering.
21pub enum NearInstant {}
22/// Indicates that a cloning operation is constant-time, but might involve acquiring a lock or
23/// performing some computations that aren't [`NearInstant`].
24pub enum ConstantTime {}
25/// Indicates that a cloning operation operates in logarithmic time or faster.
26pub enum LogTime {}
27/// Places no constraint on the overhead or time complexity of a cloning operation.
28pub enum AnySpeed {}
29
30impl Speed for NearInstant {}
31impl Speed for ConstantTime {}
32impl Speed for LogTime {}
33impl Speed for AnySpeed {}
34
35impl Sealed for NearInstant {}
36impl Sealed for ConstantTime {}
37impl Sealed for LogTime {}
38impl Sealed for AnySpeed {}