diff --git a/examples/random-generation-protocol/src/lib.rs b/examples/random-generation-protocol/src/lib.rs index 7f1b125..2fa9166 100644 --- a/examples/random-generation-protocol/src/lib.rs +++ b/examples/random-generation-protocol/src/lib.rs @@ -184,7 +184,7 @@ mod tests { let n: u16 = 5; - let randomness = round_based::simulation::run_with_setup( + let randomness = round_based::sim::run_with_setup( core::iter::repeat_with(|| rng.fork()).take(n.into()), |i, party, rng| protocol_of_random_generation(party, i, n, rng), ) @@ -201,7 +201,7 @@ mod tests { let n: u16 = 5; - let randomness = round_based::simulation::async_env::run_with_setup( + let randomness = round_based::sim::async_env::run_with_setup( core::iter::repeat_with(|| rng.fork()).take(n.into()), |i, party, rng| protocol_of_random_generation(party, i, n, rng), ) diff --git a/round-based/CHANGELOG.md b/round-based/CHANGELOG.md index c7c69fc..6948e07 100644 --- a/round-based/CHANGELOG.md +++ b/round-based/CHANGELOG.md @@ -1,16 +1,17 @@ ## v0.4.0 * Improve ergonomics of protocol simulation, which is used for writing tests [#14] * Remove `dev` feature, it's replaced with `sim` and `sim-async` - * `round_based::Simulation` is renamed and moved to `round_based::simulation::async_env::Network` - * Other async simulated network related types are moved to `round_based::simulation::async_env` - * Added convenient `round_based::simulation::{run, run_with_setup}` which make simulation very ergonomic - * Simulation outputs `round_based::simulation::SimResult`, which has convenient most-common methods: + * `round_based::simulation` module is renamed into `round_based::sim` + * `round_based::simulation::Simulation` is renamed and moved to `round_based::sim::async_env::Network` + * Other async simulated network related types are moved to `round_based::sim::async_env` + * Added convenient `round_based::sim::{run, run_with_setup}` which make simulation very ergonomic + * Simulation outputs `round_based::sim::SimResult`, which has convenient most-common methods: * `.expect_ok()` that unwraps all results, and if any party returned an error, panics with a verbose error message * `.expect_eq()` that checks that all outputs are equally the same - * When `sim-async` feature is enabled, you can use `round_based::simulation::async_env::{run, run_with_setup, ...}`, - but typically you don't want to use it - * `round_based::simulation::SimulationSync` has been renamed to `round_based::simulation::Simulation` + * When `sim-async` feature is enabled, you can use `round_based::sim::async_env::{run, run_with_setup, ...}`, + but typically you don't want to use them + * `round_based::simulation::SimulationSync` has been renamed to `round_based::sim::Simulation` Migration guidelines: * Replace `dev` feature with `sim` diff --git a/round-based/src/lib.rs b/round-based/src/lib.rs index 06c9b34..01fc783 100644 --- a/round-based/src/lib.rs +++ b/round-based/src/lib.rs @@ -70,7 +70,7 @@ pub mod runtime; pub mod state_machine; #[cfg(feature = "sim")] -pub mod simulation; +pub mod sim; pub use self::delivery::*; #[doc(no_inline)] diff --git a/round-based/src/simulation/async_env.rs b/round-based/src/sim/async_env.rs similarity index 98% rename from round-based/src/simulation/async_env.rs rename to round-based/src/sim/async_env.rs index 6f28282..8bb43df 100644 --- a/round-based/src/simulation/async_env.rs +++ b/round-based/src/sim/async_env.rs @@ -49,7 +49,7 @@ //! //! let n = 3; //! -//! let output = round_based::simulation::async_env::run( +//! let output = round_based::sim::async_env::run( //! n, //! |i, party| protocol_of_random_generation(party, i, n), //! ) @@ -276,7 +276,7 @@ impl NextMessageId { /// /// let n = 3; /// -/// let output = round_based::simulation::async_env::run( +/// let output = round_based::sim::async_env::run( /// n, /// |i, party| protocol_of_random_generation(party, i, n), /// ) @@ -354,7 +354,7 @@ where /// /// let mut rng = rand_dev::DevRng::new(); /// let n = 3; -/// let output = round_based::simulation::async_env::run_with_setup( +/// let output = round_based::sim::async_env::run_with_setup( /// core::iter::repeat_with(|| rng.fork()).take(n.into()), /// |i, party, rng| protocol_of_random_generation(rng, party, i, n), /// ) diff --git a/round-based/src/simulation/mod.rs b/round-based/src/sim/mod.rs similarity index 97% rename from round-based/src/simulation/mod.rs rename to round-based/src/sim/mod.rs index 735c623..56aa794 100644 --- a/round-based/src/simulation/mod.rs +++ b/round-based/src/sim/mod.rs @@ -51,7 +51,7 @@ //! //! let n = 3; //! -//! let output = round_based::simulation::run( +//! let output = round_based::sim::run( //! n, //! |i, party| protocol_of_random_generation(party, i, n), //! ) @@ -187,6 +187,21 @@ impl SimResult { } } +impl IntoIterator for SimResult { + type Item = T; + type IntoIter = alloc::vec::IntoIter; + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl core::ops::Deref for SimResult { + type Target = [T]; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl From> for SimResult { fn from(list: Vec) -> Self { Self(list) @@ -472,7 +487,7 @@ impl MessagesQueue { /// /// let n = 3; /// -/// let output = round_based::simulation::run( +/// let output = round_based::sim::run( /// n, /// |i, party| protocol_of_random_generation(party, i, n), /// ) @@ -527,7 +542,7 @@ where /// /// let mut rng = rand_dev::DevRng::new(); /// let n = 3; -/// let output = round_based::simulation::run_with_setup( +/// let output = round_based::sim::run_with_setup( /// core::iter::repeat_with(|| rng.fork()).take(n.into()), /// |i, party, rng| protocol_of_random_generation(rng, party, i, n), /// ) @@ -560,7 +575,7 @@ where #[cfg(test)] mod tests { mod expect_eq { - use crate::simulation::SimResult; + use crate::sim::SimResult; #[test] fn all_eq() { @@ -590,7 +605,7 @@ mod tests { } mod expect_ok { - use crate::simulation::SimResult; + use crate::sim::SimResult; #[test] fn all_ok() { diff --git a/round-based/src/simulation/sim_sync.rs b/round-based/src/sim/sim_sync.rs similarity index 100% rename from round-based/src/simulation/sim_sync.rs rename to round-based/src/sim/sim_sync.rs