### Manage Pooled Values with Lifeguard Source: https://github.com/zslayton/lifeguard/blob/master/README.md Demonstrates basic pool usage where values are automatically returned to the pool when they go out of scope. ```rust extern crate lifeguard; use lifeguard::*; fn main() { let pool : Pool = pool().with(StartingSize(10)).build(); { let string = pool.new_from("Hello, World!"); // Remove a value from the pool assert_eq!(9, pool.size()); } // Values that have gone out of scope are automatically moved back into the pool. assert_eq!(10, pool.size()); } ``` -------------------------------- ### Configure Pool with Builder API Source: https://github.com/zslayton/lifeguard/blob/master/README.md Uses the builder pattern to customize pool size, growth limits, and object supply logic. ```rust extern crate lifeguard; use lifeguard::*; fn main() { let pool : Pool = pool() // The pool will allocate 128 values for immediate use. More will be allocated on demand. .with(StartingSize(128)) // The pool will only grow up to 4096 values. Further values will be dropped. .with(MaxSize(4096)) // The pool will use this closure (or other object implementing Supply) to allocate .with(Supplier(|| String::with_capacity(1024))) .build(); // ... } ``` -------------------------------- ### Manually Attach Values to the Pool Source: https://github.com/zslayton/lifeguard/blob/master/README.md Demonstrates how to manually return a detached value to the pool. ```rust extern crate lifeguard; use lifeguard::*; fn main() { let pool : Pool = pool().with(StartingSize(10)).build(); { let string : String = pool.detached(); // An unwrapped String, detached from the Pool assert_eq!(9, pool.size()); let rstring : Recycled = pool.attach(string); // The String is attached to the pool again assert_eq!(9, pool.size()); // but it is still checked out from the pool } // rstring goes out of scope and is added back to the pool assert_eq!(10, pool.size()); } ``` -------------------------------- ### Access and Mutate Pooled Values Source: https://github.com/zslayton/lifeguard/blob/master/README.md Shows how to dereference pooled values to access or mutate their contents. ```rust extern crate lifeguard; use lifeguard::*; fn main() { let pool : Pool = pool().with(StartingSize(10)).build(); let mut string = pool.new_from("cat"); string.push_str("s love eating mice"); //string.as_mut() also works assert_eq!("cats love eating mice", *string); } ``` -------------------------------- ### Detach Values from the Pool Source: https://github.com/zslayton/lifeguard/blob/master/README.md Illustrates how to unwrap a value from the pool, preventing it from being returned automatically. ```rust extern crate lifeguard; use lifeguard::*; fn main() { let pool : Pool = pool().with(StartingSize(10)).build(); { let string : String = pool.new().detach(); } // The String goes out of scope and is dropped; it is not returned to the pool assert_eq!(9, pool.size()); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.