pub struct SnapshotSourceInput {
pub source: Rc<dyn SnapshotSource>,
pub ledger_info: Option<LedgerInfo>,
pub snapshot: Option<Rc<LedgerSnapshot>>,
}testutils only.Expand description
Input for creating an Env from a custom snapshot source.
This struct enables Env::from_ledger_snapshot to accept custom snapshot
source types beyond LedgerSnapshot, providing flexibility for testing
scenarios that load ledger state from different sources such as RPC endpoints,
history archives, or in-memory data structures.
§Fields
-
source- A snapshot source implementing theSnapshotSourcetrait. This is used to load ledger entries on demand during test execution. -
ledger_info- Optional ledger info to initialize the environment with. IfNone, default test ledger info is used. -
snapshot- OptionalLedgerSnapshotused as the base for capturing state changes. When the test completes, modified entries are written to this snapshot. IfNone, a new empty snapshot is created.
§Example
use soroban_sdk::testutils::{SnapshotSource, SnapshotSourceInput, HostError};
use soroban_sdk::xdr::{LedgerEntry, LedgerKey};
use soroban_sdk::Env;
use std::rc::Rc;
struct MyCustomSource;
impl SnapshotSource for MyCustomSource {
fn get(
&self,
key: &Rc<LedgerKey>,
) -> Result<Option<(Rc<LedgerEntry>, Option<u32>)>, HostError> {
// Return None for keys not found, or Some((entry, live_until_ledger))
Ok(None)
}
}
let input = SnapshotSourceInput {
source: Rc::new(MyCustomSource),
ledger_info: None,
snapshot: None,
};
let env = Env::from_ledger_snapshot(input);Fields§
§source: Rc<dyn SnapshotSource>§ledger_info: Option<LedgerInfo>§snapshot: Option<Rc<LedgerSnapshot>>Trait Implementations§
Source§impl From<LedgerSnapshot> for SnapshotSourceInput
Converts a LedgerSnapshot into a SnapshotSourceInput.
impl From<LedgerSnapshot> for SnapshotSourceInput
Converts a LedgerSnapshot into a SnapshotSourceInput.
This conversion maintains backward compatibility with the existing API,
allowing LedgerSnapshot to be used directly with Env::from_ledger_snapshot.
The LedgerSnapshot is wrapped in an Rc and used for all three fields:
- As the snapshot source for loading ledger entries
- To provide the ledger info for the environment
- As the base snapshot for capturing state changes
Source§fn from(s: LedgerSnapshot) -> Self
fn from(s: LedgerSnapshot) -> Self
Auto Trait Implementations§
impl Freeze for SnapshotSourceInput
impl !RefUnwindSafe for SnapshotSourceInput
impl !Send for SnapshotSourceInput
impl !Sync for SnapshotSourceInput
impl Unpin for SnapshotSourceInput
impl UnsafeUnpin for SnapshotSourceInput
impl !UnwindSafe for SnapshotSourceInput
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