mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
types: add helper for division + remainder
We frequently require these operations together when converting between bit and byte offsets, or similar purposes.
This commit is contained in:
parent
a174d627cd
commit
357ef46731
1 changed files with 23 additions and 1 deletions
24
src/types.rs
24
src/types.rs
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Index, IndexMut},
|
||||
ops::{Div, Index, IndexMut, Rem},
|
||||
};
|
||||
|
||||
use itertools::iproduct;
|
||||
|
@ -61,3 +61,25 @@ impl<T> IndexMut<ChunkCoords> for ChunkArray<T> {
|
|||
&mut self.0[index.z.0 as usize][index.x.0 as usize]
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DivRem<Rhs> {
|
||||
type DivOutput;
|
||||
type RemOutput;
|
||||
|
||||
fn div_rem(self, rhs: Rhs) -> (Self::DivOutput, Self::RemOutput);
|
||||
}
|
||||
|
||||
impl<Lhs, Rhs> DivRem<Rhs> for Lhs
|
||||
where
|
||||
Self: Div<Rhs>,
|
||||
Self: Rem<Rhs>,
|
||||
Self: Copy,
|
||||
Rhs: Copy,
|
||||
{
|
||||
type DivOutput = <Self as Div<Rhs>>::Output;
|
||||
type RemOutput = <Self as Rem<Rhs>>::Output;
|
||||
|
||||
fn div_rem(self, rhs: Rhs) -> (Self::DivOutput, Self::RemOutput) {
|
||||
(self / rhs, self % rhs)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue