pub trait LimitedCollectionExt<T> {
// Required methods
fn try_push_limited(&mut self, item: T, limit: usize) -> bool;
fn is_at_limit(&self, limit: usize) -> bool;
fn remaining_capacity(&self, limit: usize) -> usize;
}Expand description
Extension trait for collections with size limits
Provides methods for safely adding items to collections while respecting
configured limits, which is essential for DoS protection.
§Examples
use feedparser_rs::types::LimitedCollectionExt;
let mut vec = Vec::new();
assert!(vec.try_push_limited("first", 2));
assert!(vec.try_push_limited("second", 2));
assert!(!vec.try_push_limited("third", 2)); // Exceeds limit
assert_eq!(vec.len(), 2);Required Methods§
Sourcefn try_push_limited(&mut self, item: T, limit: usize) -> bool
fn try_push_limited(&mut self, item: T, limit: usize) -> bool
Try to push an item if the collection is below the limit
Returns true if the item was added, false if limit was reached.
Sourcefn is_at_limit(&self, limit: usize) -> bool
fn is_at_limit(&self, limit: usize) -> bool
Check if the collection has reached its limit
Sourcefn remaining_capacity(&self, limit: usize) -> usize
fn remaining_capacity(&self, limit: usize) -> usize
Get remaining capacity before reaching the limit