all platform traits implemented & dumb async runtime imports
This commit is contained in:
+12
-21
@@ -14,17 +14,6 @@ use std::time::Duration;
|
||||
// Trait Definitions
|
||||
// ============================================================================
|
||||
|
||||
/// Trait for spawn handles that can be stored and used to spawn tasks later.
|
||||
pub trait SpawnHandleInterface: Clone + 'static {
|
||||
/// Spawn an async task using this handle.
|
||||
fn spawn<F>(&self, future: F)
|
||||
where
|
||||
F: Future<Output = ()> + 'static;
|
||||
|
||||
/// Get a spawn handle for the current context.
|
||||
fn current() -> Self;
|
||||
}
|
||||
|
||||
pub trait AudioSystemInterface {
|
||||
type AudioPlayer: AudioPlayerInterface;
|
||||
}
|
||||
@@ -36,7 +25,6 @@ pub trait AudioPlayerInterface {}
|
||||
/// verification that all platforms implement the required functionality.
|
||||
pub trait PlatformInterface {
|
||||
type AudioSystem: AudioSystemInterface;
|
||||
type SpawnHandle: SpawnHandleInterface;
|
||||
|
||||
/// Initialize logging for the platform.
|
||||
fn init_logging();
|
||||
@@ -72,11 +60,6 @@ pub trait PlatformInterface {
|
||||
/// Save the default server URL.
|
||||
fn set_default_server(server: &str) -> Option<()>;
|
||||
|
||||
/// Spawn an async task.
|
||||
fn spawn<F>(future: F)
|
||||
where
|
||||
F: Future<Output = ()> + 'static;
|
||||
|
||||
/// Async sleep for the given duration.
|
||||
fn sleep(duration: Duration) -> impl Future<Output = ()>;
|
||||
}
|
||||
@@ -86,7 +69,7 @@ pub trait PlatformInterface {
|
||||
// ============================================================================
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
mod web;
|
||||
pub mod web;
|
||||
|
||||
#[cfg(any(feature = "desktop", feature = "mobile"))]
|
||||
mod connect;
|
||||
@@ -94,9 +77,9 @@ mod connect;
|
||||
mod native_audio;
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
mod desktop;
|
||||
pub mod desktop;
|
||||
#[cfg(feature = "mobile")]
|
||||
mod mobile;
|
||||
pub mod mobile;
|
||||
|
||||
// ============================================================================
|
||||
// Platform Type Alias
|
||||
@@ -113,7 +96,15 @@ pub type Platform = mobile::MobilePlatform;
|
||||
|
||||
pub type AudioSystem = <Platform as PlatformInterface>::AudioSystem;
|
||||
pub type AudioPlayer = <AudioSystem as AudioSystemInterface>::AudioPlayer;
|
||||
pub type SpawnHandle = <Platform as PlatformInterface>::SpawnHandle;
|
||||
|
||||
// ========================
|
||||
// Platform Async Runtime
|
||||
// ========================
|
||||
// Note: these can not be part of the Platform because they differ in Send requiremets
|
||||
#[cfg(all(any(feature = "desktop", feature = "mobile"), not(feature = "web")))]
|
||||
pub use native_audio::{spawn, SpawnHandle};
|
||||
#[cfg(feature = "web")]
|
||||
pub use web::{spawn, SpawnHandle};
|
||||
|
||||
/// Compile-time assertion that CurrentPlatform implements Platform.
|
||||
const _: () = {
|
||||
|
||||
Reference in New Issue
Block a user