Skip to main content

Bucket

Struct Bucket 

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

Source

pub fn new(content: T) -> Self

Creates new instance of the Bucket and takes ownership of the content.

Source

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

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());
Source

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;
}
Source

pub fn fill(&self, content: T) -> Option<T>

This function is used to fill the “bucket” with a desired value.
If “bucket” is already filled, it returns provided value.

use bucket::Bucket;

let bucket = Bucket::default();
bucket.fill(5);
assert_eq!(bucket.fill(6), Some(6));
Source

pub fn is_empty(&self) -> bool

Checks if the “bucket” is empty (zeroed).

Trait Implementations§

Source§

impl<T> Default for Bucket<T>

Creates an empty instance of a “bucket”.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for Bucket<T>

After dropping the “bucket”, deallocates previously allocated memory for the content.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.