Refactor the imp/gui bondary to use real traits #18

Merged
liamwarfield merged 8 commits from gui-platform-boundary-refactor into main 2026-02-18 04:53:41 +00:00
Owner

Summary

Introduces a trait-based platform abstraction layer that makes the boundary
between platform-specific and shared code explicit and compile-time verified.

The TLDR version of this new trait stuff works:

  1. Define a PlatformInterface trait.
  2. Each platform defines a zero-sized struct implementing the trait (ex WebPlatform).
  3. Create an ifdef'd type alias on those structs:
#[cfg(feature = "web")]
pub type Platform = web::WebPlatform;

#[cfg(all(feature = "desktop"))]
pub type Platform = desktop::DesktopPlatform;

#[cfg(all(feature = "mobile", not(feature = "web")))]
pub type Platform = mobile::MobilePlatform;
  1. Add a compile time assertion that Platform implements PlatformInterface.

Motivation

Previously, platform code used a mix of pub use re-exports and #[cfg] blocks
that made it difficult to understand what each platform must implement. The
new trait-based approach provides:

  • Clear documentation of the platform contract
  • Compile-time verification that all platforms implement required
    functionality
  • Ability to cargo check without feature flags (via stub platform)

Changes

New traits in imp/mod.rs:

  • PlatformInterface - logging, permissions, network, config, storage. Overall this the trait that platforms must satify to compile.
  • AudioSystemInterface - audio system initialization and recording
  • AudioPlayerInterface - opus audio playback

Type aliases:

  • Platform, AudioSystem, AudioPlayer resolve to the correct types based on
    feature flags

Call site updates:

  • Changed from imp::function() to Platform::function() syntax
  • Removed ImpRead/ImpWrite helper traits in favor of direct bounds

Testing

Manual testing reveals that Web and Desktop still work, I (Liam) have not tested the mobile version beyond compilation.

# Summary Introduces a trait-based platform abstraction layer that makes the boundary between platform-specific and shared code explicit and compile-time verified. The TLDR version of this new trait stuff works: 1. Define a `PlatformInterface` trait. 2. Each platform defines a zero-sized struct implementing the trait (ex `WebPlatform`). 3. Create an ifdef'd type alias on those structs: ```rust #[cfg(feature = "web")] pub type Platform = web::WebPlatform; #[cfg(all(feature = "desktop"))] pub type Platform = desktop::DesktopPlatform; #[cfg(all(feature = "mobile", not(feature = "web")))] pub type Platform = mobile::MobilePlatform; ``` 5. Add a compile time assertion that `Platform` implements `PlatformInterface`. # Motivation Previously, platform code used a mix of pub use re-exports and #[cfg] blocks that made it difficult to understand what each platform must implement. The new trait-based approach provides: - Clear documentation of the platform contract - Compile-time verification that all platforms implement required functionality - Ability to cargo check without feature flags (via stub platform) # Changes New traits in imp/mod.rs: - PlatformInterface - logging, permissions, network, config, storage. Overall this the trait that platforms must satify to compile. - AudioSystemInterface - audio system initialization and recording - AudioPlayerInterface - opus audio playback Type aliases: - Platform, AudioSystem, AudioPlayer resolve to the correct types based on feature flags Call site updates: - Changed from imp::function() to Platform::function() syntax - Removed ImpRead/ImpWrite helper traits in favor of direct bounds # Testing Manual testing reveals that Web and Desktop still work, I (Liam) have not tested the mobile version beyond compilation.
sam force-pushed gui-platform-boundary-refactor from 440c51735c to 4a8a4de252 2026-01-25 04:28:47 +00:00 Compare
liamwarfield requested changes 2026-01-25 17:07:02 +00:00
liamwarfield left a comment
Owner

We also need to add a description to this PR ;)

We also need to add a description to this PR ;)
@@ -1,12 +1,87 @@
use crate::app::Command;
Owner

Add a doc comment here for what this file is, here and elsewhere in imp

Add a doc comment here for what this file is, here and elsewhere in imp
Owner

I'm not sure if this is actually needed.

I'm not sure if this is actually needed.
@@ -7,3 +8,2 @@
pub use super::connect::*;
pub use super::native_audio::*;
// ============================================================================
Owner

Delete this bar

Delete this bar
liamwarfield marked this conversation as resolved
@@ -3,0 +15,4 @@
// Trait Definitions
// ============================================================================
pub trait AudioSystemInterface: Sized {
Owner

We need to add a doc comment for the overall trait here.

We need to add a doc comment for the overall trait here.
Owner

Done

Done
liamwarfield marked this conversation as resolved
liamwarfield force-pushed gui-platform-boundary-refactor from d668e9a513 to 3ca2ec2a06 2026-01-25 18:01:31 +00:00 Compare
liamwarfield force-pushed gui-platform-boundary-refactor from bc33cfd732 to b89907715b 2026-01-25 18:25:50 +00:00 Compare
liamwarfield force-pushed gui-platform-boundary-refactor from b89907715b to 5f3466546e 2026-02-18 04:31:35 +00:00 Compare
liamwarfield merged commit 9006a082b0 into main 2026-02-18 04:53:41 +00:00
liamwarfield deleted branch gui-platform-boundary-refactor 2026-02-18 04:53:42 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mumble/mumble-web2#18