summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllen George <allengeorge@apache.org>2021-03-01 23:19:52 -0500
committerGitHub <noreply@github.com>2021-03-01 23:19:52 -0500
commit55c3e4c2eff86b61eae1b098803e72d682bdaafb (patch)
treebf8f63ef1cdc0678c7ecbed0be8d4dbd8c179fbb
parent1ab156ab17b6f3268a1ba57034b4d4dc96f4f306 (diff)
downloadthrift-55c3e4c2eff86b61eae1b098803e72d682bdaafb.tar.gz
Reformat rust code using 1.40 rustfmt and fail build if rustfmt fails (#2339)
-rw-r--r--.rustfmt.toml64
-rwxr-xr-xMakefile.am2
-rw-r--r--lib/rs/Makefile.am2
-rw-r--r--lib/rs/src/errors.rs11
-rw-r--r--lib/rs/src/lib.rs3
-rw-r--r--lib/rs/src/protocol/binary.rs15
-rw-r--r--lib/rs/src/protocol/compact.rs6
-rw-r--r--lib/rs/src/protocol/mod.rs23
-rw-r--r--lib/rs/src/protocol/multiplexed.rs4
-rw-r--r--lib/rs/src/server/mod.rs3
-rw-r--r--lib/rs/src/server/multiplexed.rs16
-rw-r--r--lib/rs/src/server/threaded.rs14
-rw-r--r--lib/rs/src/transport/buffered.rs2
-rw-r--r--lib/rs/src/transport/mod.rs7
-rw-r--r--lib/rs/test/Makefile.am1
-rw-r--r--rust-toolchain1
-rw-r--r--test/rs/Makefile.am1
-rw-r--r--test/rs/src/bin/test_client.rs220
-rw-r--r--test/rs/src/bin/test_server.rs166
-rw-r--r--tutorial/rs/Makefile.am1
-rw-r--r--tutorial/rs/src/bin/tutorial_server.rs2
21 files changed, 256 insertions, 308 deletions
diff --git a/.rustfmt.toml b/.rustfmt.toml
deleted file mode 100644
index dca5afd35..000000000
--- a/.rustfmt.toml
+++ /dev/null
@@ -1,64 +0,0 @@
-max_width = 100
-hard_tabs = false
-tab_spaces = 4
-newline_style = "Auto"
-use_small_heuristics = "Default"
-indent_style = "Block"
-wrap_comments = false
-format_doc_comments = false
-comment_width = 80
-normalize_comments = false
-normalize_doc_attributes = false
-license_template_path = ""
-format_strings = false
-format_macro_matchers = false
-format_macro_bodies = true
-empty_item_single_line = true
-struct_lit_single_line = true
-fn_single_line = false
-where_single_line = false
-imports_indent = "Block"
-imports_layout = "Mixed"
-merge_imports = false
-reorder_imports = true
-reorder_modules = true
-reorder_impl_items = false
-type_punctuation_density = "Wide"
-space_before_colon = false
-space_after_colon = true
-spaces_around_ranges = false
-binop_separator = "Front"
-remove_nested_parens = true
-combine_control_expr = true
-overflow_delimited_expr = false
-struct_field_align_threshold = 0
-enum_discrim_align_threshold = 0
-match_arm_blocks = true
-force_multiline_blocks = false
-fn_args_density = "Tall"
-brace_style = "SameLineWhere"
-control_brace_style = "AlwaysSameLine"
-trailing_semicolon = true
-trailing_comma = "Vertical"
-match_block_trailing_comma = false
-blank_lines_upper_bound = 1
-blank_lines_lower_bound = 0
-edition = "2015"
-merge_derives = true
-use_try_shorthand = false
-use_field_init_shorthand = false
-force_explicit_abi = true
-condense_wildcard_suffixes = false
-color = "Auto"
-required_version = "1.0.0"
-unstable_features = false
-disable_all_formatting = false
-skip_children = false
-hide_parse_errors = false
-error_on_line_overflow = false
-error_on_unformatted = false
-report_todo = "Never"
-report_fixme = "Never"
-ignore = []
-emit_mode = "Files"
-make_backup = false
diff --git a/Makefile.am b/Makefile.am
index c5d9c41db..3db9ffa57 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -142,7 +142,6 @@ EXTRA_DIST = \
.gitattributes \
.gitignore \
.travis.yml \
- .rustfmt.toml \
ApacheThrift.nuspec \
appveyor.yml \
bootstrap.sh \
@@ -165,5 +164,6 @@ EXTRA_DIST = \
package-lock.json \
phpcs.xml.dist \
README.md \
+ rust-toolchain \
sonar-project.properties \
Thrift.podspec
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
diff --git a/rust-toolchain b/rust-toolchain
new file mode 100644
index 000000000..32b7211cb
--- /dev/null
+++ b/rust-toolchain
@@ -0,0 +1 @@
+1.40.0
diff --git a/test/rs/Makefile.am b/test/rs/Makefile.am
index 4b061eae0..afb2cad03 100644
--- a/test/rs/Makefile.am
+++ b/test/rs/Makefile.am
@@ -22,6 +22,7 @@ stubs: ../ThriftTest.thrift
precross: stubs
$(CARGO) build
+ $(CARGO) fmt --all -- --check
[ -d bin ] || mkdir bin
cp target/debug/test_server bin/test_server
cp target/debug/test_client bin/test_client
diff --git a/test/rs/src/bin/test_client.rs b/test/rs/src/bin/test_client.rs
index 476f9eb25..8623915d4 100644
--- a/test/rs/src/bin/test_client.rs
+++ b/test/rs/src/bin/test_client.rs
@@ -15,22 +15,24 @@
// specific language governing permissions and limitations
// under the License.
+use clap::{clap_app, value_t};
use env_logger;
use log::*;
-use clap::{clap_app, value_t};
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Debug;
use std::net::TcpStream;
use thrift;
+use thrift::protocol::{
+ TBinaryInputProtocol, TBinaryOutputProtocol, TCompactInputProtocol, TCompactOutputProtocol,
+ TInputProtocol, TMultiplexedOutputProtocol, TOutputProtocol,
+};
+use thrift::transport::{
+ TBufferedReadTransport, TBufferedWriteTransport, TFramedReadTransport, TFramedWriteTransport,
+ TIoChannel, TReadTransport, TTcpChannel, TWriteTransport,
+};
use thrift::OrderedFloat;
-use thrift::protocol::{TBinaryInputProtocol, TBinaryOutputProtocol, TCompactInputProtocol,
- TCompactOutputProtocol, TInputProtocol, TMultiplexedOutputProtocol,
- TOutputProtocol};
-use thrift::transport::{TBufferedReadTransport, TBufferedWriteTransport,
- TFramedReadTransport, TFramedWriteTransport, TIoChannel, TReadTransport,
- TTcpChannel, TWriteTransport};
use thrift_test::*;
fn main() {
@@ -92,10 +94,7 @@ fn run() -> thrift::Result<()> {
info!(
"connecting to {}:{} with {}+{} stack",
- host,
- port,
- protocol,
- transport
+ host, port, protocol, transport
);
for _ in 0..testloops {
@@ -115,47 +114,50 @@ fn build(
let (i_chan, o_chan) = c.split()?;
let (i_tran, o_tran): (Box<dyn TReadTransport>, Box<dyn TWriteTransport>) = match transport {
- "buffered" => {
- (Box::new(TBufferedReadTransport::new(i_chan)),
- Box::new(TBufferedWriteTransport::new(o_chan)))
- }
- "framed" => {
- (Box::new(TFramedReadTransport::new(i_chan)),
- Box::new(TFramedWriteTransport::new(o_chan)))
- }
+ "buffered" => (
+ Box::new(TBufferedReadTransport::new(i_chan)),
+ Box::new(TBufferedWriteTransport::new(o_chan)),
+ ),
+ "framed" => (
+ Box::new(TFramedReadTransport::new(i_chan)),
+ Box::new(TFramedWriteTransport::new(o_chan)),
+ ),
unmatched => return Err(format!("unsupported transport {}", unmatched).into()),
};
let (i_prot, o_prot): (Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>) = match protocol {
- "binary" => {
- (Box::new(TBinaryInputProtocol::new(i_tran, true)),
- Box::new(TBinaryOutputProtocol::new(o_tran, true)))
- }
- "multi" => {
- (Box::new(TBinaryInputProtocol::new(i_tran, true)),
- Box::new(
- TMultiplexedOutputProtocol::new(
- service_name,
- TBinaryOutputProtocol::new(o_tran, true),
- ),
- ))
- }
- "compact" => {
- (Box::new(TCompactInputProtocol::new(i_tran)),
- Box::new(TCompactOutputProtocol::new(o_tran)))
- }
- "multic" => {
- (Box::new(TCompactInputProtocol::new(i_tran)),
- Box::new(TMultiplexedOutputProtocol::new(service_name, TCompactOutputProtocol::new(o_tran)),))
- }
+ "binary" => (
+ Box::new(TBinaryInputProtocol::new(i_tran, true)),
+ Box::new(TBinaryOutputProtocol::new(o_tran, true)),
+ ),
+ "multi" => (
+ Box::new(TBinaryInputProtocol::new(i_tran, true)),
+ Box::new(TMultiplexedOutputProtocol::new(
+ service_name,
+ TBinaryOutputProtocol::new(o_tran, true),
+ )),
+ ),
+ "compact" => (
+ Box::new(TCompactInputProtocol::new(i_tran)),
+ Box::new(TCompactOutputProtocol::new(o_tran)),
+ ),
+ "multic" => (
+ Box::new(TCompactInputProtocol::new(i_tran)),
+ Box::new(TMultiplexedOutputProtocol::new(
+ service_name,
+ TCompactOutputProtocol::new(o_tran),
+ )),
+ ),
unmatched => return Err(format!("unsupported protocol {}", unmatched).into()),
};
Ok((i_prot, o_prot))
}
-type BuildThriftTestClient = ThriftTestSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
-type BuiltSecondServiceClient = SecondServiceSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
+type BuildThriftTestClient =
+ ThriftTestSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
+type BuiltSecondServiceClient =
+ SecondServiceSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
#[allow(clippy::cognitive_complexity)]
fn make_thrift_calls(
@@ -250,26 +252,22 @@ fn make_thrift_calls(
{
let x_snd = Xtruct2 {
byte_thing: Some(32),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("foo".to_owned()),
- byte_thing: Some(1),
- i32_thing: Some(324_382_098),
- i64_thing: Some(12_938_492_818),
- },
- ),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("foo".to_owned()),
+ byte_thing: Some(1),
+ i32_thing: Some(324_382_098),
+ i64_thing: Some(12_938_492_818),
+ }),
i32_thing: Some(293_481_098),
};
let x_cmp = Xtruct2 {
byte_thing: Some(32),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("foo".to_owned()),
- byte_thing: Some(1),
- i32_thing: Some(324_382_098),
- i64_thing: Some(12_938_492_818),
- },
- ),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("foo".to_owned()),
+ byte_thing: Some(1),
+ i32_thing: Some(324_382_098),
+ i64_thing: Some(12_938_492_818),
+ }),
i32_thing: Some(293_481_098),
};
verify_expected_result(thrift_test_client.test_nest(x_snd), x_cmp)?;
@@ -399,30 +397,24 @@ fn make_thrift_calls(
arg_map_usermap.insert(Numberz::EIGHT, 19);
let mut arg_vec_xtructs: Vec<Xtruct> = Vec::new();
- arg_vec_xtructs.push(
- Xtruct {
- string_thing: Some("foo".to_owned()),
- byte_thing: Some(8),
- i32_thing: Some(29),
- i64_thing: Some(92384),
- },
- );
- arg_vec_xtructs.push(
- Xtruct {
- string_thing: Some("bar".to_owned()),
- byte_thing: Some(28),
- i32_thing: Some(2),
- i64_thing: Some(-1281),
- },
- );
- arg_vec_xtructs.push(
- Xtruct {
- string_thing: Some("baz".to_owned()),
- byte_thing: Some(0),
- i32_thing: Some(3_948_539),
- i64_thing: Some(-12_938_492),
- },
- );
+ arg_vec_xtructs.push(Xtruct {
+ string_thing: Some("foo".to_owned()),
+ byte_thing: Some(8),
+ i32_thing: Some(29),
+ i64_thing: Some(92384),
+ });
+ arg_vec_xtructs.push(Xtruct {
+ string_thing: Some("bar".to_owned()),
+ byte_thing: Some(28),
+ i32_thing: Some(2),
+ i64_thing: Some(-1281),
+ });
+ arg_vec_xtructs.push(Xtruct {
+ string_thing: Some("baz".to_owned()),
+ byte_thing: Some(0),
+ i32_thing: Some(3_948_539),
+ i64_thing: Some(-12_938_492),
+ });
let mut s_cmp_nested_1: BTreeMap<Numberz, Insanity> = BTreeMap::new();
let insanity = Insanity {
@@ -450,12 +442,12 @@ fn make_thrift_calls(
{
let r = thrift_test_client.test_exception("Xception".to_owned());
let x = match r {
- Err(thrift::Error::User(ref e)) => {
- match e.downcast_ref::<Xception>() {
- Some(x) => Ok(x),
- None => Err(thrift::Error::User("did not get expected Xception struct".into()),),
- }
- }
+ Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() {
+ Some(x) => Ok(x),
+ None => Err(thrift::Error::User(
+ "did not get expected Xception struct".into(),
+ )),
+ },
_ => Err(thrift::Error::User("did not get exception".into())),
}?;
@@ -493,12 +485,12 @@ fn make_thrift_calls(
let r =
thrift_test_client.test_multi_exception("Xception".to_owned(), "ignored".to_owned());
let x = match r {
- Err(thrift::Error::User(ref e)) => {
- match e.downcast_ref::<Xception>() {
- Some(x) => Ok(x),
- None => Err(thrift::Error::User("did not get expected Xception struct".into()),),
- }
- }
+ Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() {
+ Some(x) => Ok(x),
+ None => Err(thrift::Error::User(
+ "did not get expected Xception struct".into(),
+ )),
+ },
_ => Err(thrift::Error::User("did not get exception".into())),
}?;
@@ -515,28 +507,26 @@ fn make_thrift_calls(
let r =
thrift_test_client.test_multi_exception("Xception2".to_owned(), "ignored".to_owned());
let x = match r {
- Err(thrift::Error::User(ref e)) => {
- match e.downcast_ref::<Xception2>() {
- Some(x) => Ok(x),
- None => Err(thrift::Error::User("did not get expected Xception struct".into()),),
- }
- }
+ Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception2>() {
+ Some(x) => Ok(x),
+ None => Err(thrift::Error::User(
+ "did not get expected Xception struct".into(),
+ )),
+ },
_ => Err(thrift::Error::User("did not get exception".into())),
}?;
let x_cmp = Xception2 {
error_code: Some(2002),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("This is an Xception2".to_owned()),
- // since this is an OPT_IN_REQ_OUT field the sender sets a default
- byte_thing: Some(0),
- // since this is an OPT_IN_REQ_OUT field the sender sets a default
- i32_thing: Some(0),
- // since this is an OPT_IN_REQ_OUT field the sender sets a default
- i64_thing: Some(0),
- },
- ),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("This is an Xception2".to_owned()),
+ // since this is an OPT_IN_REQ_OUT field the sender sets a default
+ byte_thing: Some(0),
+ // since this is an OPT_IN_REQ_OUT field the sender sets a default
+ i32_thing: Some(0),
+ // since this is an OPT_IN_REQ_OUT field the sender sets a default
+ i64_thing: Some(0),
+ }),
};
verify_expected_result(Ok(x), &x_cmp)?;
@@ -546,7 +536,9 @@ fn make_thrift_calls(
{
let r = thrift_test_client.test_multi_exception("haha".to_owned(), "RETURNED".to_owned());
let x = match r {
- Err(e) => Err(thrift::Error::User(format!("received an unexpected exception {:?}", e).into(),),),
+ Err(e) => Err(thrift::Error::User(
+ format!("received an unexpected exception {:?}", e).into(),
+ )),
_ => r,
}?;
@@ -586,7 +578,9 @@ fn verify_expected_result<T: Debug + PartialEq + Sized>(
Ok(())
} else {
info!("*** FAILED ***");
- Err(thrift::Error::User(format!("expected {:?} but got {:?}", &expected, &v).into()),)
+ Err(thrift::Error::User(
+ format!("expected {:?} but got {:?}", &expected, &v).into(),
+ ))
}
}
Err(e) => Err(e),
diff --git a/test/rs/src/bin/test_server.rs b/test/rs/src/bin/test_server.rs
index c1f31758a..6a05e79e5 100644
--- a/test/rs/src/bin/test_server.rs
+++ b/test/rs/src/bin/test_server.rs
@@ -15,23 +15,25 @@
// specific language governing permissions and limitations
// under the License.
+use clap::{clap_app, value_t};
use env_logger;
use log::*;
-use clap::{clap_app, value_t};
use std::collections::{BTreeMap, BTreeSet};
use std::thread;
use std::time::Duration;
use thrift;
-use thrift::OrderedFloat;
-use thrift::protocol::{TBinaryInputProtocolFactory, TBinaryOutputProtocolFactory,
- TCompactInputProtocolFactory, TCompactOutputProtocolFactory,
- TInputProtocolFactory, TOutputProtocolFactory};
+use thrift::protocol::{
+ TBinaryInputProtocolFactory, TBinaryOutputProtocolFactory, TCompactInputProtocolFactory,
+ TCompactOutputProtocolFactory, TInputProtocolFactory, TOutputProtocolFactory,
+};
use thrift::server::{TMultiplexedProcessor, TServer};
-use thrift::transport::{TBufferedReadTransportFactory, TBufferedWriteTransportFactory,
- TFramedReadTransportFactory, TFramedWriteTransportFactory,
- TReadTransportFactory, TWriteTransportFactory};
+use thrift::transport::{
+ TBufferedReadTransportFactory, TBufferedWriteTransportFactory, TFramedReadTransportFactory,
+ TFramedWriteTransportFactory, TReadTransportFactory, TWriteTransportFactory,
+};
+use thrift::OrderedFloat;
use thrift_test::*;
fn main() {
@@ -49,7 +51,6 @@ fn main() {
}
fn run() -> thrift::Result<()> {
-
// unsupported options:
// --domain-socket
// --pipe
@@ -75,50 +76,55 @@ fn run() -> thrift::Result<()> {
info!("binding to {}", listen_address);
- let (i_transport_factory, o_transport_factory): (Box<dyn TReadTransportFactory>,
- Box<dyn TWriteTransportFactory>) =
- match &*transport {
- "buffered" => {
- (Box::new(TBufferedReadTransportFactory::new()),
- Box::new(TBufferedWriteTransportFactory::new()))
- }
- "framed" => {
- (Box::new(TFramedReadTransportFactory::new()),
- Box::new(TFramedWriteTransportFactory::new()))
- }
- unknown => {
- return Err(format!("unsupported transport type {}", unknown).into());
- }
- };
-
- let (i_protocol_factory, o_protocol_factory): (Box<dyn TInputProtocolFactory>,
- Box<dyn TOutputProtocolFactory>) =
- match &*protocol {
- "binary" | "multi" | "multi:binary" => {
- (Box::new(TBinaryInputProtocolFactory::new()),
- Box::new(TBinaryOutputProtocolFactory::new()))
- }
- "compact" | "multic" | "multi:compact" => {
- (Box::new(TCompactInputProtocolFactory::new()),
- Box::new(TCompactOutputProtocolFactory::new()))
- }
- unknown => {
- return Err(format!("unsupported transport type {}", unknown).into());
- }
- };
+ let (i_transport_factory, o_transport_factory): (
+ Box<dyn TReadTransportFactory>,
+ Box<dyn TWriteTransportFactory>,
+ ) = match &*transport {
+ "buffered" => (
+ Box::new(TBufferedReadTransportFactory::new()),
+ Box::new(TBufferedWriteTransportFactory::new()),
+ ),
+ "framed" => (
+ Box::new(TFramedReadTransportFactory::new()),
+ Box::new(TFramedWriteTransportFactory::new()),
+ ),
+ unknown => {
+ return Err(format!("unsupported transport type {}", unknown).into());
+ }
+ };
+
+ let (i_protocol_factory, o_protocol_factory): (
+ Box<dyn TInputProtocolFactory>,
+ Box<dyn TOutputProtocolFactory>,
+ ) = match &*protocol {
+ "binary" | "multi" | "multi:binary" => (
+ Box::new(TBinaryInputProtocolFactory::new()),
+ Box::new(TBinaryOutputProtocolFactory::new()),
+ ),
+ "compact" | "multic" | "multi:compact" => (
+ Box::new(TCompactInputProtocolFactory::new()),
+ Box::new(TCompactOutputProtocolFactory::new()),
+ ),
+ unknown => {
+ return Err(format!("unsupported transport type {}", unknown).into());
+ }
+ };
let test_processor = ThriftTestSyncProcessor::new(ThriftTestSyncHandlerImpl {});
match &*server_type {
"simple" | "thread-pool" => {
if protocol == "multi" || protocol == "multic" {
- let second_service_processor = SecondServiceSyncProcessor::new(SecondServiceSyncHandlerImpl {},);
+ let second_service_processor =
+ SecondServiceSyncProcessor::new(SecondServiceSyncHandlerImpl {});
let mut multiplexed_processor = TMultiplexedProcessor::new();
- multiplexed_processor
- .register("ThriftTest", Box::new(test_processor), true)?;
- multiplexed_processor
- .register("SecondService", Box::new(second_service_processor), false)?;
+ multiplexed_processor.register("ThriftTest", Box::new(test_processor), true)?;
+ multiplexed_processor.register(
+ "SecondService",
+ Box::new(second_service_processor),
+ false,
+ )?;
let mut server = TServer::new(
i_transport_factory,
@@ -315,15 +321,11 @@ impl ThriftTestSyncHandler for ThriftTestSyncHandlerImpl {
info!("testException({})", arg);
match &*arg {
- "Xception" => {
- Err(
- (Xception {
- error_code: Some(1001),
- message: Some(arg),
- })
- .into(),
- )
- }
+ "Xception" => Err((Xception {
+ error_code: Some(1001),
+ message: Some(arg),
+ })
+ .into()),
"TException" => Err("this is a random error".into()),
_ => Ok(()),
}
@@ -339,41 +341,27 @@ impl ThriftTestSyncHandler for ThriftTestSyncHandlerImpl {
// do not throw anything and return Xtruct with string_thing = arg1
fn handle_test_multi_exception(&self, arg0: String, arg1: String) -> thrift::Result<Xtruct> {
match &*arg0 {
- "Xception" => {
- Err(
- (Xception {
- error_code: Some(1001),
- message: Some("This is an Xception".to_owned()),
- })
- .into(),
- )
- }
- "Xception2" => {
- Err(
- (Xception2 {
- error_code: Some(2002),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("This is an Xception2".to_owned()),
- byte_thing: None,
- i32_thing: None,
- i64_thing: None,
- },
- ),
- })
- .into(),
- )
- }
- _ => {
- Ok(
- Xtruct {
- string_thing: Some(arg1),
- byte_thing: None,
- i32_thing: None,
- i64_thing: None,
- },
- )
- }
+ "Xception" => Err((Xception {
+ error_code: Some(1001),
+ message: Some("This is an Xception".to_owned()),
+ })
+ .into()),
+ "Xception2" => Err((Xception2 {
+ error_code: Some(2002),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("This is an Xception2".to_owned()),
+ byte_thing: None,
+ i32_thing: None,
+ i64_thing: None,
+ }),
+ })
+ .into()),
+ _ => Ok(Xtruct {
+ string_thing: Some(arg1),
+ byte_thing: None,
+ i32_thing: None,
+ i64_thing: None,
+ }),
}
}
diff --git a/tutorial/rs/Makefile.am b/tutorial/rs/Makefile.am
index 666331e4a..4aa05dada 100644
--- a/tutorial/rs/Makefile.am
+++ b/tutorial/rs/Makefile.am
@@ -24,6 +24,7 @@ gen-rs/tutorial.rs gen-rs/shared.rs: $(top_srcdir)/tutorial/tutorial.thrift
all-local: gen-rs/tutorial.rs
$(CARGO) build
+ $(CARGO) fmt --all -- --check
[ -d bin ] || mkdir bin
cp target/debug/tutorial_server bin/tutorial_server
cp target/debug/tutorial_client bin/tutorial_client
diff --git a/tutorial/rs/src/bin/tutorial_server.rs b/tutorial/rs/src/bin/tutorial_server.rs
index b6ed7a123..ad16ab6dc 100644
--- a/tutorial/rs/src/bin/tutorial_server.rs
+++ b/tutorial/rs/src/bin/tutorial_server.rs
@@ -144,7 +144,7 @@ impl CalculatorSyncHandler for CalculatorServer {
} else {
Ok(num1 / num2)
}
- },
+ }
_ => {
let op_val: i32 = op.into();
Err(InvalidOperation {