Skip to content

Commit 6f304a4

Browse files
committed
Make unnecessarily public functions/mod private
If the method is useless for users but it used by generated code, just hide the docs. Fixes: #130 Signed-off-by: Tim Zhang <[email protected]>
1 parent 15411c8 commit 6f304a4

File tree

10 files changed

+47
-51
lines changed

10 files changed

+47
-51
lines changed

example/async-server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::sync::Arc;
1313
use log::LevelFilter;
1414

1515
use protocols::r#async::{agent, agent_ttrpc, health, health_ttrpc, types};
16-
use ttrpc::asynchronous::server::*;
16+
use ttrpc::asynchronous::Server;
1717
use ttrpc::error::{Error, Result};
1818
use ttrpc::ttrpc::{Code, Status};
1919

example/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ mod protocols;
1616

1717
use protocols::sync::{agent, agent_ttrpc, health, health_ttrpc};
1818
use std::thread;
19-
use ttrpc::client::Client;
2019
use ttrpc::context::{self, Context};
20+
use ttrpc::Client;
2121

2222
fn main() {
2323
let c = Client::connect("unix://@/tmp/1").unwrap();

example/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use std::thread;
2323

2424
use protocols::sync::{agent, agent_ttrpc, health, health_ttrpc, types};
2525
use ttrpc::error::{Error, Result};
26-
use ttrpc::server::*;
2726
use ttrpc::ttrpc::{Code, Status};
27+
use ttrpc::Server;
2828

2929
struct HealthService;
3030
impl health_ttrpc::Health for HealthService {

src/asynchronous/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55

66
//! Server and client in async mode (alias r#async).
77
8-
pub mod client;
9-
pub mod server;
10-
pub mod stream;
8+
mod client;
9+
mod server;
10+
mod stream;
1111
#[macro_use]
12-
pub mod utils;
12+
#[doc(hidden)]
13+
mod utils;
1314
mod unix_incoming;
1415

1516
#[doc(inline)]
1617
pub use crate::r#async::client::Client;
1718
#[doc(inline)]
1819
pub use crate::r#async::server::Server;
1920
#[doc(inline)]
20-
pub use crate::r#async::utils::{convert_response_to_buf, MethodHandler, TtrpcContext};
21+
pub use utils::{MethodHandler, TtrpcContext};

src/asynchronous/stream.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ where
5151
Ok(mh)
5252
}
5353

54-
pub async fn receive<T>(reader: &mut T) -> Result<(MessageHeader, Vec<u8>)>
54+
pub(crate) async fn receive<T>(reader: &mut T) -> Result<(MessageHeader, Vec<u8>)>
5555
where
5656
T: AsyncReadExt + std::marker::Unpin,
5757
{
@@ -94,15 +94,15 @@ fn header_to_buf(mh: MessageHeader) -> Vec<u8> {
9494
buf
9595
}
9696

97-
pub fn to_req_buf(stream_id: u32, mut body: Vec<u8>) -> Vec<u8> {
97+
pub(crate) fn to_req_buf(stream_id: u32, mut body: Vec<u8>) -> Vec<u8> {
9898
let header = utils::get_request_header_from_body(stream_id, &body);
9999
let mut buf = header_to_buf(header);
100100
buf.append(&mut body);
101101

102102
buf
103103
}
104104

105-
pub fn to_res_buf(stream_id: u32, mut body: Vec<u8>) -> Vec<u8> {
105+
pub(crate) fn to_res_buf(stream_id: u32, mut body: Vec<u8>) -> Vec<u8> {
106106
let header = utils::get_response_header_from_body(stream_id, &body);
107107
let mut buf = header_to_buf(header);
108108
buf.append(&mut body);
@@ -119,7 +119,7 @@ fn get_response_body(res: &Response) -> Result<Vec<u8>> {
119119
Ok(buf)
120120
}
121121

122-
pub async fn respond(
122+
pub(crate) async fn respond(
123123
tx: tokio::sync::mpsc::Sender<Vec<u8>>,
124124
stream_id: u32,
125125
body: Vec<u8>,
@@ -131,7 +131,7 @@ pub async fn respond(
131131
.map_err(err_to_others_err!(e, "Send packet to sender error "))
132132
}
133133

134-
pub async fn respond_with_status(
134+
pub(crate) async fn respond_with_status(
135135
tx: tokio::sync::mpsc::Sender<Vec<u8>>,
136136
stream_id: u32,
137137
status: Status,

src/asynchronous/utils.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//
55

66
use crate::common::{MessageHeader, MESSAGE_TYPE_REQUEST, MESSAGE_TYPE_RESPONSE};
7-
use crate::error::{get_status, Error, Result};
8-
use crate::ttrpc::{Code, Request, Response, Status};
7+
use crate::error::{get_status, Result};
8+
use crate::ttrpc::{Code, Request, Status};
99
use async_trait::async_trait;
1010
use protobuf::{CodedInputStream, Message};
1111
use std::collections::HashMap;
@@ -47,7 +47,11 @@ macro_rules! async_request_handler {
4747
},
4848
}
4949

50-
let buf = ::ttrpc::r#async::convert_response_to_buf(res)?;
50+
let mut buf = Vec::with_capacity(res.compute_size() as usize);
51+
let mut s = protobuf::CodedOutputStream::vec(&mut buf);
52+
res.write_to(&mut s).map_err(ttrpc::err_to_others!(e, ""))?;
53+
s.flush().map_err(ttrpc::err_to_others!(e, ""))?;
54+
5155
return Ok(($ctx.mh.stream_id, buf));
5256
};
5357
}
@@ -95,16 +99,7 @@ pub struct TtrpcContext {
9599
pub timeout_nano: i64,
96100
}
97101

98-
pub fn convert_response_to_buf(res: Response) -> Result<Vec<u8>> {
99-
let mut buf = Vec::with_capacity(res.compute_size() as usize);
100-
let mut s = protobuf::CodedOutputStream::vec(&mut buf);
101-
res.write_to(&mut s).map_err(err_to_others_err!(e, ""))?;
102-
s.flush().map_err(err_to_others_err!(e, ""))?;
103-
104-
Ok(buf)
105-
}
106-
107-
pub fn get_response_header_from_body(stream_id: u32, body: &[u8]) -> MessageHeader {
102+
pub(crate) fn get_response_header_from_body(stream_id: u32, body: &[u8]) -> MessageHeader {
108103
MessageHeader {
109104
length: body.len() as u32,
110105
stream_id,
@@ -113,7 +108,7 @@ pub fn get_response_header_from_body(stream_id: u32, body: &[u8]) -> MessageHead
113108
}
114109
}
115110

116-
pub fn get_request_header_from_body(stream_id: u32, body: &[u8]) -> MessageHeader {
111+
pub(crate) fn get_request_header_from_body(stream_id: u32, body: &[u8]) -> MessageHeader {
117112
MessageHeader {
118113
length: body.len() as u32,
119114
stream_id,
@@ -122,7 +117,7 @@ pub fn get_request_header_from_body(stream_id: u32, body: &[u8]) -> MessageHeade
122117
}
123118
}
124119

125-
pub fn new_unix_stream_from_raw_fd(fd: RawFd) -> UnixStream {
120+
pub(crate) fn new_unix_stream_from_raw_fd(fd: RawFd) -> UnixStream {
126121
let std_stream: std::os::unix::net::UnixStream;
127122
unsafe {
128123
std_stream = std::os::unix::net::UnixStream::from_raw_fd(fd);
@@ -133,7 +128,7 @@ pub fn new_unix_stream_from_raw_fd(fd: RawFd) -> UnixStream {
133128
UnixStream::from_std(std_stream).unwrap()
134129
}
135130

136-
pub fn body_to_request(body: &[u8]) -> StdResult<Request, Status> {
131+
pub(crate) fn body_to_request(body: &[u8]) -> StdResult<Request, Status> {
137132
let mut req = Request::new();
138133
let merge_result;
139134
{
@@ -150,6 +145,6 @@ pub fn body_to_request(body: &[u8]) -> StdResult<Request, Status> {
150145
Ok(req)
151146
}
152147

153-
pub fn get_path(service: &str, method: &str) -> String {
148+
pub(crate) fn get_path(service: &str, method: &str) -> String {
154149
format!("/{}/{}", service, method)
155150
}

src/lib.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ mod common;
5252
mod compiled {
5353
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
5454
}
55-
#[doc(inline)]
5655
pub use compiled::ttrpc;
5756

5857
pub mod context;
@@ -66,22 +65,17 @@ pub use crate::ttrpc::{Code, Request, Response, Status};
6665

6766
cfg_sync! {
6867
pub mod sync;
68+
#[doc(hidden)]
69+
pub use sync::response_to_channel;
6970
#[doc(inline)]
70-
pub use crate::sync::channel::{write_message};
71-
#[doc(inline)]
72-
pub use crate::sync::utils::{response_to_channel, MethodHandler, TtrpcContext};
73-
#[doc(inline)]
74-
pub use crate::sync::client;
75-
#[doc(inline)]
76-
pub use crate::sync::client::Client;
77-
#[doc(inline)]
78-
pub use crate::sync::server;
71+
pub use sync::{MethodHandler, TtrpcContext};
72+
pub use sync::Client;
7973
#[doc(inline)]
80-
pub use crate::sync::server::Server;
74+
pub use sync::Server;
8175
}
8276

8377
cfg_async! {
8478
pub mod asynchronous;
8579
#[doc(hidden)]
86-
pub use crate::asynchronous as r#async;
80+
pub use asynchronous as r#async;
8781
}

src/sync/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use std::{io, thread};
2727
use crate::common::set_fd_close_exec;
2828
use crate::common::{client_connect, MESSAGE_TYPE_REQUEST, MESSAGE_TYPE_RESPONSE, SOCK_CLOEXEC};
2929
use crate::error::{Error, Result};
30-
use crate::sync::channel::{read_message, write_message};
3130
use crate::ttrpc::{Code, Request, Response};
31+
use crate::sync::channel::{read_message, write_message};
3232
use crate::MessageHeader;
3333
use std::time::Duration;
3434

src/sync/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
//! Server and Client in sync mode.
77
8-
#[macro_use]
9-
pub mod channel;
10-
pub mod client;
11-
// TODO: address this after merging linters
12-
#[allow(clippy::too_many_arguments)]
13-
pub mod server;
8+
mod channel;
9+
mod client;
10+
mod server;
1411

1512
#[macro_use]
16-
pub mod utils;
13+
mod utils;
14+
15+
pub use client::Client;
16+
pub use server::Server;
17+
18+
#[doc(hidden)]
19+
pub use utils::response_to_channel;
20+
pub use utils::{MethodHandler, TtrpcContext};

src/sync/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::sync::{Arc, Mutex};
2525
use std::thread::JoinHandle;
2626
use std::{io, thread};
2727

28+
use super::utils::response_to_channel;
2829
#[cfg(not(target_os = "linux"))]
2930
use crate::common::set_fd_close_exec;
3031
use crate::common::{self, MESSAGE_TYPE_REQUEST};
@@ -33,7 +34,7 @@ use crate::error::{get_status, Error, Result};
3334
use crate::sync::channel::{read_message, write_message};
3435
use crate::ttrpc::{Code, Request, Response};
3536
use crate::MessageHeader;
36-
use crate::{response_to_channel, MethodHandler, TtrpcContext};
37+
use crate::{MethodHandler, TtrpcContext};
3738

3839
// poll_queue will create WAIT_THREAD_COUNT_DEFAULT threads in begin.
3940
// If wait thread count < WAIT_THREAD_COUNT_MIN, create number to WAIT_THREAD_COUNT_DEFAULT.
@@ -86,6 +87,7 @@ struct ThreadS<'a> {
8687
max: usize,
8788
}
8889

90+
#[allow(clippy::too_many_arguments)]
8991
fn start_method_handler_thread(
9092
fd: RawFd,
9193
fdlock: Arc<Mutex<()>>,

0 commit comments

Comments
 (0)