1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! HTTP based RPC library.
//!
//! This crate provides a thin framework to easily implement type-safe RPC channels
//! for client/server model communication.
#![warn(missing_docs)]
extern crate fibers;
extern crate futures;
extern crate handy_async;
extern crate miasht;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serdeconv;
#[macro_use]
extern crate slog;
#[macro_use]
extern crate trackable;
extern crate url;
extern crate url_serde;

pub use miasht::builtin::futures::FutureExt;

#[allow(missing_docs)]
pub type BodyReader =
    miasht::builtin::io::BodyReader<miasht::server::Request<fibers::net::TcpStream>>;

#[allow(missing_docs)]
pub fn content_length(body: &BodyReader) -> Option<u64> {
    if let miasht::builtin::io::BodyReader::FixedLength(ref r) = *body {
        Some(r.limit())
    } else {
        None
    }
}

#[allow(missing_docs)]
pub type ReadBody<T> = Box<dyn futures::Future<Item = (BodyReader, T), Error = Error> + Send + 'static>;

pub use client::RpcClient;
pub use error::{Error, ErrorKind};
pub use procedure::{HandleRpc, Procedure, RpcRequest, RpcResponse};
pub use server::{RpcServer, RpcServerBuilder};

/// A helper macro to construct an `EntryPoint` instance.
///
/// # Examples
///
/// ```
/// # #[macro_use]
/// # extern crate htrpc;
/// use htrpc::types::{EntryPoint, PathSegment};
///
/// # fn main() {
/// static SEGMENTS: &[PathSegment] =
///     &[PathSegment::Val("foo"), PathSegment::Var, PathSegment::Val("baz")];
/// let p0 = EntryPoint::new(SEGMENTS);
/// let p1 = htrpc_entry_point!["foo", _, "baz"];
/// assert_eq!(p0, p1);
/// # }
/// ```
#[macro_export]
macro_rules! htrpc_entry_point {
    ($($segment:tt),*) => {
        {
            static SEGMENTS: &[$crate::types::PathSegment] =
                &[$(htrpc_expand_segment!($segment)),*];
            $crate::types::EntryPoint::new(SEGMENTS)
        }
    }
}

#[doc(hidden)]
#[macro_export]
macro_rules! htrpc_expand_segment {
    (_) => {
        $crate::types::PathSegment::Var
    };
    ($s:expr) => {
        $crate::types::PathSegment::Val($s)
    }
}

pub mod deserializers;
pub mod json;
pub mod json_pretty;
pub mod msgpack;
pub mod pool;
pub mod rfc7807;
pub mod serializers;
pub mod types;

mod client;
mod error;
mod misc;
mod procedure;
mod router;
mod server;

/// This crate specific `Result` type.
pub type Result<T> = ::std::result::Result<T, Error>;