pub struct Budget(/* private fields */);
testutils
only.Expand description
Budget that tracks the resources consumed for the environment.
The budget consistents of two cost dimensions:
- CPU instructions
- Memory
Inputs feed into those cost dimensions.
Note that all cost dimensions – CPU instructions, memory – and the VM cost type inputs are likely to be underestimated when running Rust code compared to running the WASM equivalent.
§Examples
use soroban_sdk::{Env, Symbol};
env.cost_estimate().budget().reset_default();
// ...
println!("{}", env.cost_estimate().budget());
Implementations§
Source§impl Budget
impl Budget
Sourcepub fn reset_default(&mut self)
pub fn reset_default(&mut self)
Reset the budget.
pub fn reset_unlimited(&mut self)
pub fn reset_limits(&mut self, cpu: u64, mem: u64)
pub fn reset_tracker(&mut self)
Sourcepub fn cpu_instruction_cost(&self) -> u64
pub fn cpu_instruction_cost(&self) -> u64
Returns the CPU instruction cost.
Note that CPU instructions are likely to be underestimated when running Rust code compared to running the WASM equivalent.
Sourcepub fn memory_bytes_cost(&self) -> u64
pub fn memory_bytes_cost(&self) -> u64
Returns the memory cost.
Note that memory is likely to be underestimated when running Rust code compared to running the WASM equivalent.
Sourcepub fn tracker(&self, cost_type: ContractCostType) -> CostTracker
pub fn tracker(&self, cost_type: ContractCostType) -> CostTracker
Get the cost tracker associated with the cost type. The tracker
tracks the cumulative iterations and inputs and derived cpu and
memory. If the underlying model is a constant model, then inputs is
None
and only iterations matter.
Note that VM cost types are likely to be underestimated when running natively as Rust code inside tests code compared to running the WASM equivalent.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Budget
impl !RefUnwindSafe for Budget
impl !Send for Budget
impl !Sync for Budget
impl Unpin for Budget
impl !UnwindSafe for Budget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more