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 | //! Types required to send and receive bytes over an I/O channel. |
| 19 | //! |
| 20 | //! The core type is the `TTransport` trait, through which a `TProtocol` can |
| 21 | //! send and receive primitives over the wire. While `TProtocol` instances deal |
| 22 | //! with primitive types, `TTransport` instances understand only bytes. |
| 23 | |
| 24 | use std::cell::RefCell; |
| 25 | use std::io; |
| 26 | use std::rc::Rc; |
| 27 | |
| 28 | mod buffered; |
| 29 | mod framed; |
| 30 | mod passthru; |
| 31 | mod socket; |
| 32 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 33 | pub mod mem; |
| 34 | |
Flier Lu | 1187060 | 2017-03-20 17:31:34 +0800 | [diff] [blame] | 35 | pub use self::mem::TBufferTransport; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 36 | pub use self::buffered::{TBufferedTransport, TBufferedTransportFactory}; |
| 37 | pub use self::framed::{TFramedTransport, TFramedTransportFactory}; |
| 38 | pub use self::passthru::TPassThruTransport; |
| 39 | pub use self::socket::TTcpTransport; |
| 40 | |
| 41 | /// Identifies an I/O channel that can be used to send and receive bytes. |
| 42 | pub trait TTransport: io::Read + io::Write {} |
| 43 | impl<I: io::Read + io::Write> TTransport for I {} |
| 44 | |
| 45 | /// Helper type used by servers to create `TTransport` instances for accepted |
| 46 | /// client connections. |
| 47 | pub trait TTransportFactory { |
| 48 | /// Create a `TTransport` that wraps an `inner` transport, thus creating |
| 49 | /// a transport stack. |
| 50 | fn create(&self, inner: Rc<RefCell<Box<TTransport>>>) -> Box<TTransport>; |
| 51 | } |