mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-04 19:29:09 -07:00
global: snapshot
This commit is contained in:
@@ -42,6 +42,7 @@ mod semesterindex;
|
||||
mod stored_bool;
|
||||
mod stored_f32;
|
||||
mod stored_f64;
|
||||
mod stored_i16;
|
||||
mod stored_u16;
|
||||
mod stored_u32;
|
||||
mod stored_u64;
|
||||
@@ -103,6 +104,7 @@ pub use semesterindex::*;
|
||||
pub use stored_bool::*;
|
||||
pub use stored_f32::*;
|
||||
pub use stored_f64::*;
|
||||
pub use stored_i16::*;
|
||||
pub use stored_u8::*;
|
||||
pub use stored_u16::*;
|
||||
pub use stored_u32::*;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use core::panic;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
f32,
|
||||
ops::{Add, AddAssign, Div, Mul, Sub},
|
||||
};
|
||||
|
||||
@@ -26,6 +27,10 @@ use super::{Dollars, StoredF64};
|
||||
)]
|
||||
pub struct StoredF32(f32);
|
||||
|
||||
impl StoredF32 {
|
||||
pub const NAN: Self = StoredF32(f32::NAN);
|
||||
}
|
||||
|
||||
impl From<f32> for StoredF32 {
|
||||
fn from(value: f32) -> Self {
|
||||
Self(value)
|
||||
|
||||
105
crates/brk_structs/src/structs/stored_i16.rs
Normal file
105
crates/brk_structs/src/structs/stored_i16.rs
Normal file
@@ -0,0 +1,105 @@
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use serde::Serialize;
|
||||
use vecdb::{CheckedSub, Printable, StoredCompressed};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
Deref,
|
||||
Clone,
|
||||
Default,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
StoredCompressed,
|
||||
)]
|
||||
pub struct StoredI16(i16);
|
||||
|
||||
impl StoredI16 {
|
||||
pub const ZERO: Self = Self(0);
|
||||
|
||||
pub fn new(v: i16) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i16> for StoredI16 {
|
||||
fn from(value: i16) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for StoredI16 {
|
||||
fn from(value: usize) -> Self {
|
||||
if value > i16::MAX as usize {
|
||||
panic!("usize too big (value = {value})")
|
||||
}
|
||||
Self(value as i16)
|
||||
}
|
||||
}
|
||||
|
||||
impl CheckedSub<StoredI16> for StoredI16 {
|
||||
fn checked_sub(self, rhs: Self) -> Option<Self> {
|
||||
self.0.checked_sub(rhs.0).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for StoredI16 {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: usize) -> Self::Output {
|
||||
Self(self.0 / rhs as i16)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for StoredI16 {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for StoredI16 {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for StoredI16 {
|
||||
fn from(value: f64) -> Self {
|
||||
if value < 0.0 || value > i16::MAX as f64 {
|
||||
panic!()
|
||||
}
|
||||
Self(value as i16)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StoredI16> for f64 {
|
||||
fn from(value: StoredI16) -> Self {
|
||||
value.0 as f64
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StoredI16> for usize {
|
||||
fn from(value: StoredI16) -> Self {
|
||||
value.0 as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for StoredI16 {
|
||||
fn to_string() -> &'static str {
|
||||
"i16"
|
||||
}
|
||||
|
||||
fn to_possible_strings() -> &'static [&'static str] {
|
||||
&["i16"]
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use vecdb::{CheckedSub, Printable, StoredCompressed};
|
||||
use derive_deref::Deref;
|
||||
use serde::Serialize;
|
||||
use vecdb::{CheckedSub, Printable, StoredCompressed};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
use super::{
|
||||
@@ -33,8 +33,8 @@ pub struct StoredU16(u16);
|
||||
impl StoredU16 {
|
||||
pub const ZERO: Self = Self(0);
|
||||
|
||||
pub fn new(counter: u16) -> Self {
|
||||
Self(counter)
|
||||
pub fn new(v: u16) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user