Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GitHub

This documentation is part of the "Projects with Books" initiative at zenOSmosis.

The source code for this project is available on GitHub.

Workspace Structure

Loading…

Workspace Structure

Relevant source files

Purpose and Scope

This document details the Cargo workspace organization of the rust-muxio repository. It catalogs all workspace member crates, their locations in the directory tree, their roles within the overall system architecture, and their dependency relationships. For information about the design philosophy and layered architecture principles, see Design Philosophy and Layered Architecture.


Workspace Overview

The rust-muxio repository is organized as a Cargo workspace containing 11 member crates. The workspace is configured with resolver version 2 and defines shared metadata (version, authors, license, repository) inherited by all member crates.

Sources:

graph TB
    subgraph "Root Directory"
        ROOT["muxio (Root Crate)"]
end
    
    subgraph "extensions/"
        EXT_TEST["muxio-ext-test"]
RPC_SERVICE["muxio-rpc-service"]
RPC_CALLER["muxio-rpc-service-caller"]
RPC_ENDPOINT["muxio-rpc-service-endpoint"]
TOKIO_SERVER["muxio-tokio-rpc-server"]
TOKIO_CLIENT["muxio-tokio-rpc-client"]
WASM_CLIENT["muxio-wasm-rpc-client"]
end
    
    subgraph "examples/"
        EXAMPLE_APP["example-muxio-ws-rpc-app"]
EXAMPLE_DEF["example-muxio-rpc-service-definition"]
end
    
 
   ROOT -->|extends| RPC_SERVICE
 
   RPC_SERVICE -->|extends| RPC_CALLER
 
   RPC_SERVICE -->|extends| RPC_ENDPOINT
 
   RPC_CALLER -->|implements| TOKIO_CLIENT
 
   RPC_CALLER -->|implements| WASM_CLIENT
 
   RPC_ENDPOINT -->|implements| TOKIO_SERVER
 
   EXAMPLE_DEF -->|uses| RPC_SERVICE
 
   EXAMPLE_APP -->|demonstrates| EXAMPLE_DEF

Workspace Member Listing

The workspace members are declared in the root Cargo.toml and organized into three categories:

Crate NameDirectory PathCategoryPrimary Purpose
muxio.CoreBinary framing protocol and stream multiplexing
muxio-rpc-serviceextensions/muxio-rpc-serviceRPC FrameworkService trait definitions and method ID generation
muxio-rpc-service-callerextensions/muxio-rpc-service-callerRPC FrameworkClient-side RPC invocation interface
muxio-rpc-service-endpointextensions/muxio-rpc-service-endpointRPC FrameworkServer-side handler registration and dispatch
muxio-tokio-rpc-serverextensions/muxio-tokio-rpc-serverPlatform ExtensionTokio-based WebSocket RPC server
muxio-tokio-rpc-clientextensions/muxio-tokio-rpc-clientPlatform ExtensionTokio-based WebSocket RPC client
muxio-wasm-rpc-clientextensions/muxio-wasm-rpc-clientPlatform ExtensionWASM browser-based RPC client
muxio-ext-testextensions/muxio-ext-testTestingIntegration test suite
example-muxio-rpc-service-definitionexamples/example-muxio-rpc-service-definitionExampleShared service definition for examples
example-muxio-ws-rpc-appexamples/example-muxio-ws-rpc-appExampleDemonstration application

Sources:


Core Library: muxio

The root crate muxio (located at repository root .) provides the foundational binary framing protocol and stream multiplexing primitives. This crate is runtime-agnostic and has minimal dependencies.

Key Components:

  • RpcDispatcher - Request correlation and response routing
  • RpcSession - Stream multiplexing and per-stream decoders
  • RpcStreamEncoder / RpcStreamDecoder - Frame encoding/decoding
  • RpcRequest / RpcResponse / RpcHeader - Core message types

Direct Dependencies:

  • bitcode - Binary serialization
  • chrono - Timestamp generation
  • once_cell - Lazy static initialization
  • tracing - Structured logging

Dev Dependencies:

  • rand - Random data generation for tests
  • tokio - Async runtime for tests

