Skip to content

Commit

Permalink
[unstable-rust] Use feature(try_blocks).
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Dec 14, 2024
1 parent 0619ac7 commit 482ccfb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions all-is-cubes-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![move_size_limit = "256"]
#![feature(let_chains)]
#![feature(never_type)]
#![feature(try_blocks)]

//! This library is an internal component of [`all-is-cubes`],
//! which defines some core mathematical types and functions.
Expand Down
19 changes: 10 additions & 9 deletions all-is-cubes-base/src/math/grid_aab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,19 @@ impl GridAab {
) -> Result<Self, GridOverflowError> {
#[inline]
fn inner(lower_bounds: GridPoint, size: GridSize) -> Result<GridAab, GridOverflowError> {
let upper_bounds = (|| {
Some(GridPoint::new(
match try {
GridPoint::new(
lower_bounds.x.checked_add_unsigned(size.width)?,
lower_bounds.y.checked_add_unsigned(size.height)?,
lower_bounds.z.checked_add_unsigned(size.depth)?,
))
})()
.ok_or(GridOverflowError(OverflowKind::OverflowedSize {
lower_bounds,
size,
}))?;
GridAab::checked_from_lower_upper(lower_bounds, upper_bounds)
)
} {
Some(upper_bounds) => GridAab::checked_from_lower_upper(lower_bounds, upper_bounds),
None => Err(GridOverflowError(OverflowKind::OverflowedSize {
lower_bounds,
size,
})),
}
}

inner(lower_bounds.into(), size.into())
Expand Down
8 changes: 4 additions & 4 deletions all-is-cubes/src/block/eval/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ impl Cost {

/// Compute a cost from change in budget.
pub(crate) fn from_difference(original_budget: Budget, final_budget: Budget) -> Self {
let Some(new_self) = (|| {
Some(Self {
let Some(new_self) = (try {
Self {
components: original_budget
.components
.checked_sub(final_budget.components)?,
voxels: original_budget.voxels.checked_sub(final_budget.voxels)?,
recursion: original_budget
.recursion_used
.checked_sub(final_budget.recursion_used)?,
})
})() else {
}
}) else {
panic!("overflow computing budget difference: {final_budget:#?} - {original_budget:#?}")
};
new_self
Expand Down
1 change: 1 addition & 0 deletions all-is-cubes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![feature(let_chains)]
#![feature(never_type)]
#![feature(trait_upcasting)]
#![feature(try_blocks)]

//! All is Cubes is a game/engine for worlds made of cubical blocks, where the blocks
//! are themselves made of “smaller” blocks (voxels) that define their appearance and
Expand Down

0 comments on commit 482ccfb

Please sign in to comment.