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
//! Traits for modelling the output of MockFns used with `returns`.

use crate::alloc::Box;

pub(crate) mod deep;
pub(crate) mod lending;
pub(crate) mod mut_lending;
pub(crate) mod owning;
pub(crate) mod shallow;
pub(crate) mod static_ref;

#[derive(Debug)]
#[doc(hidden)]
pub enum OutputError {
    OwnershipRequired,
    NoMutexApi,
}

type OutputResult<T> = Result<T, OutputError>;

/// This trait bounds various higher order type categories used as responses.
pub trait Kind: 'static {
    /// A type used to store return values
    type Return: GetOutput;
}

/// A [Kind] that may be used with `returns` combinators.
pub trait Return: Kind {
    /// Type of the return value, as stored inside Unimock.
    type Type: 'static;
}

/// A type from which it is possible to produce an output,
/// without consuming the value.
pub trait GetOutput: Sized + 'static {
    /// The output this value produces
    type Output<'u>
    where
        Self: 'u;

    /// Produce an output
    fn output(&self) -> Option<Self::Output<'_>>;
}

/// A type that can be converted into a [Kind::Return] that can be returned one time.
pub trait IntoReturnOnce<K: Kind> {
    #[doc(hidden)]
    fn into_return_once(self) -> OutputResult<K::Return>;
}

/// A type that can be converted into a [Kind::Return] that can be returned any number of times.
pub trait IntoReturn<K: Kind>: IntoReturnOnce<K> {
    #[doc(hidden)]
    fn into_return(self) -> OutputResult<K::Return>;
}

/// A type that can be returned by its [Default] implementation.
pub trait ReturnDefault<K: Kind> {
    #[doc(hidden)]
    fn return_default() -> K::Return;
}

/// A "marker" for mutable types
pub struct Mutable<T>(pub(crate) T);

pub use deep::Deep;
pub use lending::Lending;
pub use mut_lending::MutLending;
pub use owning::Owning;
pub use shallow::Shallow;
pub use static_ref::StaticRef;