pub struct PocketIcInstance<T> { /* private fields */ }Expand description
An upstream instance together with the server owned by its construction.
Fields are ordered so a synchronous PocketIc is deleted before the server
is terminated. Connect mode borrows the caller’s server and returns None.
Native PocketIC operations remain available through Self::instance.
Self::into_parts explicitly transfers teardown ordering to the caller.
PocketIC 16 synchronous deletion has no request deadline and can block drop.
Its nonblocking instance has no automatic deletion: call
Self::into_parts, then instance.drop().await while retaining server,
when deletion matters, especially with a borrowed server. Dropping an owned
server stops all its instances.
Field projection cannot silently detach the client from its server:
use ic_testkit::pic::PocketIcInstance;
fn detach<T>(owned: PocketIcInstance<T>) -> T {
owned.instance
}Nor can a client borrow outlive a temporary owner:
use ic_testkit::pic::PocketIcInstance;
let client = PocketIcInstance::from_borrowed_server(String::new()).instance();
assert!(client.is_empty());Implementations§
Source§impl<T> PocketIcInstance<T>
impl<T> PocketIcInstance<T>
Sourcepub const fn from_borrowed_server(instance: T) -> Self
pub const fn from_borrowed_server(instance: T) -> Self
Retain an existing client whose server lifetime is owned elsewhere.
This creates no server or instance and claims no server process authority. The client retains its upstream deletion behavior; its external server must outlive it. Use a startup configuration for a managed server owner.
Sourcepub const fn instance(&self) -> &T
pub const fn instance(&self) -> &T
Borrow the client while retaining this record’s managed-server ownership.
Sourcepub const fn instance_mut(&mut self) -> &mut T
pub const fn instance_mut(&mut self) -> &mut T
Mutably borrow the client while retaining managed-server ownership.
Supports client setup such as PocketIc::make_live without splitting the
owner. Replacing the client transfers responsibility for the old client’s
server lifetime to the caller, just as with Self::into_parts.
The borrow cannot outlive the owner:
use ic_testkit::pic::PocketIcInstance;
let client = PocketIcInstance::from_borrowed_server(String::new()).instance_mut();
client.push_str("gateway");Sourcepub const fn server(&self) -> Option<&PocketIcManagedServer>
pub const fn server(&self) -> Option<&PocketIcManagedServer>
Borrow the exact managed server, or None for an externally owned server.
Sourcepub fn into_parts(self) -> (T, Option<PocketIcManagedServer>)
pub fn into_parts(self) -> (T, Option<PocketIcManagedServer>)
Transfer the client and optional server, without deleting or stopping either.
The caller must retain the server until client deletion is complete. For
a nonblocking client, explicitly await instance.drop() before dropping
the returned server. No implicit asynchronous or blocking cleanup is added.