Sources:


RPC Framework Extensions

muxio-rpc-service

Located at extensions/muxio-rpc-service, this crate provides trait definitions for RPC services and compile-time method ID generation.

Key Exports:

  • RpcMethodPrebuffered trait - Defines prebuffered RPC method signatures
  • DynamicChannelReceiver / DynamicChannelSender - Channel abstractions for streaming
  • Method ID constants via xxhash-rust

Dependencies:

  • muxio - Core framing and session management
  • bitcode - Parameter/response serialization
  • xxhash-rust - Compile-time method ID generation
  • num_enum - Message type discrimination
  • async-trait - Async trait support
  • futures - Channel and stream utilities

Sources:

muxio-rpc-service-caller

Located at extensions/muxio-rpc-service-caller, this crate defines the RpcServiceCallerInterface trait for platform-agnostic client-side RPC invocation.

Key Exports:

  • RpcServiceCallerInterface trait - Abstract client interface
  • Helper functions for invoking prebuffered and streaming methods

Dependencies:

  • muxio - Core session and dispatcher
  • muxio-rpc-service - Service definitions
  • async-trait - Trait async support
  • futures - Future combinators
  • tracing - Instrumentation

Sources:

muxio-rpc-service-endpoint

Located at extensions/muxio-rpc-service-endpoint, this crate defines the RpcServiceEndpointInterface trait for platform-agnostic server-side handler registration and request processing.

Key Exports:

  • RpcServiceEndpointInterface trait - Abstract server interface
  • Handler registration and dispatch utilities

Dependencies:

  • muxio - Core dispatcher and session
  • muxio-rpc-service - Service trait definitions
  • muxio-rpc-service-caller - For bidirectional RPC (server-to-client calls)
  • bitcode - Request/response deserialization
  • async-trait - Trait async support
  • futures - Channel management

Sources:


Platform-Specific Extensions

muxio-tokio-rpc-server

Located at extensions/muxio-tokio-rpc-server, this crate provides a Tokio-based WebSocket RPC server implementation using Axum and tokio-tungstenite.

Key Exports:

  • RpcServer struct - Main server implementation
  • Axum WebSocket handler integration
  • Connection lifecycle management

Dependencies:

  • muxio - Core session primitives
  • muxio-rpc-service - Service definitions
  • muxio-rpc-service-caller - For bidirectional communication
  • muxio-rpc-service-endpoint - Server endpoint interface
  • axum - HTTP/WebSocket framework
  • tokio - Async runtime
  • tokio-tungstenite - WebSocket transport
  • bytes - Byte buffer utilities
  • futures-util - Stream combinators
  • async-trait - Async trait implementations

Sources:

muxio-tokio-rpc-client

Located at extensions/muxio-tokio-rpc-client, this crate provides a Tokio-based WebSocket RPC client with Arc-based lifecycle management and background task coordination.

Key Exports:

  • RpcClient struct - Main client implementation
  • Connection state tracking with RpcClientConnectionState
  • Arc-based shared ownership model

Dependencies:

  • muxio - Core dispatcher and session
  • muxio-rpc-service - Service definitions
  • muxio-rpc-service-caller - Client interface implementation
  • muxio-rpc-service-endpoint - For bidirectional communication
  • axum - (Used for shared types)
  • tokio - Async runtime
  • tokio-tungstenite - WebSocket transport
  • bytes - Byte buffer utilities
  • futures / futures-util - Async combinators
  • async-trait - Trait async support

Sources:

muxio-wasm-rpc-client

Located at extensions/muxio-wasm-rpc-client, this crate provides a WASM-compatible RPC client for browser environments using wasm-bindgen and JavaScript interop.

Key Exports:

  • RpcWasmClient struct - WASM client implementation
  • MUXIO_STATIC_RPC_CLIENT_REF - Thread-local static client reference
  • JavaScript bridge functions (static_muxio_write_bytes, etc.)

Dependencies:

  • muxio - Core framing and session
  • muxio-rpc-service - Service definitions
  • muxio-rpc-service-caller - Client interface
  • muxio-rpc-service-endpoint - For bidirectional communication
  • wasm-bindgen - JavaScript FFI
  • js-sys - JavaScript API bindings
  • wasm-bindgen-futures - Async/await in WASM
  • futures / futures-util - Future utilities
  • async-trait - Trait support

