pub struct Inlined;Expand description
Pick an inlined Kamaji backend from a caller-supplied preference list.
prefer is walked in order; the first backend whose probe came back
available is selected, the matching factory is invoked, and the resulting
trait object is returned. If none of the preferred backends are
available, the function returns the probe error for the last entry
in the preference list (its install hint is what the caller most wanted).
§Example shape
let availability = BackendAvailability::probe().await;
let kamaji = Inlined::pick(
&availability,
&[Backend::Docker, Backend::Containerd],
|backend| match backend {
Backend::Docker => Ok(Arc::new(docker::DockerRuntime::new()) as Arc<dyn Kamaji>),
Backend::Containerd => Ok(Arc::new(containerd::ContainerdRuntime::connect_at(socket).await?) as _),
Backend::Native => unreachable!("not in preference list"),
},
)?;The factory closure is invoked only for the selected backend, so callers can construct backends that themselves require I/O without paying for the ones they don’t pick.
Implementations§
Source§impl Inlined
impl Inlined
Sourcepub fn pick<F>(
availability: &BackendAvailability,
prefer: &[Backend],
factory: F,
) -> Result<Arc<dyn Kamaji>, BackendUnavailable>
pub fn pick<F>( availability: &BackendAvailability, prefer: &[Backend], factory: F, ) -> Result<Arc<dyn Kamaji>, BackendUnavailable>
Walk prefer in order and return the first available backend.
The factory is invoked exactly once with the chosen backend tag.
Returns BackendUnavailable for the last preferred backend if
none are available (callers who prefer Docker but accept Containerd
see the Docker install hint).