rune_alloc/callable.rs
1//! A trait used for types which can be called.
2//!
3//! This trait allows for memory [`limits`] and [`budgets`] to be combined.
4//!
5//! [`limits`]: crate::limit
6//! [`budgets`]: ../../runtime/budget/index.html
7
8/// A trait used for types which can be called.
9///
10/// This trait allows for memory [`limits`] and [`budgets`] to be combined.
11///
12/// [`limits`]: crate::limit
13/// [`budgets`]: ../../runtime/budget/index.html
14pub trait Callable {
15 /// Output of the callable.
16 type Output;
17
18 /// Call and consume the callable.
19 fn call(self) -> Self::Output;
20}
21
22/// Blanket implementation for closures.
23impl<T, O> Callable for T
24where
25 T: FnOnce() -> O,
26{
27 type Output = O;
28
29 fn call(self) -> Self::Output {
30 self()
31 }
32}