FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    ObjectPool

    struct · ferroui-base · v0.5.0

    struct ObjectPool<T>
    

    Provides a thread-safe object pool with size limits and object validation.

    View source

    Members

    DEFAULT_MAX_SIZE

    const DEFAULT_MAX_SIZE: i32
    

    The default of the maximum number of objects to keep in the pool.

    Source

    new

    fn new(factory: impl Fn() -> T + Send + Sync + 'static, validator: Option<Box<dyn Fn(&mut T) -> bool + Send + Sync>>, max_size: i32) -> Self
    

    Initializes a new instance of the pool.

    factory creates new instances. The optional validator cleans and validates an object before it returns to the pool; it returns false to discard the object. max_size is the maximum number of objects to keep in the pool.

    Panics when max_size is less than 1.

    Source

    rent

    fn rent(self: &Self) -> T
    

    Rents an object from the pool or creates a new one if the pool is empty.

    Source

    return_item

    fn return_item(self: &Self, item: T)
    

    Returns an object to the pool if it passes validation and the pool is not full.

    Callers must not return the same item more than once without an intervening rent. The pool does not detect duplicate returns. The pool also does nothing with the items it drops (when full or when the validator returns false) beyond dropping them; any cleanup belongs in the validator or in the caller.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • ClassDefaults
    • Borrow<T>
    • BorrowMut<T>
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ErasedDestructor
    • IntoEither

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.