Skip to main content

HostsView

Struct HostsView 

Source
pub struct HostsView<'a> { /* private fields */ }
Expand description

A view over the hosts collection in an inventory that applies transform functions on access.

This struct provides a read-only view of the hosts stored in an Inventory. When accessing individual hosts through this view, any configured transform function is automatically applied. The view caches transformed results to improve performance on subsequent accesses to the same host.

The view does not own the inventory data; it holds a reference to the parent Inventory and provides methods to iterate over hosts, look up hosts by name, and query collection metadata.

§Lifetime

  • 'a - The lifetime of the reference to the parent Inventory. The view cannot outlive the inventory it references.

§Examples

let mut hosts = Hosts::new();
hosts.add_host("router1", Host::builder().hostname("10.0.0.1").build());
let inventory = Inventory::builder().hosts(hosts).build();

let hosts_view = inventory.hosts();
assert_eq!(hosts_view.len(), 1);

if let Some(host) = hosts_view.get("router1") {
    assert_eq!(host.hostname(), Some("10.0.0.1"));
}

for (name, host) in hosts_view.iter() {
    println!("Host: {}", name);
}

Implementations§

Source§

impl<'a> HostsView<'a>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn keys(&self) -> impl Iterator<Item = &'a NatString>

Source

pub fn get(&self, name: &str) -> Option<Host>

Source

pub fn iter(&self) -> impl Iterator<Item = (&'a NatString, Host)>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for HostsView<'a>

§

impl<'a> !UnwindSafe for HostsView<'a>

§

impl<'a> Freeze for HostsView<'a>

§

impl<'a> Send for HostsView<'a>

§

impl<'a> Sync for HostsView<'a>

§

impl<'a> Unpin for HostsView<'a>

§

impl<'a> UnsafeUnpin for HostsView<'a>

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, 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.