1 // Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
2 
3 /*!
4 
5 [grpcio] is a Rust implementation of [gRPC], which is a high performance, open source universal RPC
6 framework that puts mobile and HTTP/2 first. grpcio is built on [gRPC Core] and [futures-rs].
7 
8 [grpcio]: https://github.com/tikv/grpc-rs/
9 [gRPC]: https://grpc.io/
10 [gRPC Core]: https://github.com/grpc/grpc
11 [futures-rs]: https://github.com/rust-lang/futures-rs
12 
13 ## Optional features
14 
15 - **`boringssl`** *(enabled by default)* - Enables support for TLS encryption and some authentication
16   mechanisms.
17 - **`openssl`** - Same as `boringssl`, but base on the system openssl.
18 - **`openssl-vendored`** - Same as `openssl`, but build openssl from source.
19 
20 */
21 
22 #![allow(clippy::new_without_default)]
23 #![allow(clippy::new_without_default)]
24 #![allow(clippy::cast_lossless)]
25 #![allow(clippy::option_map_unit_fn)]
26 #![allow(clippy::derive_partial_eq_without_eq)]
27 
28 use grpcio_sys as grpc_sys;
29 #[macro_use]
30 extern crate log;
31 
32 mod buf;
33 mod call;
34 mod channel;
35 pub mod channelz;
36 mod client;
37 mod codec;
38 mod cq;
39 mod env;
40 mod error;
41 mod log_util;
42 mod metadata;
43 mod quota;
44 mod security;
45 mod server;
46 mod task;
47 
48 pub use crate::buf::GrpcSlice;
49 pub use crate::call::client::{
50     CallOption, ClientCStreamReceiver, ClientCStreamSender, ClientDuplexReceiver,
51     ClientDuplexSender, ClientSStreamReceiver, ClientUnaryReceiver, StreamingCallSink,
52 };
53 pub use crate::call::server::{
54     ClientStreamingSink, ClientStreamingSinkResult, Deadline, DuplexSink, DuplexSinkFailure,
55     RequestStream, RpcContext, ServerStreamingSink, ServerStreamingSinkFailure, UnarySink,
56     UnarySinkResult,
57 };
58 pub use crate::call::{MessageReader, Method, MethodType, RpcStatus, RpcStatusCode, WriteFlags};
59 pub use crate::channel::{
60     Channel, ChannelBuilder, CompressionAlgorithms, CompressionLevel, ConnectivityState, LbPolicy,
61     OptTarget,
62 };
63 pub use crate::client::Client;
64 
65 #[cfg(any(feature = "protobuf-codec", feature = "protobufv3-codec"))]
66 pub use crate::codec::pb_codec::{de as pb_de, ser as pb_ser};
67 #[cfg(feature = "prost-codec")]
68 pub use crate::codec::pr_codec::{de as pr_de, ser as pr_ser};
69 
70 pub use crate::codec::{Marshaller, MAX_MESSAGE_SIZE};
71 pub use crate::env::{EnvBuilder, Environment};
72 pub use crate::error::{Error, Result};
73 pub use crate::log_util::redirect_log;
74 pub use crate::metadata::{Metadata, MetadataBuilder, MetadataIter};
75 pub use crate::quota::ResourceQuota;
76 pub use crate::security::*;
77 pub use crate::server::{
78     CheckResult, Server, ServerBuilder, ServerChecker, Service, ServiceBuilder, ShutdownFuture,
79 };
80 
81 /// A shortcut for implementing a service method by returning `UNIMPLEMENTED` status code.
82 ///
83 /// Compiler will provide a default implementations for all methods to invoke this macro, so
84 /// you usually won't call it directly. If you really need to, just call it like:
85 /// ```ignored
86 /// fn method(&self, ctx: grpcio::RpcContext, req: Request, resp: UnarySink<Response>) {
87 ///     unimplemented_call!(ctx, resp);
88 /// }
89 /// ```
90 #[macro_export]
91 macro_rules! unimplemented_call {
92     ($ctx:ident, $sink:ident) => {{
93         let f = async move {
94             let _ = $sink
95                 .fail($crate::RpcStatus::new($crate::RpcStatusCode::UNIMPLEMENTED))
96                 .await;
97         };
98         $ctx.spawn(f)
99     }};
100 }
101