Sources:


Testing Infrastructure

muxio-ext-test

Located at extensions/muxio-ext-test, this integration test crate validates end-to-end functionality across client and server implementations.

Test Coverage:

  • Native client to native server communication
  • Service definition validation
  • Error handling and edge cases

Dependencies:

  • muxio-rpc-service - Service trait testing
  • muxio-rpc-service-caller - Client interface testing
  • muxio-rpc-service-endpoint - Server endpoint testing
  • muxio-tokio-rpc-client - Client implementation testing
  • muxio-tokio-rpc-server - Server implementation testing
  • example-muxio-rpc-service-definition - Test service definitions
  • tokio - Async test runtime
  • tracing / tracing-subscriber - Test instrumentation
  • bytemuck - Binary data utilities

Sources:


Example Applications

example-muxio-rpc-service-definition

Located at examples/example-muxio-rpc-service-definition, this crate defines shared RPC service contracts used across example applications.

Service Definitions:

  • Basic arithmetic operations (Add, Multiply)
  • Echo service
  • Demonstrates RpcMethodPrebuffered trait implementation

Dependencies:

  • muxio-rpc-service - Service trait definitions
  • bitcode - Serialization for parameters and responses

Sources:

example-muxio-ws-rpc-app

Located at examples/example-muxio-ws-rpc-app, this demonstration application shows complete client-server setup with WebSocket transport.

Demonstrates:

  • Server instantiation with RpcServer
  • Client connection with RpcClient
  • Service handler registration
  • RPC method invocation
  • Benchmarking with criterion

Dependencies:

  • example-muxio-rpc-service-definition - Shared service contracts
  • muxio - Core primitives
  • muxio-rpc-service-caller - Client calling
  • muxio-tokio-rpc-client - Client implementation
  • muxio-tokio-rpc-server - Server implementation
  • tokio - Async runtime
  • async-trait - Handler trait implementation
  • criterion - Performance benchmarking
  • futures - Async utilities
  • tracing / tracing-subscriber - Application logging
  • doc-comment - Documentation tests

Sources:


Workspace Dependency Graph

Sources:


Directory Structure to Code Entity Mapping

Sources:


Shared Workspace Configuration

All workspace member crates inherit common metadata from the workspace-level configuration:

PropertyValuePurpose
version0.10.0-alphaSynchronized versioning across all crates
edition2024Rust edition (preview edition)
authorsJeremy HarrisPackage authorship
repositoryhttps://github.com/jzombie/rust-muxioSource location
licenseApache-2.0Licensing terms
publishtruecrates.io publication enabled
resolver2Cargo feature resolver version

Workspace-wide Third-Party Dependencies:

The workspace defines shared third-party dependency versions to ensure consistency:

DependencyVersionUsed By
async-trait0.1.88RPC service traits
axum0.8.4Server framework
bitcode0.6.6Serialization
tokio1.45.1Async runtime
tokio-tungstenite0.26.2WebSocket transport
tracing0.1.41Logging infrastructure
tracing-subscriber0.3.20Log output formatting
xxhash-rust0.8.15Method ID hashing
num_enum0.7.3Enum discriminants
futures0.3.31Async utilities

Sources:


Crate Size and Complexity Metrics

Based on Cargo.lock dependency counts:

CrateDirect DependenciesPurpose Complexity
muxio5Low - Core primitives only
muxio-rpc-service6Medium - Trait definitions and hashing
muxio-rpc-service-caller5Low - Interface abstraction
muxio-rpc-service-endpoint6Low - Interface abstraction
muxio-tokio-rpc-server10High - Full server stack
muxio-tokio-rpc-client11High - Full client stack
muxio-wasm-rpc-client11High - WASM bridge complexity
muxio-ext-test8Medium - Integration testing
example-muxio-rpc-service-definition2Low - Simple definitions
example-muxio-ws-rpc-app9Medium - Demonstration code

Sources: