Skip to content

Commit 21b8e1a

Browse files
committed
async: Relayout use crate.
The first block uses the standard library. The second block uses the third party crates, and the third block uses this crate. Signed-off-by: wllenyj <[email protected]>
1 parent 041bf30 commit 21b8e1a

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

src/asynchronous/client.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6-
use nix::unistd::close;
76
use std::collections::HashMap;
87
use std::convert::TryInto;
98
use std::os::unix::io::RawFd;
109
use std::sync::{Arc, Mutex};
1110

12-
use crate::common::client_connect;
13-
use crate::error::{Error, Result};
14-
use crate::proto::{Code, Codec, GenMessage, Message, Request, Response, MESSAGE_TYPE_RESPONSE};
15-
16-
use crate::r#async::utils;
11+
use nix::unistd::close;
1712
use tokio::{
1813
self,
1914
io::split,
2015
sync::mpsc::{channel, Receiver, Sender},
2116
sync::Notify,
2217
};
2318

19+
use crate::common::client_connect;
20+
use crate::error::{Error, Result};
21+
use crate::proto::{Code, Codec, GenMessage, Message, Request, Response, MESSAGE_TYPE_RESPONSE};
22+
use crate::r#async::utils;
23+
2424
type RequestSender = Sender<(GenMessage, Sender<Result<Vec<u8>>>)>;
2525
type RequestReceiver = Receiver<(GenMessage, Sender<Result<Vec<u8>>>)>;
2626

src/asynchronous/server.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,18 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6-
use crate::r#async::utils;
7-
use nix::unistd;
86
use std::collections::HashMap;
7+
use std::marker::Unpin;
98
use std::os::unix::io::RawFd;
9+
use std::os::unix::io::{AsRawFd, FromRawFd};
10+
use std::os::unix::net::UnixListener as SysUnixListener;
1011
use std::result::Result as StdResult;
1112
use std::sync::Arc;
1213
use std::time::Duration;
1314

14-
use crate::asynchronous::stream::{receive, respond, respond_with_status};
15-
use crate::asynchronous::unix_incoming::UnixIncoming;
16-
use crate::common::{self, Domain};
17-
use crate::context;
18-
use crate::error::{get_status, Error, Result};
19-
use crate::proto::{Code, MessageHeader, Status, MESSAGE_TYPE_REQUEST};
20-
use crate::r#async::{MethodHandler, TtrpcContext};
2115
use futures::stream::Stream;
2216
use futures::StreamExt as _;
23-
use std::marker::Unpin;
24-
use std::os::unix::io::{AsRawFd, FromRawFd};
25-
use std::os::unix::net::UnixListener as SysUnixListener;
17+
use nix::unistd;
2618
use tokio::{
2719
self,
2820
io::{split, AsyncRead, AsyncWrite, AsyncWriteExt},
@@ -32,10 +24,18 @@ use tokio::{
3224
sync::watch,
3325
time::timeout,
3426
};
35-
3627
#[cfg(target_os = "linux")]
3728
use tokio_vsock::VsockListener;
3829

30+
use crate::asynchronous::stream::{receive, respond, respond_with_status};
31+
use crate::asynchronous::unix_incoming::UnixIncoming;
32+
use crate::common::{self, Domain};
33+
use crate::context;
34+
use crate::error::{get_status, Error, Result};
35+
use crate::proto::{Code, MessageHeader, Status, MESSAGE_TYPE_REQUEST};
36+
use crate::r#async::utils;
37+
use crate::r#async::{MethodHandler, TtrpcContext};
38+
3939
/// A ttrpc Server (async).
4040
pub struct Server {
4141
listeners: Vec<RawFd>,

src/asynchronous/stream.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6+
use protobuf::Message;
7+
use tokio::io::AsyncReadExt;
8+
69
use crate::error::{get_rpc_status, sock_error_msg, Error, Result};
710
use crate::proto::{
811
Code, Response, Status, MESSAGE_HEADER_LENGTH, MESSAGE_LENGTH_MAX, MESSAGE_TYPE_RESPONSE,
912
};
1013
use crate::r#async::utils;
1114
use crate::MessageHeader;
12-
use protobuf::Message;
13-
use tokio::io::AsyncReadExt;
1415

1516
async fn receive_count<T>(reader: &mut T, count: usize) -> Result<Vec<u8>>
1617
where

src/asynchronous/utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6-
use crate::error::{get_status, Result};
7-
use crate::proto::{
8-
Code, MessageHeader, Request, Status, MESSAGE_TYPE_RESPONSE,
9-
};
10-
use async_trait::async_trait;
11-
use protobuf::{CodedInputStream, Message};
126
use std::collections::HashMap;
137
use std::os::unix::io::{FromRawFd, RawFd};
148
use std::result::Result as StdResult;
9+
10+
use async_trait::async_trait;
11+
use protobuf::{CodedInputStream, Message};
1512
use tokio::net::UnixStream;
1613

14+
use crate::error::{get_status, Result};
15+
use crate::proto::{Code, MessageHeader, Request, Status, MESSAGE_TYPE_RESPONSE};
16+
1717
/// Handle request in async mode.
1818
#[macro_export]
1919
macro_rules! async_request_handler {

0 commit comments

Comments
 (0)