pub struct Bucket<T> { /* private fields */ }Expand description
Simple container that holds any value.
!WARNING!
If your value is zeroed, the “bucket” is considered empty.
This features probably won’t be revoked.
Implementations§
Source§impl<T> Bucket<T>
impl<T> Bucket<T>
Sourcepub fn new(content: T) -> Self
pub fn new(content: T) -> Self
Creates new instance of the Bucket and takes ownership of the content.
Sourcepub fn vacate(&self) -> Option<T>
pub fn vacate(&self) -> Option<T>
This function is used to empty the “bucket” and return the value that was inside.
If the “bucket” was empty, it returns variant None
use bucket::Bucket;
let bucket = Bucket::new("value");
assert!(bucket.vacate().is_some());
let bucket = Bucket::default();
assert!(bucket.vacate().is_none()); // Returns none, because our bucket is created without any contentSourcepub fn peek_ref(&self) -> Option<&T>
pub fn peek_ref(&self) -> Option<&T>
Returns a reference to the content value if the “bucket” is filled.
use bucket::Bucket;
let bucket = Bucket::new(5);
println!("{}", bucket.peek_ref());
assert!(bucket.vacate().is_some());Sourcepub fn peek_mut(&self) -> Option<&mut T>
pub fn peek_mut(&self) -> Option<&mut T>
Returns a mutable reference to the content value if the “bucket” is filled.
use bucket::Bucket;
let bucket = Bucket::new(vec![1, 2, 3]);
for number in bucket.peek_mut().unwrap() {
*number += 1;
}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Bucket<T>
impl<T> RefUnwindSafe for Bucket<T>where
T: RefUnwindSafe,
impl<T> !Send for Bucket<T>
impl<T> !Sync for Bucket<T>
impl<T> Unpin for Bucket<T>
impl<T> UnsafeUnpin for Bucket<T>
impl<T> UnwindSafe for Bucket<T>where
T: RefUnwindSafe,
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