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.
if self.is_some() && other.is_some() {
panic!("Can't merge two `Option`s that are both `Some`")
}
assert!(
self.is_none() || other.is_none(),
"Can't merge two `Option`s that are both `Some`"
);
self.xor(other)
}

View File

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

View File

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

View File

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

View File

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