LimitedCollectionExt

Trait LimitedCollectionExt 

Source
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§

Source

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.

Source

fn is_at_limit(&self, limit: usize) -> bool

Check if the collection has reached its limit

Source

fn remaining_capacity(&self, limit: usize) -> usize

Get remaining capacity before reaching the limit

Implementations on Foreign Types§

Source§

impl<T> LimitedCollectionExt<T> for Vec<T>

Source§

fn try_push_limited(&mut self, item: T, limit: usize) -> bool

Source§

fn is_at_limit(&self, limit: usize) -> bool

Source§

fn remaining_capacity(&self, limit: usize) -> usize

Implementors§