Skip to main content

glycin_utils/
memory.rs

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