pub struct DynamicPool { /* private fields */ }Expand description
Interns unique strings and assigns each a u16 index. Index 0 is reserved as null.
Implementations§
Source§impl DynamicPool
impl DynamicPool
pub fn new() -> Self
Sourcepub fn intern(&mut self, s: &str) -> u16
pub fn intern(&mut self, s: &str) -> u16
Interns a string and returns its index.
§Examples
use state_engine::common::pool::DynamicPool;
let mut pool = DynamicPool::new();
let i0 = pool.intern("foo");
let i1 = pool.intern("bar");
// same string returns same index
assert_eq!(pool.intern("foo"), i0);
assert_ne!(i0, i1);
// index 0 is reserved as null
assert_ne!(i0, 0);Sourcepub fn get(&self, index: u16) -> Option<&str>
pub fn get(&self, index: u16) -> Option<&str>
Returns the string at the given index, or None if out of range.
§Examples
use state_engine::common::pool::DynamicPool;
let mut pool = DynamicPool::new();
let i0 = pool.intern("foo");
assert_eq!(pool.get(i0), Some("foo"));
assert_eq!(pool.get(0), Some("")); // null slot
assert_eq!(pool.get(999), None);Trait Implementations§
Auto Trait Implementations§
impl Freeze for DynamicPool
impl RefUnwindSafe for DynamicPool
impl Send for DynamicPool
impl Sync for DynamicPool
impl Unpin for DynamicPool
impl UnsafeUnpin for DynamicPool
impl UnwindSafe for DynamicPool
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
Mutably borrows from an owned value. Read more