rune_alloc/
callable.rs

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
//! A trait used for types which can be called.
//!
//! This trait allows for memory [`limits`] and [`budgets`] to be combined.
//!
//! [`limits`]: crate::limit
//! [`budgets`]: ../../runtime/budget/index.html

/// A trait used for types which can be called.
///
/// This trait allows for memory [`limits`] and [`budgets`] to be combined.
///
/// [`limits`]: crate::limit
/// [`budgets`]: ../../runtime/budget/index.html
pub trait Callable {
    /// Output of the callable.
    type Output;

    /// Call and consume the callable.
    fn call(self) -> Self::Output;
}

/// Blanket implementation for closures.
impl<T, O> Callable for T
where
    T: FnOnce() -> O,
{
    type Output = O;

    fn call(self) -> Self::Output {
        self()
    }
}