Skip to main content

apple_quant_algorithmic/volume/
fast.rs

1use std::ops::{Deref, DerefMut};
2
3#[repr(u32)]
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum Interpretation {
6	Whole,
7	Decimal { multiplier: u32 },
8}
9
10#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub struct FastVolume(i64);
12
13impl FastVolume {
14	pub fn as_whole_i64(
15		self,
16	) -> i64 {
17		self.0
18	}
19
20	pub fn as_interpreted_f64(
21		self,
22		interpretation: Interpretation,
23	) -> f64 {
24		match interpretation {
25			Interpretation::Whole => self.0 as f64,
26			Interpretation::Decimal {
27				multiplier,
28			} => self.0 as f64 * multiplier as f64,
29		}
30	}
31}
32
33impl Deref for FastVolume {
34	type Target = i64;
35
36	fn deref(
37		&self,
38	) -> &Self::Target {
39		&self.0
40	}
41}
42
43impl DerefMut for FastVolume {
44	fn deref_mut(
45		&mut self,
46	) -> &mut Self::Target {
47		&mut self.0
48	}
49}