Skip to main content

Resolver

Struct Resolver 

Source
pub struct Resolver { /* private fields */ }
Expand description

A composable chain of identity sources.

Use Resolver::with_defaults for the platform-appropriate default chain, or Resolver::new to start empty and build your own order with Resolver::push / Resolver::prepend.

Implementations§

Source§

impl Resolver

Source

pub fn new() -> Self

Start with an empty chain. No sources are tried until you add some.

Source

pub fn with_defaults() -> Self

Start with the default chain for the current platform.

The chain begins with the HOST_IDENTITY environment variable override, then — on Linux, when the container feature is on — inserts the container source ahead of the host-level sources so containers get their own identity, then walks the platform’s native sources in recommended order. See sources::default_chain for the exact contents on each OS.

This chain is strictly local: no source makes network calls.

Source

pub fn push<S: Source + 'static>(self, source: S) -> Self

Append a source to the end of the chain (lowest priority).

Source

pub fn push_boxed(self, source: Box<dyn Source>) -> Self

Append an already-boxed source. Use when you have Box<dyn Source> already — for example when building a chain from runtime input via crate::ids::resolver_from_ids.

Source

pub fn prepend<S: Source + 'static>(self, source: S) -> Self

Prepend a source to the front of the chain (highest priority).

O(n) in the existing chain length — each call shifts every other source. For a chain assembled from many prepends, build the full list first and pass it to Resolver::with_sources instead.

Source

pub fn with_sources<I, S>(self, sources: I) -> Self
where I: IntoIterator<Item = S>, S: Source + 'static,

Replace the entire chain. All items must be the same concrete Source type; for heterogeneous chains use Resolver::with_boxed_sources.

Source

pub fn into_boxed_sources(self) -> Vec<Box<dyn Source>>

Drain the chain, returning its boxed sources in chain order.

The wrap strategy is discarded — the caller reapplies one via Resolver::with_wrap when rebuilding. Use when you need to post-process the chain (for example, wrapping every source with crate::sources::AppSpecific) and feed the sources back via Resolver::with_boxed_sources.

Source

pub fn with_boxed_sources<I>(self, sources: I) -> Self
where I: IntoIterator<Item = Box<dyn Source>>,

Replace the entire chain with an already-boxed, heterogeneous list. Use when you have sources of different concrete types — with_sources requires a single concrete type for all items, so a mixed chain has to be boxed first.

use host_identity::{Resolver, Source};
use host_identity::sources::{EnvOverride, FnSource};

let chain: Vec<Box<dyn Source>> = vec![
    Box::new(EnvOverride::new("HOST_IDENTITY")),
    Box::new(FnSource::new(SourceKind::custom("x"), || Ok(None))),
];
let resolver = Resolver::new().with_boxed_sources(chain);
Source

pub fn with_wrap(self, wrap: Wrap) -> Self

Set the UUID-wrapping strategy applied to the raw identifier.

Defaults to Wrap::UuidV5Namespaced.

Source

pub fn source_kinds(&self) -> Vec<SourceKind>

Inspect the configured chain — useful for tests, diagnostics, and logging the resolver shape at startup.

Source

pub fn source_kinds_iter(&self) -> impl Iterator<Item = SourceKind> + '_

Non-allocating view of the chain’s source kinds, in order.

Use when you want to iterate without materialising a Vec — e.g. constructing a log line, or checking whether a specific kind is present. The returned iterator borrows self and must not outlive the resolver.

Source

pub fn resolve(&self) -> Result<HostId, Error>

Walk the chain and return the first successful identity.

§Errors

Returns Error::NoSource if every source returned Ok(None), or Error::Malformed if the selected Wrap is Wrap::Passthrough and the raw value is not a valid UUID. Other Error variants bubble up from the source that produced them (permission denied, sentinel value, platform-tool failure).

Source

pub fn resolve_all(&self) -> Vec<ResolveOutcome>

Walk the entire chain without short-circuiting and return one ResolveOutcome per source.

Complements Resolver::resolve: the chain, wrap strategy, and container-detection logic are identical — only the stopping behaviour differs. Every source is consulted exactly once, in chain order, and neither a success nor an error stops the walk.

Use this to audit what each source would produce — operator diagnostics, debugging, or test harnesses that want to confirm that several sources agree. For normal resolution use Resolver::resolve, which stops at the first usable source.

To run a caller-chosen subset of sources, build the resolver with exactly those sources — the same builder that feeds resolve():

use host_identity::Resolver;
use host_identity::sources::{MachineIdFile, DmiProductUuid};

let report = Resolver::new()
    .push(MachineIdFile::default())
    .push(DmiProductUuid::default())
    .resolve_all();
for outcome in report {
    println!("{:?} → {:?}", outcome.source(), outcome.host_id());
}

Trait Implementations§

Source§

impl Debug for Resolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Resolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.