Skip to main content

selium_abi/
singleton.rs

1//! Singleton dependency identifiers and hostcall payloads.
2
3use rkyv::{Archive, Deserialize, Serialize};
4
5use crate::GuestResourceId;
6
7/// Stable identifier for a singleton dependency.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Archive, Serialize, Deserialize)]
9#[rkyv(bytecheck())]
10pub struct DependencyId(pub [u8; 16]);
11
12impl DependencyId {
13    /// Return the raw byte representation of the identifier.
14    pub const fn bytes(self) -> [u8; 16] {
15        self.0
16    }
17}
18
19/// Payload used to register a singleton dependency in the host registry.
20#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
21#[rkyv(bytecheck())]
22pub struct SingletonRegister {
23    /// Dependency identifier.
24    pub id: DependencyId,
25    /// Shared handle to the resource that should back this singleton.
26    pub resource: GuestResourceId,
27}
28
29/// Payload used to look up a singleton dependency from the host registry.
30#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
31#[rkyv(bytecheck())]
32pub struct SingletonLookup {
33    /// Dependency identifier.
34    pub id: DependencyId,
35}