cros_async/
async_types.rs1use std::io;
6
7use base::RecvTube;
8use base::SendTube;
9use base::Tube;
10use base::TubeResult;
11use serde::de::DeserializeOwned;
12use serde::Serialize;
13
14pub use crate::sys::async_types::*;
15use crate::Executor;
16use crate::IntoAsync;
17
18impl IntoAsync for Tube {}
28impl IntoAsync for SendTube {}
29impl IntoAsync for RecvTube {}
30
31pub struct RecvTubeAsync(AsyncTube);
32#[allow(dead_code)]
33impl RecvTubeAsync {
34 pub fn new(tube: RecvTube, ex: &Executor) -> io::Result<Self> {
35 Ok(Self(AsyncTube::new(
36 ex,
37 #[allow(deprecated)]
38 tube.into_tube(),
39 )?))
40 }
41
42 pub async fn next<T: 'static + DeserializeOwned + Send>(&self) -> TubeResult<T> {
46 self.0.next().await
47 }
48}
49
50pub struct SendTubeAsync(AsyncTube);
51#[allow(dead_code)]
52impl SendTubeAsync {
53 pub fn new(tube: SendTube, ex: &Executor) -> io::Result<Self> {
54 Ok(Self(AsyncTube::new(
55 ex,
56 #[allow(deprecated)]
57 tube.into_tube(),
58 )?))
59 }
60
61 pub async fn send<T: 'static + Serialize + Send + Sync>(&self, msg: T) -> TubeResult<()> {
62 self.0.send(msg).await
63 }
64}