Trait soroban_sdk::xdr::curr::DepthLimiter
pub trait DepthLimiter {
type DepthLimiterError;
// Required methods
fn enter(&mut self) -> Result<(), Self::DepthLimiterError>;
fn leave(&mut self) -> Result<(), Self::DepthLimiterError>;
// Provided method
fn with_limited_depth<T, F>(
&mut self,
f: F
) -> Result<T, Self::DepthLimiterError>
where F: FnOnce(&mut Self) -> Result<T, Self::DepthLimiterError> { ... }
}
Expand description
DepthLimiter
is a trait designed for managing the depth of recursive operations.
It provides a mechanism to limit recursion depth, and defines the behavior upon
entering and leaving a recursion level.
Required Associated Types§
type DepthLimiterError
type DepthLimiterError
A general error type for any type implementing, or an operation under the guard of
DepthLimiter
. It must at least include the error case where the depth limit is exceeded
which is returned from enter
.
Required Methods§
fn enter(&mut self) -> Result<(), Self::DepthLimiterError>
fn enter(&mut self) -> Result<(), Self::DepthLimiterError>
Defines the behavior for entering a new recursion level.
A DepthLimiterError
is returned if the new level exceeds the depth limit.
fn leave(&mut self) -> Result<(), Self::DepthLimiterError>
fn leave(&mut self) -> Result<(), Self::DepthLimiterError>
Defines the behavior for leaving a recursion level.
A DepthLimiterError
is returned if an error occurs.
Provided Methods§
fn with_limited_depth<T, F>(
&mut self,
f: F
) -> Result<T, Self::DepthLimiterError>
fn with_limited_depth<T, F>( &mut self, f: F ) -> Result<T, Self::DepthLimiterError>
Wraps a given function f
with depth limiting guards.
It triggers an enter
before, and a leave
after the execution of f
.
Parameters
f
: The function to be executed under depth limit constraints.
Returns
Err
if 1. the depth limit has been exceeded uponenter
2.f
executes with an error 3. if error occurs onleave
.Ok
otherwise.