use std::{
sync::mpsc::Receiver,
cell::Cell
};
pub struct Bottle<W>(Receiver<W>, Cell<bool>);
impl<W> Bottle<W> {
pub(crate) fn new(water: Receiver<W>) -> Bottle<W> {
Bottle(water, Cell::new(false))
}
pub fn open(&self) -> W {
if self.1.get() {
panic!("Tried to open an already opened bottle");
} else {
self.1.set(true);
}
self.0
.recv()
.expect("Tried to open a Poisoned bottle")
}
}
impl<T> Drop for Bottle<T> {
fn drop(&mut self) {
assert!(self.1.get(), "Bottle dropped without ever being opened *Shatters*");
}
}