fbthrift/
lib.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#![recursion_limit = "1024"]
18#![deny(warnings)]
19
20use std::i32;
21
22macro_rules! bail_err {
23    ($e:expr) => {
24        return Err(From::from($e))
25    };
26}
27
28macro_rules! ensure_err {
29    ($cond:expr, $e:expr) => {
30        if !$cond {
31            bail_err!($e);
32        }
33    };
34}
35
36use anyhow::Result;
37
38#[macro_use]
39pub mod protocol;
40
41pub mod application_exception;
42pub mod binary_protocol;
43pub mod binary_type;
44pub mod builtin_types;
45pub mod compact_protocol;
46pub mod context_stack;
47pub mod deserialize;
48pub mod export;
49pub mod framing;
50pub mod processor;
51pub mod request_context;
52pub mod serialize;
53pub mod simplejson_protocol;
54pub mod thrift_protocol;
55pub mod ttype;
56pub mod uri;
57
58mod bufext;
59mod client;
60mod errors;
61mod exceptions;
62mod varint;
63
64#[cfg(test)]
65mod tests;
66
67#[doc(hidden)]
68pub mod help;
69
70pub mod types {
71    // Define ApplicationException as if it were a normal generated type to make things simpler
72    // for codegen.
73    pub use crate::application_exception::ApplicationException;
74}
75
76pub use crate::application_exception::ApplicationException;
77pub use crate::application_exception::ApplicationExceptionErrorCode;
78pub use crate::binary_protocol::BinaryProtocol;
79pub use crate::bufext::BufExt;
80pub use crate::bufext::BufMutExt;
81pub use crate::client::ClientFactory;
82pub use crate::client::Transport;
83pub use crate::compact_protocol::CompactProtocol;
84pub use crate::context_stack::ContextStack;
85pub use crate::context_stack::DummyContextStack;
86pub use crate::context_stack::SerializedMessage;
87pub use crate::deserialize::Deserialize;
88pub use crate::errors::NonthrowingFunctionError;
89pub use crate::errors::ProtocolError;
90pub use crate::exceptions::ExceptionInfo;
91pub use crate::exceptions::ResultInfo;
92pub use crate::exceptions::ResultType;
93pub use crate::framing::Framing;
94pub use crate::framing::FramingDecoded;
95pub use crate::framing::FramingEncoded;
96pub use crate::framing::FramingEncodedFinal;
97pub use crate::help::NoopSpawner;
98pub use crate::processor::NullServiceProcessor;
99pub use crate::processor::ReplyState;
100pub use crate::processor::SerializedStreamElement;
101pub use crate::processor::ServiceProcessor;
102pub use crate::processor::ThriftService;
103pub use crate::protocol::Field;
104pub use crate::protocol::Protocol;
105pub use crate::protocol::ProtocolDecoded;
106pub use crate::protocol::ProtocolEncoded;
107pub use crate::protocol::ProtocolEncodedFinal;
108pub use crate::protocol::ProtocolReader;
109pub use crate::protocol::ProtocolWriter;
110pub use crate::request_context::DummyRequestContext;
111pub use crate::request_context::RequestContext;
112pub use crate::serialize::Serialize;
113pub use crate::simplejson_protocol::SimpleJsonProtocol;
114pub use crate::thrift_protocol::MessageType;
115pub use crate::thrift_protocol::ProtocolID;
116pub use crate::ttype::GetTType;
117pub use crate::ttype::TType;
118pub use crate::uri::GetUri;
119
120pub trait ThriftEnum: Sized {
121    fn enumerate() -> &'static [(Self, &'static str)];
122
123    fn variants() -> &'static [&'static str];
124
125    fn variant_values() -> &'static [Self];
126}
127
128/// Set the default ID's for unknown exceptions and fields.
129/// When reading off the wire, these default values will be
130/// overridden with the unrecognized id (which must be nonnegative).
131// ---
132// Keep in sync with the UNKNOWN_ID constant in //common/rust/thrift/ast.
133pub const __UNKNOWN_ID: i32 = i32::MIN;