noosphere_into/write/
target.rs1use anyhow::Result;
2use std::future::Future;
3use std::path::Path;
4
5use async_trait::async_trait;
6use tokio::io::AsyncRead;
7
8#[cfg(not(target_arch = "wasm32"))]
9pub trait WriteTargetConditionalSend: Send {}
10
11#[cfg(not(target_arch = "wasm32"))]
12pub trait WriteTargetConditionalSendSync: Send + Sync {}
13
14#[cfg(target_arch = "wasm32")]
15pub trait WriteTargetConditionalSend {}
16
17#[cfg(target_arch = "wasm32")]
18pub trait WriteTargetConditionalSendSync {}
19
20#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
23#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
24pub trait WriteTarget: Clone + WriteTargetConditionalSendSync {
25 async fn exists(&self, path: &Path) -> Result<bool>;
27
28 async fn write<R>(&self, path: &Path, contents: R) -> Result<()>
31 where
32 R: AsyncRead + Unpin + WriteTargetConditionalSend;
33
34 async fn symlink(&self, src: &Path, dst: &Path) -> Result<()>;
36
37 async fn spawn<F>(future: F) -> Result<()>
40 where
41 F: Future<Output = Result<()>> + WriteTargetConditionalSend + 'static;
42}
43
44impl<W> WriteTargetConditionalSendSync for W where W: WriteTarget {}
45
46#[cfg(not(target_arch = "wasm32"))]
47impl<S> WriteTargetConditionalSend for S where S: Send {}
48
49#[cfg(target_arch = "wasm32")]
50impl<S> WriteTargetConditionalSend for S {}