diff options
author | Allen George <allengeorge@apache.org> | 2021-03-01 23:19:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 23:19:52 -0500 |
commit | 55c3e4c2eff86b61eae1b098803e72d682bdaafb (patch) | |
tree | bf8f63ef1cdc0678c7ecbed0be8d4dbd8c179fbb /lib/rs | |
parent | 1ab156ab17b6f3268a1ba57034b4d4dc96f4f306 (diff) | |
download | thrift-55c3e4c2eff86b61eae1b098803e72d682bdaafb.tar.gz |
Reformat rust code using 1.40 rustfmt and fail build if rustfmt fails (#2339)
Diffstat (limited to 'lib/rs')
-rw-r--r-- | lib/rs/Makefile.am | 2 | ||||
-rw-r--r-- | lib/rs/src/errors.rs | 11 | ||||
-rw-r--r-- | lib/rs/src/lib.rs | 3 | ||||
-rw-r--r-- | lib/rs/src/protocol/binary.rs | 15 | ||||
-rw-r--r-- | lib/rs/src/protocol/compact.rs | 6 | ||||
-rw-r--r-- | lib/rs/src/protocol/mod.rs | 23 | ||||
-rw-r--r-- | lib/rs/src/protocol/multiplexed.rs | 4 | ||||
-rw-r--r-- | lib/rs/src/server/mod.rs | 3 | ||||
-rw-r--r-- | lib/rs/src/server/multiplexed.rs | 16 | ||||
-rw-r--r-- | lib/rs/src/server/threaded.rs | 14 | ||||
-rw-r--r-- | lib/rs/src/transport/buffered.rs | 2 | ||||
-rw-r--r-- | lib/rs/src/transport/mod.rs | 7 | ||||
-rw-r--r-- | lib/rs/test/Makefile.am | 1 |
13 files changed, 67 insertions, 40 deletions
diff --git a/lib/rs/Makefile.am b/lib/rs/Makefile.am index 6d74348eb..dd1c03bfa 100644 --- a/lib/rs/Makefile.am +++ b/lib/rs/Makefile.am @@ -31,9 +31,11 @@ install: @echo '##############################################################' check-local: + $(CARGO) fmt --all -- --check $(CARGO) test all-local: + $(CARGO) fmt --all -- --check $(CARGO) build clean-local: diff --git a/lib/rs/src/errors.rs b/lib/rs/src/errors.rs index 41a055eca..03d98cf7e 100644 --- a/lib/rs/src/errors.rs +++ b/lib/rs/src/errors.rs @@ -15,13 +15,15 @@ // specific language governing permissions and limitations // under the License. +use std::convert::TryFrom; use std::convert::{From, Into}; use std::error::Error as StdError; use std::fmt::{Debug, Display, Formatter}; use std::{error, fmt, io, string}; -use std::convert::TryFrom; -use crate::protocol::{TFieldIdentifier, TInputProtocol, TOutputProtocol, TStructIdentifier, TType}; +use crate::protocol::{ + TFieldIdentifier, TInputProtocol, TOutputProtocol, TStructIdentifier, TType, +}; // FIXME: should all my error structs impl error::Error as well? // FIXME: should all fields in TransportError, ProtocolError and ApplicationError be optional? @@ -235,10 +237,7 @@ impl Error { i.read_struct_end()?; - Ok(ApplicationError { - kind, - message, - }) + Ok(ApplicationError { kind, message }) } /// Convert an `ApplicationError` into its wire representation and write diff --git a/lib/rs/src/lib.rs b/lib/rs/src/lib.rs index f71c3e88a..279690ede 100644 --- a/lib/rs/src/lib.rs +++ b/lib/rs/src/lib.rs @@ -80,4 +80,5 @@ pub use crate::autogen::*; pub type Result<T> = std::result::Result<T, self::Error>; // Re-export ordered-float, since it is used by the generator -pub use ordered_float::OrderedFloat as OrderedFloat;
\ No newline at end of file +// FIXME: check the guidance around type reexports +pub use ordered_float::OrderedFloat; diff --git a/lib/rs/src/protocol/binary.rs b/lib/rs/src/protocol/binary.rs index 22b496c07..8509c34ae 100644 --- a/lib/rs/src/protocol/binary.rs +++ b/lib/rs/src/protocol/binary.rs @@ -68,10 +68,7 @@ where /// Set `strict` to `true` if all incoming messages contain the protocol /// version number in the protocol header. pub fn new(transport: T, strict: bool) -> TBinaryInputProtocol<T> { - TBinaryInputProtocol { - strict, - transport, - } + TBinaryInputProtocol { strict, transport } } } @@ -294,10 +291,7 @@ where /// Set `strict` to `true` if all outgoing messages should contain the /// protocol version number in the protocol header. pub fn new(transport: T, strict: bool) -> TBinaryOutputProtocol<T> { - TBinaryOutputProtocol { - strict, - transport, - } + TBinaryOutputProtocol { strict, transport } } } @@ -453,7 +447,10 @@ impl TBinaryOutputProtocolFactory { } impl TOutputProtocolFactory for TBinaryOutputProtocolFactory { - fn create(&self, transport: Box<dyn TWriteTransport + Send>) -> Box<dyn TOutputProtocol + Send> { + fn create( + &self, + transport: Box<dyn TWriteTransport + Send>, + ) -> Box<dyn TOutputProtocol + Send> { Box::new(TBinaryOutputProtocol::new(transport, true)) } } diff --git a/lib/rs/src/protocol/compact.rs b/lib/rs/src/protocol/compact.rs index f885e4022..e08a30bd9 100644 --- a/lib/rs/src/protocol/compact.rs +++ b/lib/rs/src/protocol/compact.rs @@ -427,7 +427,8 @@ where self.write_byte(COMPACT_PROTOCOL_ID)?; self.write_byte((u8::from(identifier.message_type) << 5) | COMPACT_VERSION)?; // cast i32 as u32 so that varint writing won't use zigzag encoding - self.transport.write_varint(identifier.sequence_number as u32)?; + self.transport + .write_varint(identifier.sequence_number as u32)?; self.write_string(&identifier.name)?; Ok(()) } @@ -1091,6 +1092,7 @@ mod tests { let (mut i_prot, _) = test_objects(); // signed two's complement of -1073741823 = 1100_0000_0000_0000_0000_0000_0000_0001 + #[rustfmt::skip] let source_bytes: [u8; 11] = [ 0x82, /* protocol ID */ 0x21, /* message type | protocol version */ @@ -1102,7 +1104,7 @@ mod tests { 0x03, /* message-name length */ 0x66, 0x6F, - 0x6F /* "foo" */, + 0x6F, /* "foo" */ ]; i_prot.transport.set_readable_bytes(&source_bytes); diff --git a/lib/rs/src/protocol/mod.rs b/lib/rs/src/protocol/mod.rs index f9c1f724c..e11a104df 100644 --- a/lib/rs/src/protocol/mod.rs +++ b/lib/rs/src/protocol/mod.rs @@ -577,14 +577,18 @@ where /// ``` pub trait TOutputProtocolFactory { /// Create a `TOutputProtocol` that writes bytes to `transport`. - fn create(&self, transport: Box<dyn TWriteTransport + Send>) -> Box<dyn TOutputProtocol + Send>; + fn create(&self, transport: Box<dyn TWriteTransport + Send>) + -> Box<dyn TOutputProtocol + Send>; } impl<T> TOutputProtocolFactory for Box<T> where T: TOutputProtocolFactory + ?Sized, { - fn create(&self, transport: Box<dyn TWriteTransport + Send>) -> Box<dyn TOutputProtocol + Send> { + fn create( + &self, + transport: Box<dyn TWriteTransport + Send>, + ) -> Box<dyn TOutputProtocol + Send> { (**self).create(transport) } } @@ -679,10 +683,7 @@ impl TListIdentifier { /// Create a `TListIdentifier` for a list with `size` elements of type /// `element_type`. pub fn new(element_type: TType, size: i32) -> TListIdentifier { - TListIdentifier { - element_type, - size, - } + TListIdentifier { element_type, size } } } @@ -699,10 +700,7 @@ impl TSetIdentifier { /// Create a `TSetIdentifier` for a set with `size` elements of type /// `element_type`. pub fn new(element_type: TType, size: i32) -> TSetIdentifier { - TSetIdentifier { - element_type, - size, - } + TSetIdentifier { element_type, size } } } @@ -878,7 +876,10 @@ pub fn verify_expected_service_call(expected: &str, actual: &str) -> crate::Resu /// `actual`. /// /// Return `()` if `actual == expected`, `Err` otherwise. -pub fn verify_expected_message_type(expected: TMessageType, actual: TMessageType) -> crate::Result<()> { +pub fn verify_expected_message_type( + expected: TMessageType, + actual: TMessageType, +) -> crate::Result<()> { if expected == actual { Ok(()) } else { diff --git a/lib/rs/src/protocol/multiplexed.rs b/lib/rs/src/protocol/multiplexed.rs index 83498fbdd..697b7e6bc 100644 --- a/lib/rs/src/protocol/multiplexed.rs +++ b/lib/rs/src/protocol/multiplexed.rs @@ -191,7 +191,9 @@ where #[cfg(test)] mod tests { - use crate::protocol::{TBinaryOutputProtocol, TMessageIdentifier, TMessageType, TOutputProtocol}; + use crate::protocol::{ + TBinaryOutputProtocol, TMessageIdentifier, TMessageType, TOutputProtocol, + }; use crate::transport::{TBufferChannel, TIoChannel, WriteHalf}; use super::*; diff --git a/lib/rs/src/server/mod.rs b/lib/rs/src/server/mod.rs index 050feeec7..64c6da2e3 100644 --- a/lib/rs/src/server/mod.rs +++ b/lib/rs/src/server/mod.rs @@ -91,7 +91,8 @@ pub trait TProcessor { /// the response to `o`. /// /// Returns `()` if the handler was executed; `Err` otherwise. - fn process(&self, i: &mut dyn TInputProtocol, o: &mut dyn TOutputProtocol) -> crate::Result<()>; + fn process(&self, i: &mut dyn TInputProtocol, o: &mut dyn TOutputProtocol) + -> crate::Result<()>; } /// Convenience function used in generated `TProcessor` implementations to diff --git a/lib/rs/src/server/multiplexed.rs b/lib/rs/src/server/multiplexed.rs index 4f41f2447..8331d91ef 100644 --- a/lib/rs/src/server/multiplexed.rs +++ b/lib/rs/src/server/multiplexed.rs @@ -136,7 +136,11 @@ impl TMultiplexedProcessor { } impl TProcessor for TMultiplexedProcessor { - fn process(&self, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> crate::Result<()> { + fn process( + &self, + i_prot: &mut dyn TInputProtocol, + o_prot: &mut dyn TOutputProtocol, + ) -> crate::Result<()> { let msg_ident = i_prot.read_message_begin()?; debug!("process incoming msg id:{:?}", &msg_ident); @@ -183,7 +187,9 @@ mod tests { use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; - use crate::protocol::{TBinaryInputProtocol, TBinaryOutputProtocol, TMessageIdentifier, TMessageType}; + use crate::protocol::{ + TBinaryInputProtocol, TBinaryOutputProtocol, TMessageIdentifier, TMessageType, + }; use crate::transport::{ReadHalf, TBufferChannel, TIoChannel, WriteHalf}; use crate::{ApplicationError, ApplicationErrorKind}; @@ -261,7 +267,11 @@ mod tests { } impl TProcessor for Service { - fn process(&self, _: &mut dyn TInputProtocol, _: &mut dyn TOutputProtocol) -> crate::Result<()> { + fn process( + &self, + _: &mut dyn TInputProtocol, + _: &mut dyn TOutputProtocol, + ) -> crate::Result<()> { let res = self .invoked .compare_and_swap(false, true, Ordering::Relaxed); diff --git a/lib/rs/src/server/threaded.rs b/lib/rs/src/server/threaded.rs index 64bf8bbe5..897235c2b 100644 --- a/lib/rs/src/server/threaded.rs +++ b/lib/rs/src/server/threaded.rs @@ -21,7 +21,9 @@ use std::net::{TcpListener, TcpStream, ToSocketAddrs}; use std::sync::Arc; use threadpool::ThreadPool; -use crate::protocol::{TInputProtocol, TInputProtocolFactory, TOutputProtocol, TOutputProtocolFactory}; +use crate::protocol::{ + TInputProtocol, TInputProtocolFactory, TOutputProtocol, TOutputProtocolFactory, +}; use crate::transport::{TIoChannel, TReadTransportFactory, TTcpChannel, TWriteTransportFactory}; use crate::{ApplicationError, ApplicationErrorKind}; @@ -196,7 +198,10 @@ where fn new_protocols_for_connection( &mut self, stream: TcpStream, - ) -> crate::Result<(Box<dyn TInputProtocol + Send>, Box<dyn TOutputProtocol + Send>)> { + ) -> crate::Result<( + Box<dyn TInputProtocol + Send>, + Box<dyn TOutputProtocol + Send>, + )> { // create the shared tcp stream let channel = TTcpChannel::with_stream(stream); @@ -227,10 +232,11 @@ fn handle_incoming_connection<PRC>( let mut o_prot = o_prot; loop { match processor.process(&mut *i_prot, &mut *o_prot) { - Ok(()) => {}, + Ok(()) => {} Err(err) => { match err { - crate::Error::Transport(ref transport_err) if transport_err.kind == TransportErrorKind::EndOfFile => {}, + crate::Error::Transport(ref transport_err) + if transport_err.kind == TransportErrorKind::EndOfFile => {} other => warn!("processor completed with error: {:?}", other), } break; diff --git a/lib/rs/src/transport/buffered.rs b/lib/rs/src/transport/buffered.rs index ebdcdc292..a54f823da 100644 --- a/lib/rs/src/transport/buffered.rs +++ b/lib/rs/src/transport/buffered.rs @@ -365,7 +365,7 @@ mod tests { assert_eq!(&buf, &[0, 1, 2, 3, 4, 5, 6, 7]); // let's clear out the buffer and try read again - for b in &mut buf{ + for b in &mut buf { *b = 0; } let read_result = t.read(&mut buf); diff --git a/lib/rs/src/transport/mod.rs b/lib/rs/src/transport/mod.rs index d02a87c64..2b5733f49 100644 --- a/lib/rs/src/transport/mod.rs +++ b/lib/rs/src/transport/mod.rs @@ -111,7 +111,12 @@ pub trait TIoChannel: Read + Write { /// Returned halves may share the underlying OS channel or buffer resources. /// Implementations **should ensure** that these two halves can be safely /// used independently by concurrent threads. - fn split(self) -> crate::Result<(crate::transport::ReadHalf<Self>, crate::transport::WriteHalf<Self>)> + fn split( + self, + ) -> crate::Result<( + crate::transport::ReadHalf<Self>, + crate::transport::WriteHalf<Self>, + )> where Self: Sized; } diff --git a/lib/rs/test/Makefile.am b/lib/rs/test/Makefile.am index 5dc4f56ea..19056a65f 100644 --- a/lib/rs/test/Makefile.am +++ b/lib/rs/test/Makefile.am @@ -28,6 +28,7 @@ stubs: thrifts/Base_One.thrift thrifts/Base_Two.thrift thrifts/Midlayer.thrift t $(THRIFT) -out src --gen rs $(top_builddir)/test/Identifiers.thrift #THRIFT-4953 check: stubs + $(CARGO) fmt --all -- --check $(CARGO) build $(CARGO) test [ -d bin ] || mkdir bin |