noosphere_core/context/content/
file.rs1use std::pin::Pin;
2
3use crate::data::{Did, Link, MemoIpld};
4use tokio::io::AsyncRead;
5
6#[cfg(not(target_arch = "wasm32"))]
8pub trait AsyncFileBody: AsyncRead + Unpin + Send {}
9
10#[cfg(not(target_arch = "wasm32"))]
11impl<S> AsyncFileBody for S where S: AsyncRead + Unpin + Send {}
12
13#[cfg(target_arch = "wasm32")]
14pub trait AsyncFileBody: AsyncRead + Unpin {}
16
17#[cfg(target_arch = "wasm32")]
18impl<S> AsyncFileBody for S where S: AsyncRead + Unpin {}
19
20pub struct SphereFile<C> {
22 pub sphere_identity: Did,
24 pub sphere_version: Link<MemoIpld>,
26 pub memo_version: Link<MemoIpld>,
28 pub memo: MemoIpld,
30 pub contents: C,
32}
33
34impl<C> SphereFile<C>
35where
36 C: AsyncFileBody + 'static,
37{
38 pub fn boxed(self) -> SphereFile<Pin<Box<dyn AsyncFileBody + 'static>>> {
41 SphereFile {
42 sphere_identity: self.sphere_identity,
43 sphere_version: self.sphere_version,
44 memo_version: self.memo_version,
45 memo: self.memo,
46 contents: Box::pin(self.contents),
47 }
48 }
49}