ma_core/service.rs
1//! Service trait for ma endpoint protocol handlers.
2//!
3//! A `Service` is analogous to an entry in `/etc/services`: a named protocol
4//! on a ma endpoint. Register services on an `MaEndpoint` to handle incoming
5//! connections on their protocol.
6
7/// Trait that all ma services must implement.
8///
9/// Each service declares its protocol identifier and provides a handler for
10/// incoming connections. Built-in services ship with ma-core; applications
11/// add custom services via this trait.
12///
13/// # Examples
14///
15/// ```
16/// use ma_core::Service;
17///
18/// struct MyService;
19///
20/// impl Service for MyService {
21/// fn protocol(&self) -> &[u8] { b"ma/my-service/0.0.1" }
22/// fn label(&self) -> &str { "my-service" }
23/// }
24///
25/// let svc = MyService;
26/// assert_eq!(svc.label(), "my-service");
27/// ```
28pub trait Service: Send + Sync {
29 /// The protocol identifier for this service.
30 fn protocol(&self) -> &[u8];
31
32 /// Human-readable label for logging and diagnostics.
33 fn label(&self) -> &str;
34}
35
36// ─── Well-known protocol constants (ma-core scope) ──────────────────────────
37
38pub const INBOX_PROTOCOL: &[u8] = b"ma/inbox/0.0.1";
39pub const BROADCAST_PROTOCOL: &[u8] = b"ma/broadcast/0.0.1";
40pub const IPFS_PROTOCOL: &[u8] = b"ma/ipfs/0.0.1";
41
42pub const BROADCAST_TOPIC: &str = "ma/broadcast/0.0.1";
43
44// ─── Content types ──────────────────────────────────────────────────────────
45
46pub const DEFAULT_CONTENT_TYPE: &str = "application/x-ma";
47pub const CONTENT_TYPE_CHAT: &str = "application/x-ma-chat";
48pub const CONTENT_TYPE_PRESENCE: &str = "application/x-ma-presence";
49pub const CONTENT_TYPE_WORLD: &str = "application/x-ma-world";
50pub const CONTENT_TYPE_EVENT: &str = "application/x-ma-event";
51pub const CONTENT_TYPE_BROADCAST: &str = "application/x-ma-broadcast";
52pub const CONTENT_TYPE_WHISPER: &str = "application/x-ma-whisper";
53pub const CONTENT_TYPE_MESSAGE: &str = "application/x-ma-message";