Skip to main content

GroupsView

Struct GroupsView 

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

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

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

The view does not own the inventory data; it holds references to both the parent Inventory and the underlying Groups collection. It provides methods to iterate over groups, look up groups by name, and query collection metadata.

§Lifetime

  • 'a - The lifetime of the references to the parent Inventory and Groups collection. The view cannot outlive either the inventory or groups it references.

§Examples

let mut groups = Groups::new();
groups.add_group("core", Group::builder().platform("linux").build());
let inventory = Inventory::builder().groups(groups).build();

if let Some(groups_view) = inventory.groups() {
    assert_eq!(groups_view.len(), 1);

    if let Some(group) = groups_view.get("core") {
        assert_eq!(group.platform(), Some("linux"));
    }

    for (name, group) in groups_view.iter() {
        println!("Group: {}", name);
    }
}

Implementations§

Source§

impl<'a> GroupsView<'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<Group>

Source

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

Auto Trait Implementations§

§

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

§

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

§

impl<'a> Freeze for GroupsView<'a>

§

impl<'a> Send for GroupsView<'a>

§

impl<'a> Sync for GroupsView<'a>

§

impl<'a> Unpin for GroupsView<'a>

§

impl<'a> UnsafeUnpin for GroupsView<'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.