From 7ae107cf2b89d5e5170d9512586bc529fd0aad97 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 16 Feb 2017 17:36:43 -0800 Subject: [PATCH 1/7] Fix readme for real this time. --- README.md | 38 +++++++++++++++++++------------------- hooks/pre-push | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4c51613..6c21ced 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,12 @@ tarpc = { git = "https://github.com/google/tarpc" } tarpc-plugins = { git = "https://github.com/google/tarpc" } ``` -## Example -```rust +## Example: Sync + +tarpc has two APIs: `sync` for blocking requests and `future` for asynchronous +requests. Here's how to use the sync api. + +```rust,no_run // required by `FutureClient` (not used directly in this example) #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] @@ -53,7 +57,7 @@ extern crate tarpc; extern crate tokio_core; use tarpc::{client, server}; -use tarpc::client::sync::Connect; +use tarpc::client::sync::ClientExt; use tarpc::util::{FirstSocketAddr, Never}; service! { @@ -92,7 +96,7 @@ races! See the `tarpc_examples` package for more examples. Here's the same service, implemented using futures. -```rust +```rust,no_run #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] @@ -162,7 +166,7 @@ Both TLS streams and TCP streams are supported in the same binary when the `tls` However, if you are working with both stream types, ensure that you use the TLS clients with TLS servers and TCP clients with TCP servers. -```rust +```rust,no_run #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] @@ -188,7 +192,7 @@ struct HelloServer; impl FutureService for HelloServer { type HelloFut = Result; - fn hello(&mut self, name: String) -> Self::HelloFut { + fn hello(&self, name: String) -> Self::HelloFut { Ok(format!("Hello, {}!", name)) } } @@ -208,7 +212,7 @@ fn main() { .unwrap(); let options = client::Options::default() .handle(reactor.handle()) - .tls(client::tls::Context::new("foobar.com").unwrap())); + .tls(client::tls::Context::new("foobar.com").unwrap()); reactor.run(FutureClient::connect(addr, options) .map_err(tarpc::Error::from) .and_then(|client| client.hello("Mom".to_string())) @@ -235,7 +239,7 @@ E>`. The error type defaults to `tarpc::util::Never` (a wrapper for `!` which im `std::error::Error`) if no error type is explicitly specified in the `service!` macro invocation. An error type can be specified like so: -```rust +```rust,ignore use tarpc::util::Message; service! { @@ -251,23 +255,19 @@ the macro automatically chooses `tarpc::util::Never` as the error type. The above declaration would produce the following synchronous service trait: -```rust -impl SyncService for HelloServer { - fn hello(&self, name: String) -> Result { - Ok(format!("Hello, {}!", name)) - } +```rust,ignore +trait SyncService { + fn hello(&self, name: String) -> Result; } ``` and the following future-based trait: -```rust -impl FutureService for HelloServer { - type HelloFut = Result; +```rust,ignore +trait FutureService for HelloServer { + type HelloFut = IntoFutue; - fn hello(&mut self, name: String) -> Self::HelloFut { - Ok(format!("Hello, {}!", name)) - } + fn hello(&mut self, name: String) -> Self::HelloFut; } ``` diff --git a/hooks/pre-push b/hooks/pre-push index b3ddbfe..c156b77 100755 --- a/hooks/pre-push +++ b/hooks/pre-push @@ -123,7 +123,7 @@ else printf "${SUCCESS}\n" fi - run_cargo build + run_cargo build run_cargo test fi From 77638b388d31b3835b16e5e2cb7cd2be101ad37a Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 16 Feb 2017 17:53:06 -0800 Subject: [PATCH 2/7] Have travis test README with rustdoc. Yay! --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f240e47..795443d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,8 @@ before_script: script: - | travis-cargo build && travis-cargo test && travis-cargo bench && - travis-cargo build -- --features tls && travis-cargo test -- --features tls && travis-cargo bench -- --features tls + travis-cargo build -- --features tls && travis-cargo test -- --features tls && travis-cargo bench -- --features tls && + rustdoc --test README.md -L target/debug/deps -L target/debug after_success: - travis-cargo coveralls --no-sudo From db9c23058d5aeedc7fdfcdd5f71f15c167196f59 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 16 Feb 2017 17:53:59 -0800 Subject: [PATCH 3/7] Dumb thing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c21ced..fea342b 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ trait SyncService { and the following future-based trait: ```rust,ignore -trait FutureService for HelloServer { +trait FutureService { type HelloFut = IntoFutue; fn hello(&mut self, name: String) -> Self::HelloFut; From fea8d5eb1da846abce5354e26ba67843882dbf5e Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 16 Feb 2017 17:57:17 -0800 Subject: [PATCH 4/7] I hate READMEs. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fea342b..34f12b0 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ and the following future-based trait: ```rust,ignore trait FutureService { - type HelloFut = IntoFutue; + type HelloFut = IntoFuture; fn hello(&mut self, name: String) -> Self::HelloFut; } From bceaea1206ef0d44204eaeee39cc53f6e69b9336 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 16 Feb 2017 20:18:46 -0800 Subject: [PATCH 5/7] .travis.yml: Do tls tests, then rustdoc tests, then regular tests --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 795443d..fe53702 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,9 +21,9 @@ before_script: script: - | - travis-cargo build && travis-cargo test && travis-cargo bench && travis-cargo build -- --features tls && travis-cargo test -- --features tls && travis-cargo bench -- --features tls && - rustdoc --test README.md -L target/debug/deps -L target/debug + rustdoc --test README.md -L target/debug/deps -L target/debug && + travis-cargo build && travis-cargo test && travis-cargo bench after_success: - travis-cargo coveralls --no-sudo From 8faba59d66942bf981310cac678b595dc506c6d4 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 16 Feb 2017 20:51:57 -0800 Subject: [PATCH 6/7] Fix tabs in pre-push, and remove dead code in readme --- README.md | 6 ++-- hooks/pre-push | 92 +++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 34f12b0..515a2a5 100644 --- a/README.md +++ b/README.md @@ -43,18 +43,16 @@ tarpc-plugins = { git = "https://github.com/google/tarpc" } ## Example: Sync -tarpc has two APIs: `sync` for blocking requests and `future` for asynchronous -requests. Here's how to use the sync api. +tarpc has two APIs: `sync` for blocking code and `future` for asynchronous +code. Here's how to use the sync api. ```rust,no_run // required by `FutureClient` (not used directly in this example) #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] -extern crate futures; #[macro_use] extern crate tarpc; -extern crate tokio_core; use tarpc::{client, server}; use tarpc::client::sync::ClientExt; diff --git a/hooks/pre-push b/hooks/pre-push index 0c0eca3..a8a4975 100755 --- a/hooks/pre-push +++ b/hooks/pre-push @@ -42,15 +42,15 @@ SUCCESS="${GREEN}ok${NC}" printf "${PREFIX} Clean working copy ... " git diff --exit-code &>/dev/null if [ "$?" == 0 ]; then - printf "${SUCCESS}\n" + printf "${SUCCESS}\n" else - if [ "${TARPC_ALLOW_DIRTY}" == "1" ] - then - printf "${SKIPPED}\n" - else - printf "${FAILURE}\n" - exit 1 - fi + if [ "${TARPC_ALLOW_DIRTY}" == "1" ] + then + printf "${SKIPPED}\n" + else + printf "${FAILURE}\n" + exit 1 + fi fi PREPUSH_RESULT=0 @@ -59,64 +59,64 @@ PREPUSH_RESULT=0 # 1 - cargo command to run (build/test) # 2 - rust toolchain (nightly/stable/beta) run_cargo() { - if [ "$1" == "build" ]; then - VERB=Building + if [ "$1" == "build" ]; then + VERB=Building elif [ "$1" == "test" ]; then - VERB=Testing + VERB=Testing else VERB=Benching - fi - if [ "$2" != "" ]; then - printf "${PREFIX} $VERB on $2... " + fi + if [ "$2" != "" ]; then + printf "${PREFIX} $VERB on $2... " if [ "$2" != "nightly" ]; then rustup run $2 cargo $1 &>/dev/null else rustup run nightly cargo $1 --features unstable &>/dev/null rustup run nightly cargo $1 --features unstable,tls &>/dev/null fi - else - printf "${PREFIX} $VERB... " - cargo $1 &>/dev/null - cargo $1 --features tls &>/dev/null - fi - if [ "$?" != "0" ]; then - printf "${FAILURE}\n" - PREPUSH_RESULT=1 - else - printf "${SUCCESS}\n" - fi + else + printf "${PREFIX} $VERB... " + cargo $1 &>/dev/null + cargo $1 --features tls &>/dev/null + fi + if [ "$?" != "0" ]; then + printf "${FAILURE}\n" + PREPUSH_RESULT=1 + else + printf "${SUCCESS}\n" + fi } TOOLCHAIN_RESULT=0 check_toolchain() { - printf "${PREFIX} Checking for $1 toolchain ... " - if [[ $(rustup toolchain list) =~ $1 ]]; then - printf "${SUCCESS}\n" - else - TOOLCHAIN_RESULT=1 - PREPUSH_RESULT=1 - printf "${FAILURE}\n" - fi + printf "${PREFIX} Checking for $1 toolchain ... " + if [[ $(rustup toolchain list) =~ $1 ]]; then + printf "${SUCCESS}\n" + else + TOOLCHAIN_RESULT=1 + PREPUSH_RESULT=1 + printf "${FAILURE}\n" + fi } printf "${PREFIX} Checking for rustup or current toolchain directive... " command -v rustup &>/dev/null if [ "$?" == 0 ] && [ "${TARPC_USE_CURRENT_TOOLCHAIN}" == "" ]; then - printf "${SUCCESS}\n" + printf "${SUCCESS}\n" - check_toolchain stable - check_toolchain beta - check_toolchain nightly - if [ ${TOOLCHAIN_RESULT} == 1 ]; then - exit 1 - fi + check_toolchain stable + check_toolchain beta + check_toolchain nightly + if [ ${TOOLCHAIN_RESULT} == 1 ]; then + exit 1 + fi - run_cargo build stable - run_cargo build beta - run_cargo build nightly + run_cargo build stable + run_cargo build beta + run_cargo build nightly - # We still rely on some nightly stuff for tests - run_cargo test nightly + # We still rely on some nightly stuff for tests + run_cargo test nightly else if [ "${TARPC_USE_CURRENT_TOOLCHAIN}" == "" ]; then printf "${YELLOW}NOT FOUND${NC}\n" @@ -126,7 +126,7 @@ else fi run_cargo build - run_cargo test + run_cargo test run_cargo bench fi From c7831e8aa648be1e6e518affc85a84e78a92c7c4 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 16 Feb 2017 20:56:04 -0800 Subject: [PATCH 7/7] More spacing stuff --- hooks/pre-push | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/hooks/pre-push b/hooks/pre-push index a8a4975..1ad8b55 100755 --- a/hooks/pre-push +++ b/hooks/pre-push @@ -68,12 +68,12 @@ run_cargo() { fi if [ "$2" != "" ]; then printf "${PREFIX} $VERB on $2... " - if [ "$2" != "nightly" ]; then - rustup run $2 cargo $1 &>/dev/null - else - rustup run nightly cargo $1 --features unstable &>/dev/null - rustup run nightly cargo $1 --features unstable,tls &>/dev/null - fi + if [ "$2" != "nightly" ]; then + rustup run $2 cargo $1 &>/dev/null + else + rustup run nightly cargo $1 --features unstable &>/dev/null + rustup run nightly cargo $1 --features unstable,tls &>/dev/null + fi else printf "${PREFIX} $VERB... " cargo $1 &>/dev/null @@ -118,14 +118,14 @@ if [ "$?" == 0 ] && [ "${TARPC_USE_CURRENT_TOOLCHAIN}" == "" ]; then # We still rely on some nightly stuff for tests run_cargo test nightly else - if [ "${TARPC_USE_CURRENT_TOOLCHAIN}" == "" ]; then - printf "${YELLOW}NOT FOUND${NC}\n" - printf "${WARNING} Falling back to current toolchain: $(rustc -V)\n" - else - printf "${SUCCESS}\n" - fi + if [ "${TARPC_USE_CURRENT_TOOLCHAIN}" == "" ]; then + printf "${YELLOW}NOT FOUND${NC}\n" + printf "${WARNING} Falling back to current toolchain: $(rustc -V)\n" + else + printf "${SUCCESS}\n" + fi - run_cargo build + run_cargo build run_cargo test run_cargo bench fi