Skip to content

Commit fa20590

Browse files
committed
Add crate docs for ttrpc-rust
- Add docs. - Display all features in docs. - Make the intermediate-module compiled private. Signed-off-by: Tim Zhang <[email protected]>
1 parent f2be137 commit fa20590

File tree

12 files changed

+61
-2
lines changed

12 files changed

+61
-2
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ttrpc"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["The AntFin Kata Team <[email protected]>"]
55
edition = "2018"
66
license = "Apache-2.0"
@@ -32,3 +32,6 @@ protobuf-codec = ["protobuf"]
3232
async = []
3333
sync = []
3434

35+
[package.metadata.docs.rs]
36+
all-features = true
37+
rustdoc-args = ["--cfg", "docsrs"]

src/asynchronous/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type RequestReceiver = Receiver<(Vec<u8>, Sender<Result<Vec<u8>>>)>;
2929
type ResponseSender = Sender<Result<Vec<u8>>>;
3030
type ResponseReceiver = Receiver<Result<Vec<u8>>>;
3131

32+
/// A ttrpc Client (async).
3233
#[derive(Clone)]
3334
pub struct Client {
3435
req_tx: RequestSender,

src/asynchronous/mod.rs

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

6+
//! Server and client in async mode.
7+
68
pub mod client;
79
pub mod server;
810
pub mod stream;
911
#[macro_use]
1012
pub mod utils;
1113

14+
#[doc(inline)]
1215
pub use crate::r#async::client::Client;
16+
#[doc(inline)]
1317
pub use crate::r#async::server::Server;
18+
#[doc(inline)]
1419
pub use crate::r#async::utils::{convert_response_to_buf, MethodHandler, TtrpcContext};

src/asynchronous/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use tokio::{
2828
};
2929
use tokio_vsock::VsockListener;
3030

31+
/// A ttrpc Server (async).
3132
pub struct Server {
3233
listeners: Vec<RawFd>,
3334
methods: Arc<HashMap<String, Box<dyn MethodHandler + Send + Sync>>>,

src/asynchronous/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use protobuf::Message;
1111
use std::os::unix::io::{FromRawFd, RawFd};
1212
use tokio::net::UnixStream;
1313

14+
/// Handle request in async mode.
1415
#[macro_export]
1516
macro_rules! async_request_handler {
1617
($class: ident, $ctx: ident, $req: ident, $server: ident, $req_type: ident, $req_fn: ident) => {
@@ -49,6 +50,7 @@ macro_rules! async_request_handler {
4950
};
5051
}
5152

53+
/// Send request through async client.
5254
#[macro_export]
5355
macro_rules! async_client_request {
5456
($self: ident, $req: ident, $timeout_nano: ident, $server: expr, $method: expr, $cres: ident) => {
@@ -74,11 +76,13 @@ macro_rules! async_client_request {
7476
};
7577
}
7678

79+
/// Trait that implements handler which is a proxy to the desired method (async).
7780
#[async_trait]
7881
pub trait MethodHandler {
7982
async fn handler(&self, ctx: TtrpcContext, req: Request) -> Result<(u32, Vec<u8>)>;
8083
}
8184

85+
/// The context of ttrpc (async).
8286
#[derive(Debug)]
8387
pub struct TtrpcContext {
8488
pub fd: std::os::unix::io::RawFd,

src/common.rs

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

6+
//! Common functions and macros.
7+
68
#![allow(unused_macros)]
79

810
use crate::error::{Error, Result};
@@ -17,6 +19,7 @@ pub enum Domain {
1719
Vsock,
1820
}
1921

22+
/// Message header of ttrpc.
2023
#[derive(Default, Debug)]
2124
pub struct MessageHeader {
2225
pub length: u32,
@@ -102,6 +105,8 @@ macro_rules! cfg_sync {
102105
($($item:item)*) => {
103106
$(
104107
#[cfg(feature = "sync")]
108+
#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
109+
#[doc(inline)]
105110
$item
106111
)*
107112
}
@@ -111,6 +116,8 @@ macro_rules! cfg_async {
111116
($($item:item)*) => {
112117
$(
113118
#[cfg(feature = "async")]
119+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
120+
#[doc(inline)]
114121
$item
115122
)*
116123
}

src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//! Error and Result of ttrpc and relevant functions, macros.
16+
1517
use crate::ttrpc::{Code, Status};
1618
use std::result;
1719

20+
/// The error type for ttrpc.
1821
#[derive(Debug)]
1922
pub enum Error {
2023
Socket(String),
2124
RpcStatus(Status),
2225
Others(String),
2326
}
2427

28+
/// A specialized Result type for ttrpc.
2529
pub type Result<T> = result::Result<T, Error>;
2630

31+
/// Get ttrpc::Status from ttrpc::Code and a message.
2732
pub fn get_status(c: Code, msg: String) -> Status {
2833
let mut status = Status::new();
2934
status.set_code(c);
@@ -57,6 +62,7 @@ macro_rules! err_to_Others {
5762
};
5863
}
5964

65+
/// Convert to ttrpc::Error::Others.
6066
#[macro_export]
6167
macro_rules! Err_to_Others {
6268
($e: ident, $s: expr) => {

src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//! ttrpc-rust is a **non-core** subproject of containerd
16+
//!
17+
//! `ttrpc-rust` is the Rust version of [ttrpc](https://github.com/containerd/ttrpc). [ttrpc](https://github.com/containerd/ttrpc) is GRPC for low-memory environments.
18+
//!
19+
//! Example:
20+
//!
21+
//! Check [this](https://github.com/containerd/ttrpc-rust/tree/master/example)
22+
//!
23+
//! # Feature flags
24+
//!
25+
//! - `async`: Enables async server and client.
26+
//! - `sync`: Enables traditional sync server and client (default enabled).
27+
//! - `protobuf-codec`: Includes rust-protobuf (default enabled).
28+
1529
#[macro_use]
1630
extern crate log;
1731

@@ -20,13 +34,17 @@ pub mod error;
2034
#[macro_use]
2135
pub mod common;
2236
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
23-
pub mod compiled {
37+
mod compiled {
2438
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
2539
}
40+
#[doc(inline)]
2641
pub use compiled::ttrpc;
2742

43+
#[doc(inline)]
2844
pub use crate::common::MessageHeader;
45+
#[doc(inline)]
2946
pub use crate::error::{get_status, Error, Result};
47+
#[doc(inline)]
3048
pub use crate::ttrpc::{Code, Request, Response, Status};
3149

3250
cfg_sync! {

src/sync/client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//! Sync client of ttrpc.
16+
1517
use nix::sys::select::*;
1618
use nix::sys::socket::*;
1719
use nix::unistd::close;
@@ -31,6 +33,7 @@ use crate::MessageHeader;
3133
type Sender = mpsc::Sender<(Vec<u8>, mpsc::SyncSender<Result<Vec<u8>>>)>;
3234
type Receiver = mpsc::Receiver<(Vec<u8>, mpsc::SyncSender<Result<Vec<u8>>>)>;
3335

36+
/// A ttrpc Client (sync).
3437
#[derive(Clone)]
3538
pub struct Client {
3639
fd: RawFd,

src/sync/mod.rs

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

6+
//! Server and Client in sync mode.
7+
68
#[macro_use]
79
pub mod channel;
810
pub mod client;

0 commit comments

Comments
 (0)