1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::marker::PhantomData;
use super::{Geometry, LegacyTransducer, NormalTransducer};
pub struct Normal;
pub struct Legacy;
pub struct GeometryBuilder<M> {
attenuation: f64,
sound_speed: f64,
_mode: PhantomData<M>,
}
impl<M> GeometryBuilder<M> {
pub fn attenuation(mut self, attenuation: f64) -> Self {
self.attenuation = attenuation;
self
}
pub fn sound_speed(mut self, sound_speed: f64) -> Self {
self.sound_speed = sound_speed;
self
}
}
impl GeometryBuilder<Normal> {
pub fn new() -> Self {
Self {
attenuation: 0.0,
sound_speed: 340.0,
_mode: PhantomData,
}
}
pub fn legacy_mode(self) -> GeometryBuilder<Legacy> {
unsafe { std::mem::transmute(self) }
}
pub fn build(self) -> Geometry<NormalTransducer> {
Geometry::<NormalTransducer>::new(self.attenuation, self.sound_speed)
}
}
impl GeometryBuilder<Legacy> {
pub fn normal_mode(self) -> GeometryBuilder<Normal> {
unsafe { std::mem::transmute(self) }
}
pub fn build(self) -> Geometry<LegacyTransducer> {
Geometry::<LegacyTransducer>::new(self.attenuation, self.sound_speed)
}
}
impl Default for GeometryBuilder<Normal> {
fn default() -> Self {
Self::new()
}
}