rogue_machines 0.1.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  //! The experiments a process is running.
2
2
 
3
- use crate::{Armed, EXPERIMENTS, Experiment, Fault, PER_MILLION, Slot};
3
+ use core::time::Duration;
4
+
5
+ use crate::{Draw, EXPERIMENTS, Experiment, Fault, Slot};
4
6
 
5
7
  /// What to do with one call.
6
8
  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -11,28 +13,61 @@ pub enum Decision {
11
13
  Inject(Fault),
12
14
  }
13
15
 
16
+ /// What an honoured [`Rogue::arm`] did.
17
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
18
+ pub enum Arming {
19
+ /// The slot was empty and now holds the experiment.
20
+ Armed,
21
+ /// The slot held this other experiment, which the new one replaced.
22
+ Replaced(Experiment),
23
+ /// The slot already holds exactly this experiment. Nothing changed.
24
+ AlreadyArmed,
25
+ }
26
+
27
+ /// What a [`Rogue::disarm`] did.
28
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
29
+ pub enum Disarming {
30
+ /// The slot held this experiment and is now empty.
31
+ Disarmed(Experiment),
32
+ /// The slot was already empty. Nothing changed.
33
+ NotArmed,
34
+ }
35
+
14
36
  /// A slot table and the mask over it.
15
37
  ///
38
+ /// A slot is *armed* while it holds an experiment, and that experiment is
39
+ /// *live* at an instant before its expiry. Expiry is never applied behind the
40
+ /// caller's back: [`active`](Self::active), [`decide`](Self::decide) and
41
+ /// [`live_count`](Self::live_count) judge it against the instant they are
42
+ /// given and change nothing, and only [`sweep`](Self::sweep) empties the slots
43
+ /// of experiments that have expired.
44
+ ///
16
45
  /// ```
17
- /// use rogue_machines::{Decision, Experiment, Fault, Fraction, Rogue, Slot};
46
+ /// use core::time::Duration;
47
+ /// use rogue_machines::{Arming, Decision, Draw, Experiment, Fault, Fraction, Rogue, Slot};
18
48
  ///
19
- /// const SECOND: u64 = 1_000_000_000;
20
49
  /// let Some(slot) = Slot::new(0) else { unreachable!() };
50
+ /// let Some(draw) = Draw::new(0) else { unreachable!() };
51
+ /// let second = Duration::from_secs(1);
21
52
  /// let mut rogue = Rogue::new();
22
53
  ///
23
54
  /// // Disarmed, which is where every process starts.
24
- /// assert_eq!(rogue.decide(slot, 0, 0), Decision::Pass);
55
+ /// assert_eq!(rogue.decide(slot, Duration::ZERO, draw), Decision::Pass);
25
56
  ///
26
- /// rogue.arm(slot, Experiment::new(Fault::Raise, Fraction::ALL, 5 * SECOND));
27
- /// assert_eq!(rogue.decide(slot, SECOND, 0), Decision::Inject(Fault::Raise));
57
+ /// let experiment = Experiment::new(Fault::Raise, Fraction::ALL, 5 * second);
58
+ /// assert_eq!(rogue.arm(slot, experiment), Arming::Armed);
59
+ /// assert_eq!(rogue.decide(slot, second, draw), Decision::Inject(Fault::Raise));
28
60
  ///
29
- /// // Past its expiry it disarms itself, and stays disarmed.
30
- /// assert_eq!(rogue.decide(slot, 5 * SECOND, 0), Decision::Pass);
61
+ /// // Past its expiry it injects nothing, and a sweep gives the slot back.
62
+ /// assert_eq!(rogue.decide(slot, 5 * second, draw), Decision::Pass);
63
+ /// assert!(rogue.any_armed());
64
+ /// assert_eq!(rogue.sweep(5 * second), 1);
31
65
  /// assert!(!rogue.any_armed());
32
66
  /// ```
33
- #[derive(Debug)]
67
+ #[derive(Debug, Clone, PartialEq, Eq)]
34
68
  pub struct Rogue {
35
- armed: Armed,
69
+ /// One bit per slot, set exactly while `experiments` holds one there.
70
+ armed: u32,
36
71
  experiments: [Option<Experiment>; EXPERIMENTS],
37
72
  }
38
73
 
@@ -43,92 +78,146 @@ impl Default for Rogue {
43
78
  }
44
79
 
