Skip to content
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

Partial effort to upgrade dependencies #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ documentation = "https://docs.rs/anterofit"
license = "MIT OR Apache-2.0"

[dependencies]
crossbeam = "0.2"
crossbeam = "~0.7"
futures = "0.1"
hyper = "0.10.0"
mime = ">= 0.2.2, < 0.3"
parking_lot = "0.3.7"
quick-error = "1.1.0"
parking_lot = "~0.11"
quick-error = "~1.2"
serde = "1.0"
url = "1.0"

serde_json = { version = "1.0", optional = true }
serde-xml-rs = { version = "0.2.1", optional = true }
serde-xml-rs = { version = "~0.4", optional = true }

clippy = { version = ">=0.0, <0.1", optional = true}

Expand Down
31 changes: 21 additions & 10 deletions examples/post_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// If you are using the `rustc-serialize` feature, use `RustcDecodable` and `RustcEncodable`
// instead of `Deserialize` and `Serialize`, respectively.

#[macro_use] extern crate anterofit;
#[macro_use] extern crate serde_derive;
#[macro_use]
extern crate anterofit;
#[macro_use]
extern crate serde_derive;

// The minimum imports needed to get this example working.
//
Expand All @@ -17,7 +19,7 @@ struct Post {
pub userid: Option<u64>,
pub id: u64,
pub title: String,
pub body: String
pub body: String,
}

/// Used to create a new Post.
Expand Down Expand Up @@ -87,12 +89,14 @@ fn main() {

/// Create a new Post.
fn create_post<P: PostService>(post_service: &P) {
let post = post_service.new_post(42, "Hello", "World!")
let post = post_service
.new_post(42, "Hello", "World!")
// If you don't want to block, the return value of exec() can be used as a Future
// to poll for the result. However, it does shadow a couple methods of Future
// so that you don't have to import the trait to use them.
// See the docs of Call for more info.
.exec().block()
.exec()
.block()
.unwrap();

println!("Created post: {:?}", post);
Expand All @@ -101,7 +105,8 @@ fn create_post<P: PostService>(post_service: &P) {
/// Fetch the top 3 posts in the database.
// Service traits can be object-safe
fn fetch_posts(post_service: &PostService) {
let posts = post_service.get_posts()
let posts = post_service
.get_posts()
// Shorthand for .exec().wait(), but executes the request on the current thread.
.exec_here()
.unwrap();
Expand All @@ -112,8 +117,14 @@ fn fetch_posts(post_service: &PostService) {
}

fn user_posts(post_service: &PostService) {
post_service.posts_by_user(1)
post_service
.posts_by_user(1)
// This will be executed asynchronously when the request is completed
.on_complete(|posts| for post in posts { println!("User post: {:?}", post); })
.exec().ignore();
}
.on_complete(|posts| {
for post in posts {
println!("User post: {:?}", post);
}
})
.exec()
.ignore();
}