Skip to content

Convert tarpc::service! function macro to #[tarpc::service] attribute macro #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ os:
script:
- cargo test --all-targets --all-features
- cargo test --doc --all-features
- cargo run --example 2>&1 | grep ' ' | awk '{print $1}' | xargs -L 1 cargo run --all-features --example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep forgetting to update examples before pushing code. This will make that harder. I could make this change outside this pr if you'd like.

16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ use std::io;

// This is the service definition. It looks a lot like a trait definition.
// It defines one RPC, hello, which takes one arg, name, and returns a String.
tarpc::service! {
#[tarpc::service]
trait Service {
/// Returns a greeting for name.
rpc hello(name: String) -> String;
async fn hello(name: String) -> String;
}
```

Expand All @@ -102,9 +103,10 @@ implement it for our Server struct.
#
# // This is the service definition. It looks a lot like a trait definition.
# // It defines one RPC, hello, which takes one arg, name, and returns a String.
# tarpc::service! {
# #[tarpc::service]
# trait Service {
# /// Returns a greeting for name.
# rpc hello(name: String) -> String;
# async fn hello(name: String) -> String;
# }
#
// This is the type that implements the generated Service trait. It is the business logic
Expand Down Expand Up @@ -147,9 +149,10 @@ that uses bincode over TCP.
#
# // This is the service definition. It looks a lot like a trait definition.
# // It defines one RPC, hello, which takes one arg, name, and returns a String.
# tarpc::service! {
# #[tarpc::service]
# trait Service {
# /// Returns a greeting for name.
# rpc hello(name: String) -> String;
# async fn hello(name: String) -> String;
# }
#
# // This is the type that implements the generated Service trait. It is the business logic
Expand Down Expand Up @@ -198,7 +201,6 @@ async fn main() -> io::Result<()> {
}
```


## Service Documentation

Use `cargo doc` as you normally would to see the documentation created for all
Expand Down
15 changes: 6 additions & 9 deletions example-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

#![feature(async_await, proc_macro_hygiene)]
#![feature(async_await)]

// This is the service definition. It looks a lot like a trait definition.
// It defines one RPC, hello, which takes one arg, name, and returns a String.
tarpc::service! {
/// This is the service definition. It looks a lot like a trait definition.
/// It defines one RPC, hello, which takes one arg, name, and returns a String.
#[tarpc::service]
pub trait Service {
/// Returns a greeting for name.
rpc hello(#[serde(default = "default_name")] name: String) -> String;
}

fn default_name() -> String {
"DefaultName".into()
async fn hello(name: String) -> String;
}
6 changes: 5 additions & 1 deletion hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ if [ "$?" == 0 ]; then

try_run "Building ... " cargo build --color=always
try_run "Testing ... " cargo test --color=always
try_run "Doc Test ... " cargo clean && cargo build --tests && rustdoc --test README.md --edition 2018 -L target/debug/deps -Z unstable-options
try_run "Testing with all features enabled ... " cargo test --all-features --color=always
for EXAMPLE in $(cargo run --example 2>&1 | grep ' ' | awk '{print $1}')
do
try_run "Running example \"$EXAMPLE\" ... " cargo run --all-features --example $EXAMPLE
done

fi

Expand Down
18 changes: 18 additions & 0 deletions plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "tarpc-plugins"
version = "0.5.1"
authors = ["Adam Wright <[email protected]>", "Tim Kuehn <[email protected]>"]
edition = "2018"
license = "MIT"
documentation = "https://docs.rs/tarpc-plugins"
homepage = "https://github.com/google/tarpc"
Expand All @@ -11,6 +12,9 @@ categories = ["asynchronous", "network-programming"]
readme = "../README.md"
description = "Proc macros for tarpc."

[features]
serde1 = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be enabled by default

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to get this to work. Unfortunately, it presents a footgun for users who don't need serde but don't opt out of the default features. They'll get the following errors if they don't have serde in their Cargo.toml dependencies:

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> example-service/src/lib.rs:11:1
   |
11 | #[tarpc::service]
   | ^^^^^^^^^^^^^^^^^
   |
   = note: for more information, see https://github.com/rust-lang/rust/issues/27812
   = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> example-service/src/lib.rs:11:1
   |
11 | #[tarpc::service]
   | ^^^^^^^^^^^^^^^^^
   |
   = note: for more information, see https://github.com/rust-lang/rust/issues/27812
   = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> example-service/src/lib.rs:11:1
   |
11 | #[tarpc::service]
   | ^^^^^^^^^^^^^^^^^
   |
   = note: for more information, see https://github.com/rust-lang/rust/issues/27812
   = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> example-service/src/lib.rs:11:1
   |
11 | #[tarpc::service]
   | ^^^^^^^^^^^^^^^^^
   |
   = note: for more information, see https://github.com/rust-lang/rust/issues/27812
   = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> example-service/src/lib.rs:14:20
   |
14 |     async fn hello(name: String) -> String;
   |                    ^^^^
   |
   = note: for more information, see https://github.com/rust-lang/rust/issues/27812
   = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> example-service/src/lib.rs:14:37
   |
14 |     async fn hello(name: String) -> String;
   |                                     ^^^^^^
   |
   = note: for more information, see https://github.com/rust-lang/rust/issues/27812
   = help: add `#![feature(rustc_private)]` to the crate attributes to enable

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0658`.
error: Could not compile `tarpc-example-service`.

This comment has more context.


[badges]
travis-ci = { repository = "google/tarpc" }

Expand All @@ -22,3 +26,17 @@ proc-macro2 = "0.4"

[lib]
proc-macro = true

[dev-dependencies]
bincode = "1"
bincode-transport = { package = "tarpc-bincode-transport", version = "0.7", path = "../bincode-transport" }
bytes = { version = "0.4", features = ["serde"] }
futures-preview = { version = "0.3.0-alpha.17", features = ["compat"] }
humantime = "1.0"
env_logger = "0.6"
serde = { version = "1.0", features = ["derive"] }
tarpc = { path = "../tarpc" }
tokio = "0.1"
tokio-executor = "0.1"
tokio-tcp = "0.1"
pin-utils = "0.1.0-alpha.4"
Loading