Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 1 | // 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 |
| 24 | //! 2. protocol |
| 25 | //! 3. transport |
| 26 | //! 4. server |
| 27 | //! 5. autogen |
| 28 | //! |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame^] | 29 | //! The modules are layered as shown in the diagram below. The `autogen'd` |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 30 | //! layer is generated by the Thrift compiler's Rust plugin. It uses the |
| 31 | //! types and functions defined in this crate to serialize and deserialize |
| 32 | //! messages and implement RPC. Users interact with these types and services |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame^] | 33 | //! by writing their own code that uses the auto-generated clients and |
| 34 | //! servers. |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 35 | //! |
| 36 | //! ```text |
| 37 | //! +-----------+ |
| 38 | //! | user app | |
| 39 | //! +-----------+ |
| 40 | //! | autogen'd | (uses errors, autogen) |
| 41 | //! +-----------+ |
| 42 | //! | protocol | |
| 43 | //! +-----------+ |
| 44 | //! | transport | |
| 45 | //! +-----------+ |
| 46 | //! ``` |
| 47 | |
| 48 | #![crate_type = "lib"] |
| 49 | #![doc(test(attr(allow(unused_variables), deny(warnings))))] |
| 50 | |
| 51 | extern crate byteorder; |
| 52 | extern crate integer_encoding; |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame^] | 53 | extern crate threadpool; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 54 | extern crate try_from; |
| 55 | |
| 56 | #[macro_use] |
| 57 | extern crate log; |
| 58 | |
| 59 | // NOTE: this macro has to be defined before any modules. See: |
| 60 | // https://danielkeep.github.io/quick-intro-to-macros.html#some-more-gotchas |
| 61 | |
| 62 | /// Assert that an expression returning a `Result` is a success. If it is, |
| 63 | /// return the value contained in the result, i.e. `expr.unwrap()`. |
| 64 | #[cfg(test)] |
| 65 | macro_rules! assert_success { |
| 66 | ($e: expr) => { |
| 67 | { |
| 68 | let res = $e; |
| 69 | assert!(res.is_ok()); |
| 70 | res.unwrap() |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | pub mod protocol; |
| 76 | pub mod server; |
| 77 | pub mod transport; |
| 78 | |
| 79 | mod errors; |
| 80 | pub use errors::*; |
| 81 | |
| 82 | mod autogen; |
| 83 | pub use autogen::*; |
| 84 | |
| 85 | /// Result type returned by all runtime library functions. |
| 86 | /// |
| 87 | /// As is convention this is a typedef of `std::result::Result` |
| 88 | /// with `E` defined as the `thrift::Error` type. |
| 89 | pub type Result<T> = std::result::Result<T, self::Error>; |