diff options
author | Sameer Puri <sameer@users.noreply.github.com> | 2019-02-09 14:34:00 -0600 |
---|---|---|
committer | Sameer Puri <sameer@users.noreply.github.com> | 2019-02-13 18:29:04 -0600 |
commit | 4bdebbf4d1d1edb839eba860b013e3fdb870f66e (patch) | |
tree | 965a5a80b387c0eb719ca568a96a729d9d3f2ade /ipfs-api/examples | |
parent | f125fdbde329095419630e02ebf33d2c73aeced7 (diff) |
Add actix feature for using actix-web
Diffstat (limited to 'ipfs-api/examples')
-rw-r--r-- | ipfs-api/examples/add_file.rs | 11 | ||||
-rw-r--r-- | ipfs-api/examples/add_tar.rs | 13 | ||||
-rw-r--r-- | ipfs-api/examples/bootstrap_default.rs | 19 | ||||
-rw-r--r-- | ipfs-api/examples/dns.rs | 11 | ||||
-rw-r--r-- | ipfs-api/examples/get_commands.rs | 11 | ||||
-rw-r--r-- | ipfs-api/examples/get_stats.rs | 23 | ||||
-rw-r--r-- | ipfs-api/examples/get_swarm.rs | 21 | ||||
-rw-r--r-- | ipfs-api/examples/get_version.rs | 15 | ||||
-rw-r--r-- | ipfs-api/examples/mfs.rs | 19 | ||||
-rw-r--r-- | ipfs-api/examples/ping_peer.rs | 11 | ||||
-rw-r--r-- | ipfs-api/examples/pubsub.rs | 34 | ||||
-rw-r--r-- | ipfs-api/examples/replace_config.rs | 11 | ||||
-rw-r--r-- | ipfs-api/examples/resolve_name.rs | 21 |
13 files changed, 186 insertions, 34 deletions
diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api/examples/add_file.rs index d771966..3d9be49 100644 --- a/ipfs-api/examples/add_file.rs +++ b/ipfs-api/examples/add_file.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -27,5 +30,13 @@ fn main() { .map(|add| println!("added file: {:?}", add)) .map_err(|e| eprintln!("{}", e)); + #[cfg(feature = "hyper")] hyper::rt::run(req); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/add_tar.rs b/ipfs-api/examples/add_tar.rs index 1880712..5d75e28 100644 --- a/ipfs-api/examples/add_tar.rs +++ b/ipfs-api/examples/add_tar.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; extern crate tar; @@ -52,5 +55,13 @@ fn main() { }) .map_err(|e| eprintln!("{}", e)); - hyper::rt::run(req) + #[cfg(feature = "hyper")] + hyper::rt::run(req); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/bootstrap_default.rs b/ipfs-api/examples/bootstrap_default.rs index 6ba9575..bc36952 100644 --- a/ipfs-api/examples/bootstrap_default.rs +++ b/ipfs-api/examples/bootstrap_default.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -42,8 +45,7 @@ fn main() { } }); - hyper::rt::run( - bootstrap + let fut = bootstrap .and_then(|_| { println!(); println!("dropping all bootstrap peers..."); @@ -56,6 +58,15 @@ fn main() { add }) - .map_err(|e| eprintln!("{}", e)), - ); + .map_err(|e| eprintln!("{}", e)); + + #[cfg(feature = "hyper")] + hyper::rt::run(fut); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + fut.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/dns.rs b/ipfs-api/examples/dns.rs index 78b4086..6b3823d 100644 --- a/ipfs-api/examples/dns.rs +++ b/ipfs-api/examples/dns.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -38,5 +41,13 @@ fn main() { }) .map_err(|e| eprintln!("{}", e)); + #[cfg(feature = "hyper")] hyper::rt::run(req); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/get_commands.rs b/ipfs-api/examples/get_commands.rs index b12ffa1..f99167d 100644 --- a/ipfs-api/examples/get_commands.rs +++ b/ipfs-api/examples/get_commands.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -46,5 +49,13 @@ fn main() { .map(|commands| print_recursive(0, &commands)) .map_err(|e| eprintln!("{}", e)); + #[cfg(feature = "hyper")] hyper::rt::run(req); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/get_stats.rs b/ipfs-api/examples/get_stats.rs index 41f2a5c..9107aa3 100644 --- a/ipfs-api/examples/get_stats.rs +++ b/ipfs-api/examples/get_stats.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -54,10 +57,18 @@ fn main() { println!(" version : {}", repo_stats.version); }); - hyper::rt::run( - bitswap_stats - .and_then(|_| bw_stats) - .and_then(|_| repo_stats) - .map_err(|e| eprintln!("{}", e)), - ); + let fut = bitswap_stats + .and_then(|_| bw_stats) + .and_then(|_| repo_stats) + .map_err(|e| eprintln!("{}", e)); + + #[cfg(feature = "hyper")] + hyper::rt::run(fut); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + fut.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/get_swarm.rs b/ipfs-api/examples/get_swarm.rs index 2b9fd73..2b2c238 100644 --- a/ipfs-api/examples/get_swarm.rs +++ b/ipfs-api/examples/get_swarm.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -43,9 +46,17 @@ fn main() { } }); - hyper::rt::run( - local - .and_then(|_| connected) - .map_err(|e| eprintln!("{}", e)), - ); + let fut = local + .and_then(|_| connected) + .map_err(|e| eprintln!("{}", e)); + + #[cfg(feature = "hyper")] + hyper::rt::run(fut); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + fut.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/get_version.rs b/ipfs-api/examples/get_version.rs index 41a4ee5..6fb9c7e 100644 --- a/ipfs-api/examples/get_version.rs +++ b/ipfs-api/examples/get_version.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -23,5 +26,15 @@ fn main() { .version() .map(|version| println!("version: {:?}", version.version)); - hyper::rt::run(req.map_err(|e| eprintln!("{}", e))); + let fut = req.map_err(|e| eprintln!("{}", e)); + + #[cfg(feature = "hyper")] + hyper::rt::run(fut); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + fut.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs index 8bea192..97d1824 100644 --- a/ipfs-api/examples/mfs.rs +++ b/ipfs-api/examples/mfs.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -46,7 +49,7 @@ fn main() { let file_rm = client.files_rm("/test", true); - hyper::rt::run( + let fut = mkdir .and_then(|_| { println!("making dirs /test/does/not/exist/yet..."); @@ -78,6 +81,16 @@ fn main() { file_rm }) .map(|_| println!("done!")) - .map_err(|e| eprintln!("{}", e)), - ) + .map_err(|e| eprintln!("{}", e)) + ; + + #[cfg(feature = "hyper")] + hyper::rt::run(fut); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + fut.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/ping_peer.rs b/ipfs-api/examples/ping_peer.rs index 1d32210..c60e895 100644 --- a/ipfs-api/examples/ping_peer.rs +++ b/ipfs-api/examples/ping_peer.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -59,5 +62,13 @@ fn main() { }) .map_err(|e| eprintln!("{}", e)); + #[cfg(feature = "hyper")] hyper::rt::run(req); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/pubsub.rs b/ipfs-api/examples/pubsub.rs index 10ee0c5..39fb25a 100644 --- a/ipfs-api/examples/pubsub.rs +++ b/ipfs-api/examples/pubsub.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; extern crate tokio_timer; @@ -49,7 +52,11 @@ fn main() { println!(); println!("starting task to publish messages to ({})...", TOPIC); + + #[cfg(feature = "hyper")] hyper::rt::run(publish); + #[cfg(feature = "actix")] + actix_web::actix::spawn(publish); }); // This block will execute a future that suscribes to a topic, @@ -61,15 +68,24 @@ fn main() { println!(); println!("waiting for messages on ({})...", TOPIC); - hyper::rt::run( - req.take(5) - .for_each(|msg| { - println!(); - println!("received ({:?})", msg); + let fut = req + .take(5) + .for_each(|msg| { + println!(); + println!("received ({:?})", msg); + + Ok(()) + }) + .map_err(|e| eprintln!("{}", e)); - Ok(()) - }) - .map_err(|e| eprintln!("{}", e)), - ) + #[cfg(feature = "hyper")] + hyper::rt::run(fut); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + fut.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } } diff --git a/ipfs-api/examples/replace_config.rs b/ipfs-api/examples/replace_config.rs index f354386..9c1ec61 100644 --- a/ipfs-api/examples/replace_config.rs +++ b/ipfs-api/examples/replace_config.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -27,5 +30,13 @@ fn main() { .map(|_| println!("replaced file")) .map_err(|e| println!("{}", e)); + #[cfg(feature = "hyper")] hyper::rt::run(req); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } diff --git a/ipfs-api/examples/resolve_name.rs b/ipfs-api/examples/resolve_name.rs index 4bcb648..6d400dc 100644 --- a/ipfs-api/examples/resolve_name.rs +++ b/ipfs-api/examples/resolve_name.rs @@ -6,7 +6,10 @@ // copied, modified, or distributed except according to those terms. // +#[cfg(feature = "actix")] +extern crate actix_web; extern crate futures; +#[cfg(feature = "hyper")] extern crate hyper; extern crate ipfs_api; @@ -40,9 +43,17 @@ fn main() { }) }); - hyper::rt::run( - name_resolve - .and_then(|_| name_publish) - .map_err(|e| eprintln!("{}", e)), - ); + let fut = name_resolve + .and_then(|_| name_publish) + .map_err(|e| eprintln!("{}", e)); + + #[cfg(feature = "hyper")] + hyper::rt::run(fut); + #[cfg(feature = "actix")] + actix_web::actix::run(|| { + fut.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) + }); } |