blob: d3804eccc086c5ddaa41b07821e28bbca7e45db2 [file] [log] [blame]
Allen George8b96bfb2016-11-02 08:01:08 -04001// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Rust runtime library for the Apache Thrift RPC system.
19//!
20//! This crate implements the components required to build a working
21//! Thrift server and client. It is divided into the following modules:
22//!
23//! 1. errors
Hasnain Lakhani42d0b712025-07-17 19:57:05 -070024//! 2. configuration
25//! 3. protocol
26//! 4. transport
27//! 5. server
28//! 6. autogen
Allen George8b96bfb2016-11-02 08:01:08 -040029//!
Allen George0e22c362017-01-30 07:15:00 -050030//! The modules are layered as shown in the diagram below. The `autogen'd`
Allen George8b96bfb2016-11-02 08:01:08 -040031//! layer is generated by the Thrift compiler's Rust plugin. It uses the
32//! types and functions defined in this crate to serialize and deserialize
33//! messages and implement RPC. Users interact with these types and services
Allen George0e22c362017-01-30 07:15:00 -050034//! by writing their own code that uses the auto-generated clients and
35//! servers.
Allen George8b96bfb2016-11-02 08:01:08 -040036//!
37//! ```text
38//! +-----------+
39//! | user app |
40//! +-----------+
41//! | autogen'd | (uses errors, autogen)
42//! +-----------+
43//! | protocol |
44//! +-----------+
45//! | transport |
46//! +-----------+
47//! ```
Zicklag70992f12021-05-08 12:47:13 -050048//!
49//! # Tutorial
50//!
51//! For an example of how to setup a simple client and server using this crate
52//! see the [tutorial].
53//!
54//! [tutorial]: https://github.com/apache/thrift/tree/master/tutorial/rs
Allen George8b96bfb2016-11-02 08:01:08 -040055
56#![crate_type = "lib"]
Cameron Martinda54fc82025-01-12 08:55:45 +000057#![doc(test(attr(allow(unused_variables, dead_code), deny(warnings))))]
Danny Browning77d96c12019-08-21 13:41:07 -060058#![deny(bare_trait_objects)]
Allen George8b96bfb2016-11-02 08:01:08 -040059
Allen George8b96bfb2016-11-02 08:01:08 -040060// NOTE: this macro has to be defined before any modules. See:
61// https://danielkeep.github.io/quick-intro-to-macros.html#some-more-gotchas
62
63/// Assert that an expression returning a `Result` is a success. If it is,
64/// return the value contained in the result, i.e. `expr.unwrap()`.
65#[cfg(test)]
66macro_rules! assert_success {
Allen Georgeef7a1892018-12-16 18:01:37 -050067 ($e: expr) => {{
68 let res = $e;
69 assert!(res.is_ok());
70 res.unwrap()
71 }};
Allen George8b96bfb2016-11-02 08:01:08 -040072}
73
74pub mod protocol;
Jorge C. Leitao77afa012021-08-08 14:51:15 +000075
76#[cfg(feature = "server")]
Allen George8b96bfb2016-11-02 08:01:08 -040077pub mod server;
78pub mod transport;
79
80mod errors;
Allen Georgeb0d14132020-03-29 11:48:55 -040081pub use crate::errors::*;
Allen George8b96bfb2016-11-02 08:01:08 -040082
83mod autogen;
Allen Georgeb0d14132020-03-29 11:48:55 -040084pub use crate::autogen::*;
Allen George8b96bfb2016-11-02 08:01:08 -040085
Hasnain Lakhani42d0b712025-07-17 19:57:05 -070086mod configuration;
87pub use crate::configuration::*;
88
Allen George8b96bfb2016-11-02 08:01:08 -040089/// Result type returned by all runtime library functions.
90///
91/// As is convention this is a typedef of `std::result::Result`
92/// with `E` defined as the `thrift::Error` type.
93pub type Result<T> = std::result::Result<T, self::Error>;
Danny Browningddec4312019-03-08 14:20:41 -070094
95// Re-export ordered-float, since it is used by the generator
Allen George55c3e4c2021-03-01 23:19:52 -050096// FIXME: check the guidance around type reexports
97pub use ordered_float::OrderedFloat;