Skip to content

Commit 53db5a0

Browse files
docs: add documentation for future interpreter API
Added missing documentation for all public APIs in the future interpreter module. This includes the FutureInterpreterAction trait, FutureInterpreterSubmit and FutureInterpreter structs, along with their public methods. The documentation follows the project's standards and provides clear explanations of parameters, return values, and usage patterns for async EVM operations.
1 parent 0fbf596 commit 53db5a0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

future/src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![warn(missing_docs)]
23

34
extern crate alloc;
45

@@ -14,10 +15,26 @@ use evm::interpreter::{
1415
Capture, ExitError, ExitFatal, ExitResult, FeedbackInterpreter, Interpreter,
1516
};
1617

18+
/// An action that can be executed by a future interpreter.
19+
///
20+
/// This trait defines the interface for asynchronous operations that can be
21+
/// submitted to a future interpreter. Implementations should handle the
22+
/// execution logic and return appropriate feedback or trap information.
1723
pub trait FutureInterpreterAction<S, H> {
24+
/// The feedback type returned when the action completes successfully.
1825
type Feedback;
26+
/// The trap type that can be raised during action execution.
1927
type Trap;
2028

29+
/// Execute the action with the given state, return buffer, and handler.
30+
///
31+
/// # Parameters
32+
/// - `state`: Mutable reference to the interpreter state
33+
/// - `retbuf`: Mutable reference to the return buffer
34+
/// - `handle`: Mutable reference to the handler
35+
///
36+
/// # Returns
37+
/// A `Capture` that either contains feedback on success or a trap on failure.
2138
fn run(
2239
self,
2340
state: &mut S,
@@ -26,6 +43,11 @@ pub trait FutureInterpreterAction<S, H> {
2643
) -> Capture<Self::Feedback, Self::Trap>;
2744
}
2845

46+
/// A submitter for future interpreter actions.
47+
///
48+
/// This structure manages the submission and feedback mechanism for asynchronous
49+
/// actions in a future interpreter. It provides a way to submit actions and
50+
/// receive feedback through a future-based interface.
2951
pub struct FutureInterpreterSubmit<A, F> {
3052
action: Cell<Option<A>>,
3153
action_feedback: Cell<Option<F>>,
@@ -39,6 +61,13 @@ impl<A, F> FutureInterpreterSubmit<A, F> {
3961
}
4062
}
4163

64+
/// Submit an action for execution and return a future that resolves with feedback.
65+
///
66+
/// # Parameters
67+
/// - `action`: The action to be executed
68+
///
69+
/// # Returns
70+
/// A future that resolves with the feedback from the action execution.
4271
pub fn submit(self: Rc<Self>, action: A) -> impl Future<Output = F> {
4372
struct SubmitFuture<A, F>(Cell<Option<A>>, Rc<FutureInterpreterSubmit<A, F>>);
4473

@@ -64,6 +93,11 @@ impl<A, F> FutureInterpreterSubmit<A, F> {
6493
}
6594
}
6695

96+
/// A future-based interpreter for asynchronous EVM operations.
97+
///
98+
/// This interpreter allows for asynchronous execution of EVM operations,
99+
/// particularly useful for async precompiles and other operations that
100+
/// require non-blocking execution.
67101
pub struct FutureInterpreter<A, F, S, Tr> {
68102
state: S,
69103
retbuf: Vec<u8>,
@@ -73,6 +107,15 @@ pub struct FutureInterpreter<A, F, S, Tr> {
73107
}
74108

75109
impl<A, F, S, Tr> FutureInterpreter<A, F, S, Tr> {
110+
/// Create a new future interpreter.
111+
///
112+
/// # Parameters
113+
/// - `state`: The initial state for the interpreter
114+
/// - `retbuf`: The return buffer for the interpreter
115+
/// - `f`: A function that creates the future to be executed
116+
///
117+
/// # Returns
118+
/// A new `FutureInterpreter` instance.
76119
pub fn new<Fn, Fu>(state: S, retbuf: Vec<u8>, f: Fn) -> Self
77120
where
78121
Fn: FnOnce(Rc<FutureInterpreterSubmit<A, F>>) -> Fu,

0 commit comments

Comments
 (0)