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 parentInventory. 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§
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> 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
Mutably borrows from an owned value. Read more