beet_core 0.0.8

Core utilities and types for other beet crates
use crate::prelude::*;

#[extend::ext(name=MatcherOption)]
pub impl<T> Option<T> {
	/// Performs an assertion ensuring this value is a `Some(_)`.
	///
	/// ## Example
	///
	/// ```
	/// # use beet_core::prelude::*;
	/// Some(1).xpect_some();
	/// ```
	///
	/// ## Panics
	///
	/// Panics if the value is not `Some(_)`.
	#[track_caller]
	fn xpect_some(&self) -> &Self {
		match self {
			Some(_) => self,
			None => {
				panic_ext::panic_expected_received_display("Some", "None");
			}
		}
	}
	/// Performs an assertion ensuring this value is a `None`.
	///
	/// ## Example
	///
	/// ```
	/// # use beet_core::prelude::*;
	/// let v: Option<i32> = None;
	/// v.xpect_none();
	/// ```
	///
	/// ## Panics
	///
	/// Panics if the value is not `None`.
	#[track_caller]
	fn xpect_none(&self) -> &Self {
		match self {
			None => self,
			Some(_) => {
				panic_ext::panic_expected_received_display("None", "Some");
			}
		}
	}
}


#[cfg(test)]
mod test {
	use crate::prelude::*;

	#[test]
	fn option() {
		Some(true).xpect_some();
		(None::<bool>).xpect_none();
	}
}