-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
29 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,60 @@ | ||
#[allow(unused_imports)] | ||
use super::*; | ||
|
||
use crate::SwarmBuilder; | ||
use std::marker::PhantomData; | ||
/// Represents the phase where a provider is not yet specified. | ||
/// This is a marker type used in the type-state pattern to ensure compile-time checks of the builder's state. | ||
pub enum NoProviderSpecified {} | ||
|
||
// Define enums for each of the possible runtime environments. These are used as markers in the type-state pattern, | ||
// allowing compile-time checks for the appropriate environment configuration. | ||
|
||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))] | ||
/// Represents the AsyncStd runtime environment. | ||
pub enum AsyncStd {} | ||
|
||
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))] | ||
/// Represents the Tokio runtime environment. | ||
pub enum Tokio {} | ||
|
||
#[cfg(feature = "wasm-bindgen")] | ||
/// Represents the WasmBindgen environment for WebAssembly. | ||
pub enum WasmBindgen {} | ||
|
||
/// Represents a phase in the SwarmBuilder where a provider has been chosen but not yet specified. | ||
pub struct ProviderPhase {} | ||
|
||
impl SwarmBuilder<NoProviderSpecified, ProviderPhase> { | ||
/// Configures the SwarmBuilder to use the AsyncStd runtime. | ||
/// This method is only available when compiling for non-Wasm targets with the `async-std` feature enabled. | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))] | ||
pub fn with_async_std(self) -> SwarmBuilder<AsyncStd, TcpPhase> { | ||
SwarmBuilder { | ||
keypair: self.keypair, | ||
phantom: std::marker::PhantomData, | ||
phantom: PhantomData, | ||
phase: TcpPhase {}, | ||
} | ||
} | ||
|
||
/// Configures the SwarmBuilder to use the Tokio runtime. | ||
/// This method is only available when compiling for non-Wasm targets with the `tokio` feature enabled | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))] | ||
pub fn with_tokio(self) -> SwarmBuilder<Tokio, TcpPhase> { | ||
SwarmBuilder { | ||
keypair: self.keypair, | ||
phantom: std::marker::PhantomData, | ||
phantom: PhantomData, | ||
phase: TcpPhase {}, | ||
} | ||
} | ||
|
||
/// Configures the SwarmBuilder for WebAssembly using WasmBindgen. | ||
/// This method is available when the `wasm-bindgen` feature is enabled. | ||
#[cfg(feature = "wasm-bindgen")] | ||
pub fn with_wasm_bindgen(self) -> SwarmBuilder<WasmBindgen, TcpPhase> { | ||
SwarmBuilder { | ||
keypair: self.keypair, | ||
phantom: std::marker::PhantomData, | ||
phantom: PhantomData, | ||
phase: TcpPhase {}, | ||
} | ||
} | ||
} | ||
|
||
pub enum NoProviderSpecified {} | ||
|
||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))] | ||
pub enum AsyncStd {} | ||
|
||
#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))] | ||
pub enum Tokio {} | ||
|
||
#[cfg(feature = "wasm-bindgen")] | ||
pub enum WasmBindgen {} |