pub struct Capped<T> { /* private fields */ }Expand description
A list that may have been truncated when it was produced, paired with the true count of items that existed at the source.
Exists so a truncated list can never be silently read as complete: items are
only reachable through Capped::items and the real count only through
Capped::total, so items().len() is never mistaken for “everything there
is”. Both OSV lists capped at crate::osv::ADVISORY_DISPLAY_CAP use it —
DependencyVulnerabilities::advisories and UpgradeStatus::CandidateVulnerable.
§Examples
use deps_core::osv::Capped;
let truncated = Capped::new(vec!["A1".to_string(), "A2".to_string()], 5);
assert_eq!(truncated.items().len(), 2);
assert_eq!(truncated.total(), 5);
assert!(!truncated.is_complete());
assert_eq!(truncated.remaining(), 3);
let complete = Capped::new(vec!["A1".to_string()], 1);
assert!(complete.is_complete());
assert_eq!(complete.remaining(), 0);Implementations§
Source§impl<T> Capped<T>
impl<T> Capped<T>
Sourcepub fn new(items: Vec<T>, total: usize) -> Self
pub fn new(items: Vec<T>, total: usize) -> Self
Pairs an already-truncated items list with the total the source
reported, which may exceed items.len().
Sourcepub fn items(&self) -> &[T]
pub fn items(&self) -> &[T]
The items actually retained — not necessarily all Self::total of them.
Sourcepub const fn total(&self) -> usize
pub const fn total(&self) -> usize
The count the source reported, independent of how many items were retained.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Whether Self::items holds everything the source reported.
Trait Implementations§
impl<T: Eq> Eq for Capped<T>
impl<T: PartialEq> StructuralPartialEq for Capped<T>
Auto Trait Implementations§
impl<T> Freeze for Capped<T>
impl<T> RefUnwindSafe for Capped<T>where
T: RefUnwindSafe,
impl<T> Send for Capped<T>where
T: Send,
impl<T> Sync for Capped<T>where
T: Sync,
impl<T> Unpin for Capped<T>where
T: Unpin,
impl<T> UnsafeUnpin for Capped<T>
impl<T> UnwindSafe for Capped<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.