use built-in 'assert'

This commit is contained in:
Daniel Eades 2022-12-05 20:02:47 +00:00 committed by Hanno Braun
parent 392a2d34ef
commit 844185baf5
5 changed files with 15 additions and 15 deletions

View File

@ -46,9 +46,10 @@ where
} }
// We know that `self != other`, or we wouldn't have made it here. // We know that `self != other`, or we wouldn't have made it here.
if self.is_some() && other.is_some() { assert!(
panic!("Can't merge two `Option`s that are both `Some`") self.is_none() || other.is_none(),
} "Can't merge two `Option`s that are both `Some`"
);
self.xor(other) self.xor(other)
} }

View File

@ -94,9 +94,7 @@ impl<T> Block<T> {
pub fn insert(&mut self, index: ObjectIndex, object: T) { pub fn insert(&mut self, index: ObjectIndex, object: T) {
let slot = &mut self.objects[index.0]; let slot = &mut self.objects[index.0];
if slot.is_some() { assert!(slot.is_none(), "Attempting to overwrite object in store");
panic!("Attempting to overwrite object in store")
}
*slot = Some(object); *slot = Some(object);
} }

View File

@ -21,9 +21,10 @@ impl<const D: usize> Line<D> {
origin: Point<D>, origin: Point<D>,
direction: Vector<D>, direction: Vector<D>,
) -> Self { ) -> Self {
if direction.magnitude() == Scalar::ZERO { assert!(
panic!("Can't construct `Line`. Direction is zero: {direction:?}"); direction.magnitude() != Scalar::ZERO,
} "Can't construct `Line`. Direction is zero: {direction:?}"
);
Self { origin, direction } Self { origin, direction }
} }

View File

@ -45,9 +45,10 @@ impl EventLoopHandler {
let event = events let event = events
.try_recv() .try_recv()
.map_err(|err| { .map_err(|err| {
if err.is_disconnected() { assert!(
panic!("Expected channel to never disconnect"); !err.is_disconnected(),
} "Expected channel to never disconnect"
);
}) })
.ok(); .ok();

View File

@ -9,7 +9,7 @@ pub fn find_version_in_str(s: &str) -> anyhow::Result<Option<semver::Version>> {
version.as_str(), version.as_str(),
); );
}) })
.filter_map(|m| { .find_map(|m| {
let version = semver::Version::parse(m.as_str()).ok(); let version = semver::Version::parse(m.as_str()).ok();
if version.is_some() { if version.is_some() {
@ -19,8 +19,7 @@ pub fn find_version_in_str(s: &str) -> anyhow::Result<Option<semver::Version>> {
} }
version version
}) });
.next();
Ok(version) Ok(version)
} }