1use std::{
2 fmt::Debug,
3 ops::{Deref, DerefMut},
4};
5
6#[cfg(feature = "external")]
7pub use zbus::zvariant;
8
9mod fungible;
10mod local;
11#[cfg(feature = "external")]
12mod shared;
13
14pub use fungible::*;
15pub use local::*;
16#[cfg(feature = "external")]
17pub use shared::*;
18
19#[derive(Debug)]
20pub struct MemoryAllocationError(pub(crate) String);
21
22impl std::fmt::Display for MemoryAllocationError {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 f.write_str(&self.0)
25 }
26}
27
28impl std::error::Error for MemoryAllocationError {}
29
30pub trait ByteData: Sized + Deref<Target = [u8]> + DerefMut + Debug + 'static {
31 fn new(size: u64) -> std::io::Result<Self>;
32 fn into_fungible(self) -> FungibleMemory;
33 fn into_other<O: ByteData>(self) -> Result<O, MemoryAllocationError>;
34 #[cfg(feature = "external")]
35 fn from_shared(shared: SharedMemory) -> Self;
36 fn try_from_vec(vec: Vec<u8>) -> Result<Self, MemoryAllocationError>;
37 fn try_from_slice(slice: &[u8]) -> Result<Self, MemoryAllocationError>;
38 fn initial_seal(
39 &mut self,
40 ) -> impl std::future::Future<Output = Result<(), MemoryAllocationError>> + Send;
41 fn final_seal(
42 &mut self,
43 ) -> impl std::future::Future<Output = Result<(), MemoryAllocationError>> + Send;
44 #[cfg(feature = "glib")]
45 fn into_gbytes(self) -> Result<glib::Bytes, MemoryAllocationError>;
46}