45
80
  impl Rogue {
81
+ /// Nothing armed.
46
82
  #[must_use]
47
83
  pub const fn new() -> Self {
48
84
  Self {
49
- armed: Armed::new(),
85
+ armed: 0,
50
86
  experiments: [None; EXPERIMENTS],
51
87
  }
52
88
  }
53
89
 
54
- /// Arms `slot`, replacing whatever it held.
55
- pub fn arm(&mut self, slot: Slot, experiment: Experiment) {
56
- self.experiments[slot.index()] = Some(experiment);
57
- self.armed.hold(slot);
90
+ /// Arms `slot` with `experiment`, replacing whatever it held, expired or
91
+ /// not. Never refuses: the slot is the caller's to pick, and an
92
+ /// experiment already spent is armed and injects nothing.
93
+ ///
94
+ /// Arming the identical experiment again is an honoured repeat: the slot
95
+ /// already holds exactly that value, so [`Arming::AlreadyArmed`] is
96
+ /// provable and nothing changes.
97
+ pub fn arm(&mut self, slot: Slot, experiment: Experiment) -> Arming {
98
+ let held = self.held_mut(slot);
99
+ let arming = match *held {
100
+ None => Arming::Armed,
101
+ Some(previous) if previous == experiment => return Arming::AlreadyArmed,
102
+ Some(previous) => Arming::Replaced(previous),
103
+ };
104
+ *held = Some(experiment);
105
+ self.armed |= slot.bit();
106
+ arming
58
107
  }
59
108
 
60
- pub fn disarm(&mut self, slot: Slot) {
61
- self.experiments[slot.index()] = None;
62
- self.armed.release(slot);
109
+ /// Empties `slot`, whether or not what it held had expired. Never refuses.
110
+ pub const fn disarm(&mut self, slot: Slot) -> Disarming {
111
+ match self.held_mut(slot).take() {
112
+ Some(experiment) => {
113
+ self.armed &= !slot.bit();
114
+ Disarming::Disarmed(experiment)
115
+ }
116
+ None => Disarming::NotArmed,
117
+ }
63
118
  }
64
119
 
65
- pub fn disarm_all(&mut self) {
120
+ /// Empties every slot and answers how many held an experiment, expired or
121
+ /// not. Never refuses; zero means nothing was armed and nothing changed.
122
+ pub const fn disarm_all(&mut self) -> u32 {
123
+ let held = self.armed.count_ones();
66
124
  self.experiments = [None; EXPERIMENTS];
67
- self.armed.release_all();
125
+ self.armed = 0;
126
+ held
127
+ }
128
+
129
+ /// Empties every slot whose experiment has expired by `now` and answers
130
+ /// how many. Never refuses; zero means nothing changed.
131
+ ///
132
+ /// The only call that applies an expiry. Without it an expired experiment
133
+ /// injects nothing but keeps its slot, and keeps
134
+ /// [`any_armed`](Self::any_armed) answering `true`.
135
+ pub fn sweep(&mut self, now: Duration) -> u32 {
136
+ let mut retired = 0;
137
+ for (index, held) in self.experiments.iter_mut().enumerate() {
138
+ if held.is_some_and(|experiment| experiment.spent(now)) {
139
+ *held = None;
140
+ self.armed &= !(1_u32 << index);
141
+ // At most `EXPERIMENTS`.
142
+ retired += 1;
143
+ }
144
+ }
145
+ retired
68
146
  }
69
147
 
70
- /// Whether any experiment is armed as of the last [`sweep`](Self::sweep),
71
- /// which is the only read a call runs when none is.
148
+ /// Whether any slot holds an experiment, expired or not: the one word a
149
+ /// call reads when nothing is armed. `false` means every decision passes.
72
150
  #[must_use]
73
- pub fn any_armed(&self) -> bool {
74
- self.armed.any()
151
+ pub const fn any_armed(&self) -> bool {
152
+ self.armed != 0
75
153
  }
76
154
 
77
- /// How many experiments are armed as of the last [`sweep`](Self::sweep).
155
+ /// How many slots hold an experiment, expired or not.
78
156
  #[must_use]
79
- pub fn armed_count(&self) -> u32 {
80
- self.armed.count()
157
+ pub const fn armed_count(&self) -> u32 {
158
+ self.armed.count_ones()
81
159
  }
82
160
 
83
- /// Releases every slot whose experiment has expired by `now_ns`.
84
- ///
85
- /// [`any_armed`](Self::any_armed) is a bare mask read, so without this an
86
- /// experiment that expired on a slot nothing decides on again would hold
87
- /// the gate open for the life of the process. Both readers below sweep
88
- /// first, so the next call of either restores the disarmed fast path.
89
- pub fn sweep(&self, now_ns: u64) {
90
- if !self.armed.any() {
91
- return;
92
- }
93
- for index in 0..EXPERIMENTS {
94
- let Some(slot) = Slot::new(index) else {
95
- continue;
96
- };
97
- if self.armed.holds(slot) && self.spent(slot, now_ns) {
98
- self.armed.release(slot);
161
+ /// How many slots hold an experiment that is live at `now`.
162
+ #[must_use]
163
+ pub fn live_count(&self, now: Duration) -> u32 {
164
+ let mut live = 0;
165
+ for experiment in self.experiments.iter().flatten() {
166
+ if !experiment.spent(now) {
167
+ // At most `EXPERIMENTS`.
168
+ live += 1;
99
169
  }
100
170
  }
171
+ live
101
172
  }
102
173
 
103
- /// The experiment arming `slot` at `now_ns`.
174
+ /// The lowest slot holding nothing, or `None` when every slot is armed.
104
175
  #[must_use]
105
- pub fn active(&self, slot: Slot, now_ns: u64) -> Option<&Experiment> {
106
- self.sweep(now_ns);
107
- if !self.armed.holds(slot) {
108
- return None;
109
- }
110
- self.experiments[slot.index()].as_ref()
176
+ pub const fn vacant(&self) -> Option<Slot> {
177
+ Slot::new(self.armed.trailing_ones() as usize)
178
+ }
179
+
180
+ /// The experiment `slot` holds, expired or not.
181
+ #[must_use]
182
+ pub const fn experiment(&self, slot: Slot) -> Option<Experiment> {
183
+ self.held(slot)
184
+ }
185
+
186
+ /// The experiment `slot` holds, if it is live at `now`.
187
+ #[must_use]
188
+ pub fn active(&self, slot: Slot, now: Duration) -> Option<Experiment> {
189
+ self.held(slot).filter(|experiment| !experiment.spent(now))
190
+ }
191
+
192
+ /// The entry `slot` names.
193
+ #[expect(
194
+ clippy::indexing_slicing,
195
+ reason = "a `Slot` is below `EXPERIMENTS` by construction, the table's length"
196
+ )]
197
+ const fn held(&self, slot: Slot) -> Option<Experiment> {
198
+ self.experiments[slot.index()]
111
199
  }
112
200
 
113
- /// What to do with one call: retires anything expired by `now_ns`, then
114
- /// injects if `slot` is armed and `draw`, which is below
115
- /// [`PER_MILLION`](crate::PER_MILLION), falls in the share it covers.
201
+ /// The entry `slot` names, to change.
202
+ #[expect(
203
+ clippy::indexing_slicing,
204
+ reason = "a `Slot` is below `EXPERIMENTS` by construction, the table's length"
205
+ )]
206
+ const fn held_mut(&mut self, slot: Slot) -> &mut Option<Experiment> {
207
+ &mut self.experiments[slot.index()]
208
+ }
209
+
210
+ /// What to do with one call: inject when `slot` holds an experiment that
211
+ /// is live at `now` and `draw` falls in the share it covers.
116
212
  #[must_use]
117
- pub fn decide(&self, slot: Slot, now_ns: u64, draw: u32) -> Decision {
118
- debug_assert!(draw < PER_MILLION, "a draw must be below PER_MILLION");
119
- match self.active(slot, now_ns) {
213
+ pub fn decide(&self, slot: Slot, now: Duration, draw: Draw) -> Decision {
214
+ match self.active(slot, now) {
120
215
  Some(experiment) if experiment.fraction.covers(draw) => {
121
216
  Decision::Inject(experiment.fault)
122
217
  }
123
- _ => Decision::Pass,
218
+ Some(_) | None => Decision::Pass,
124
219
  }
125
220
  }
126
-
127
- /// Whether `slot` holds nothing, or holds something already expired. An
128
- /// empty slot counts as spent so a bit can never outlive its experiment.
129
- fn spent(&self, slot: Slot, now_ns: u64) -> bool {
130
- self.experiments[slot.index()].is_none_or(|experiment| experiment.spent(now_ns))
131
- }
132
221
  }
133
222
 
134
223
  #[cfg(test)]
@@ -0,0 +1,34 @@
1
+ //! Which experiment a call is asking about.
2
+
3
+ use crate::EXPERIMENTS;
4
+
5
+ /// A slot index a [`Rogue`](crate::Rogue) can hold. The caller picks it; the
6
+ /// core issues none.
7
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8
+ pub struct Slot(usize);
9
+
10
+ impl Slot {
11
+ /// Rejects an index at or above [`EXPERIMENTS`].
12
+ #[must_use]
13
+ pub const fn new(index: usize) -> Option<Self> {
14
+ if index < EXPERIMENTS {
15
+ Some(Self(index))
16
+ } else {
17
+ None
18
+ }
19
+ }
20
+
21
+ /// The index this slot was built from.
22
+ #[must_use]
23
+ pub const fn index(self) -> usize {
24
+ self.0
25
+ }
26
+
27
+ /// This slot's bit in the armed mask.
28
+ pub(crate) const fn bit(self) -> u32 {
29
+ 1_u32 << self.0
30
+ }
31
+ }
32
+
33
+ #[cfg(test)]
34
+ mod tests;
@@ -0,0 +1,27 @@
1
+ //! Fixtures the unit tests share.
2
+
3
+ use core::time::Duration;
4
+
5
+ use crate::{Draw, Experiment, Fault, Fraction, Slot};
6
+
7
+ /// An instant `nanoseconds` after the epoch.
8
+ pub const fn at(nanoseconds: u64) -> Duration {
9
+ Duration::from_nanos(nanoseconds)
10
+ }
11
+
12
+ pub fn slot(index: usize) -> Slot {
13
+ Slot::new(index).expect("the index is inside the mask")
14
+ }
15
+
16
+ pub fn fraction(millionths: u32) -> Fraction {
17
+ Fraction::new(millionths).expect("the share is a whole at most")
18
+ }
19
+
20
+ pub fn draw(millionths: u32) -> Draw {
21
+ Draw::new(millionths).expect("the draw is below a whole")
22
+ }
23
+
24
+ /// Raises on every call until `expires_at`.
25
+ pub const fn raising(expires_at: Duration) -> Experiment {
26
+ Experiment::new(Fault::Raise, Fraction::ALL, expires_at)
27
+ }
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rogue_machines_native"
3
- version = "0.1.1"
3
+ version = "0.1.5"
4
4
  edition.workspace = true
5
5
  rust-version.workspace = true
6
6
  authors = ["Abdelkader Boudih <oss@seuros.com>"]
@@ -15,17 +15,13 @@ crate-type = ["cdylib"]
15
15
  workspace = true
16
16
 
17
17
  [dependencies]
18
- rogue-machines = { workspace = true, features = ["std"] }
19
- magnus = { version = ">= 0.9.3", default-features = false, features = ["io"] }
20
- # Nothing here calls rb-sys directly: this is the compiled fallback that
21
- # implements the stable API for a Ruby rb-sys has no pre-generated bindings
22
- # for, such as a preview. magnus asks for "stable-api" without it, and
23
- # default-features = false drops the default that would have supplied it, so
24
- # removing this line breaks the build on every future Ruby.
18
+ rogue-machines = { workspace = true }
19
+ magnus = { version = "0.9.3", default-features = false, features = ["io"] }
20
+ matryona-machines = { workspace = true, features = ["ruby"] }
25
21
  # Nothing here calls rb-sys directly: this is the compiled fallback that
26
22
  # implements the stable API for a Ruby rb-sys ships no pre-generated bindings
27
23
  # for, such as a preview. magnus asks for "stable-api" without it, and its
28
24
  # default-features = false drops the default that would have supplied it, so
29
25
  # dropping this line breaks the build on every Ruby newer than rb-sys.
30
- rb-sys = { version = ">= 0.9.130", default-features = false, features = ["stable-api-compiled-fallback"] }
26
+ rb-sys = { version = "0.9.130", default-features = false, features = ["stable-api-compiled-fallback"] }
31
27
 
@@ -0,0 +1,15 @@
1
+ //! Private native entry point.
2
+ use magnus::{Error, Ruby, prelude::*};
3
+ use rogue_machines::PER_MILLION;
4
+
5
+ use crate::{define_errors, rogue, values};
6
+
7
+ #[magnus::init]
8
+ fn init(ruby: &Ruby) -> Result<(), Error> {
9
+ let module = ruby.define_module("RogueMachines")?;
10
+ module.const_set("PER_MILLION", PER_MILLION)?;
11
+ module.const_set("EXPERIMENTS", rogue_machines::EXPERIMENTS)?;
12
+ define_errors(ruby, module)?;
13
+ values::define(ruby, module)?;
14
+ rogue::define(ruby, module)
15
+ }
@@ -1,173 +1,19 @@
1
1
  //! Ruby bindings for the `rogue-machines` fault injector.
2
2
  //!
3
- //! The core decides; this layer names the experiments and converts seconds to
4
- //! the nanoseconds the core counts in. The clock and the draw come from the
5
- //! caller, so `RogueMachines.clock` and `RogueMachines.random` are swappable
6
- //! and an experiment replays exactly.
3
+ //! A plain mirror of the core: `RogueMachines::Rogue` wraps one `Rogue`, and
4
+ //! the `Data` values `Slot`, `Fraction`, `Draw`, `Delay`, `Experiment`,
5
+ //! `Inject`, `Replaced` and `Disarmed` (defined in Ruby, validated here) carry
6
+ //! the core's types. Time is Integer nanoseconds in and out. The process-wide
7
+ //! runtime (`RogueMachines.arm`, `RogueMachines.run`) is Ruby, on top of this.
7
8
 
8
- #![allow(clippy::needless_pass_by_value)]
9
+ mod init;
10
+ mod rogue;
11
+ mod values;
9
12
 
10
- mod injection;
11
- mod registry;
13
+ use magnus::{Error, RModule, Ruby, prelude::*};
12
14
 
13
- use std::sync::OnceLock;
14
-
15
- use magnus::value::Opaque;
16
- use magnus::{Error, ExceptionClass, Integer, RModule, Ruby, Value, prelude::*};
17
- use rogue_machines::{Fraction, PER_MILLION};
18
-
19
- static ERROR: OnceLock<Opaque<ExceptionClass>> = OnceLock::new();
20
- static INJECTED: OnceLock<Opaque<ExceptionClass>> = OnceLock::new();
21
-
22
- /// Nanoseconds in a second.
23
- pub(crate) const NS_PER_SECOND: u32 = 1_000_000_000;
24
-
25
- /// Longest an experiment may run for. An experiment is something a person is
26
- /// waiting on, so a day is already generous; past that it is configuration,
27
- /// and it must be re-armed deliberately.
28
- pub(crate) const LONGEST_EXPERIMENT: f64 = 24.0 * 60.0 * 60.0;
29
-
30
- /// Longest a single delay may wait. Bounds how long a stall can hold a caller
31
- /// that has no deadline of its own.
32
- pub(crate) const LONGEST_DELAY: f64 = 5.0 * 60.0;
33
-
34
- /// Seconds as nanoseconds, rejecting a duration no experiment should run for.
35
- ///
36
- /// An unbounded duration is not merely untidy: `as u64` saturates rather than
37
- /// wrapping, so without `longest` a large `delay` becomes a stall of centuries.
38
- #[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
39
- pub(crate) fn duration(ruby: &Ruby, name: &str, seconds: f64, longest: f64) -> Result<u64, Error> {
40
- if !seconds.is_finite() || seconds <= 0.0 || seconds > longest {
41
- return Err(Error::new(
42
- ruby.exception_arg_error(),
43
- format!("{name} must be above 0 and at most {longest} seconds, got {seconds}"),
44
- ));
45
- }
46
- let nanoseconds = seconds * f64::from(NS_PER_SECOND);
47
- if nanoseconds < 1.0 {
48
- return Err(Error::new(
49
- ruby.exception_arg_error(),
50
- format!("{name} of {seconds} is below the one nanosecond resolution"),
51
- ));
52
- }
53
- Ok(nanoseconds.round() as u64)
54
- }
55
-
56
- /// A reading in nanoseconds.
57
- ///
58
- /// A Float is refused rather than truncated, and so is a value outside the
59
- /// range: magnus would reject that with its own `RangeError`, which would
60
- /// leak out of a protected call site as something the gem never documents.
61
- pub(crate) fn reading(ruby: &Ruby, name: &str, value: Value) -> Result<u64, Error> {
62
- whole(ruby, name, value)?.to_u64().map_err(|_| {
63
- Error::new(
64
- ruby.exception_arg_error(),
65
- format!(
66
- "{name} must be a non-negative Integer of at most {}",
67
- u64::MAX
68
- ),
69
- )
70
- })
71
- }
72
-
73
- /// A draw below [`PER_MILLION`].
74
- ///
75
- /// A truncated draw becomes 0, which every share covers, so a caller whose
76
- /// `rand` returns a Float would inject on every call instead of none.
77
- pub(crate) fn draw(ruby: &Ruby, value: Value) -> Result<u32, Error> {
78
- let drawn = whole(ruby, "draw", value)?.to_u32().map_err(|_| {
79
- Error::new(
80
- ruby.exception_arg_error(),
81
- format!("draw must be a non-negative Integer below {PER_MILLION}"),
82
- )
83
- })?;
84
- if drawn >= PER_MILLION {
85
- return Err(Error::new(
86
- ruby.exception_arg_error(),
87
- format!("draw must be below {PER_MILLION}, got {drawn}"),
88
- ));
89
- }
90
- Ok(drawn)
91
- }
92
-
93
- /// A generation tag.
94
- pub(crate) fn counted(ruby: &Ruby, name: &str, value: Value) -> Result<u32, Error> {
95
- whole(ruby, name, value)?.to_u32().map_err(|_| {
96
- Error::new(
97
- ruby.exception_arg_error(),
98
- format!(
99
- "{name} must be a non-negative Integer of at most {}",
100
- u32::MAX
101
- ),
102
- )
103
- })
104
- }
105
-
106
- fn whole(ruby: &Ruby, name: &str, value: Value) -> Result<Integer, Error> {
107
- Integer::from_value(value).ok_or_else(|| {
108
- Error::new(
109
- ruby.exception_arg_error(),
110
- format!("{name} must be an Integer"),
111
- )
112
- })
113
- }
114
-
115
- /// A share of calls, rejecting one outside a whole or too small to express.
116
- #[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
117
- pub(crate) fn share(ruby: &Ruby, given: f64) -> Result<Fraction, Error> {
118
- if !given.is_finite() || !(0.0..=1.0).contains(&given) {
119
- return Err(Error::new(
120
- ruby.exception_arg_error(),
121
- format!("share must be between 0 and 1, got {given}"),
122
- ));
123
- }
124
- let millionths = given * f64::from(PER_MILLION);
125
- if given > 0.0 && millionths < 1.0 {
126
- return Err(Error::new(
127
- ruby.exception_arg_error(),
128
- format!("share of {given} is below the one millionth resolution"),
129
- ));
130
- }
131
- let millionths = millionths.round() as u32;
132
- Fraction::new(millionths).ok_or_else(|| {
133
- Error::new(
134
- ruby.exception_arg_error(),
135
- format!("share of {millionths} millionths is not a whole"),
136
- )
137
- })
138
- }
139
-
140
- pub(crate) fn error(ruby: &Ruby, message: String) -> Error {
141
- ERROR.get().map_or_else(
142
- || {
143
- Error::new(
144
- ruby.exception_runtime_error(),
145
- "RogueMachines was not initialised",
146
- )
147
- },
148
- |class| Error::new(ruby.get_inner(*class), message),
149
- )
150
- }
151
-
152
- fn define_errors(ruby: &Ruby, module: RModule) -> Result<(), Error> {
15
+ pub(crate) fn define_errors(ruby: &Ruby, module: RModule) -> Result<(), Error> {
153
16
  let base = module.define_error("Error", ruby.exception_standard_error())?;
154
- ERROR
155
- .set(base.into())
156
- .map_err(|_| error(ruby, "Error was defined twice".to_owned()))?;
157
-
158
- let injected = module.define_error("Injected", base)?;
159
- INJECTED
160
- .set(injected.into())
161
- .map_err(|_| error(ruby, "Injected was defined twice".to_owned()))
162
- }
163
-
164
- #[magnus::init]
165
- fn init(ruby: &Ruby) -> Result<(), Error> {
166
- let module = ruby.define_module("RogueMachines")?;
167
- module.const_set("NS_PER_SECOND", NS_PER_SECOND)?;
168
- module.const_set("PER_MILLION", PER_MILLION)?;
169
- module.const_set("EXPERIMENTS", rogue_machines::EXPERIMENTS)?;
170
- define_errors(ruby, module)?;
171
- injection::define(ruby, module)?;
172
- registry::define(ruby, module)
17
+ module.define_error("Injected", base)?;
18
+ Ok(())
173
19
  }