use crate::{ComponentsInner, Error};
use super::Component;
#[doc = include_str!("../../docs/snippets/component.md")]
pub struct Components {
pub(crate) inner: ComponentsInner,
}
impl_collection_method!(Components, Component, inner, list, list_mut);
impl Components {
pub fn new() -> Result<Self, Error> {
Ok(Self {
inner: ComponentsInner::new()?,
})
}
impl_new_with_refreshed_list!(Components, true);
pub fn refresh(&mut self, remove_not_listed_components: bool) {
self.inner.refresh();
if remove_not_listed_components {
self.inner.components.retain_mut(|c| {
if !c.inner.updated {
return false;
}
c.inner.updated = false;
true
});
} else {
for c in self.inner.components.iter_mut() {
c.inner.updated = false;
}
}
}
}