diff options
author | Ferris Tseng <ferristseng@fastmail.fm> | 2021-02-23 23:26:48 -0500 |
---|---|---|
committer | Ferris Tseng <ferristseng@fastmail.fm> | 2021-02-23 23:26:48 -0500 |
commit | 1dbab207ece88a47f92b951a83ef8d95dc40fe1c (patch) | |
tree | e93fe962328364bde9e5ac2bbdb80c62746ff28a | |
parent | fd4a1e309d565d88c5e394e9e8411f4968499d18 (diff) |
migrate examples to separate crate
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | ipfs-api-examples/Cargo.toml | 28 | ||||
-rw-r--r-- | ipfs-api-examples/examples/add_file.rs (renamed from ipfs-api/examples/add_file.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/add_tar.rs (renamed from ipfs-api/examples/add_tar.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/bootstrap_default.rs (renamed from ipfs-api/examples/bootstrap_default.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/config.rs (renamed from ipfs-api/examples/config.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/dag.rs (renamed from ipfs-api/examples/dag.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/default_config.json (renamed from ipfs-api/examples/default_config.json) | 0 | ||||
-rw-r--r-- | ipfs-api-examples/examples/dns.rs (renamed from ipfs-api/examples/dns.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/get_commands.rs (renamed from ipfs-api/examples/get_commands.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/get_stats.rs (renamed from ipfs-api/examples/get_stats.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/get_swarm.rs (renamed from ipfs-api/examples/get_swarm.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/get_version.rs (renamed from ipfs-api/examples/get_version.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/log_tail.rs (renamed from ipfs-api/examples/log_tail.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/mfs.rs (renamed from ipfs-api/examples/mfs.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/ping_peer.rs (renamed from ipfs-api/examples/ping_peer.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/pubsub.rs (renamed from ipfs-api/examples/pubsub.rs) | 14 | ||||
-rw-r--r-- | ipfs-api-examples/examples/replace_config.rs (renamed from ipfs-api/examples/replace_config.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/examples/resolve_name.rs (renamed from ipfs-api/examples/resolve_name.rs) | 5 | ||||
-rw-r--r-- | ipfs-api-examples/src/lib.rs | 25 |
20 files changed, 92 insertions, 55 deletions
@@ -2,7 +2,8 @@ members = [ "ipfs-api", - "ipfs-api-prelude", + "ipfs-api-examples", "ipfs-api-backend-actix", - "ipfs-api-backend-hyper" + "ipfs-api-backend-hyper", + "ipfs-api-prelude", ] diff --git a/ipfs-api-examples/Cargo.toml b/ipfs-api-examples/Cargo.toml new file mode 100644 index 0000000..531dc53 --- /dev/null +++ b/ipfs-api-examples/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "ipfs-api-examples" +description = "Examples for IPFS HTTP API clients" +authors = ["Ferris Tseng <ferristseng@fastmail.fm>"] +edition = "2018" +documentation = "https://docs.rs/ipfs-api" +repository = "https://github.com/ferristseng/rust-ipfs-api" +keywords = ["ipfs"] +categories = ["filesystem", "web-programming"] +version = "0.1.0" +readme = "../README.md" +license = "MIT OR Apache-2.0" + +[features] +default = ["with-hyper"] +with-hyper = ["ipfs-api-backend-hyper", "tokio-hyper", "tokio-hyper/macros", "tokio-hyper/rt-multi-thread"] +with-actix = ["ipfs-api-backend-actix", "tokio-actix", "actix-rt"] + +[dependencies] +actix-rt = { version = "1.1", optional = true } +futures = "0.3" +ipfs-api-backend-actix = { version = "0.1", path = "../ipfs-api-backend-actix", optional = true } +ipfs-api-backend-hyper = { version = "0.1", path = "../ipfs-api-backend-hyper", optional = true } +tar = "0.4" +tokio-actix = { package = "tokio", version = "1.0", features = ["time"], optional = true } +tokio-hyper = { package = "tokio", version = "1.2", features = ["time"], optional = true } +tokio-stream = { version = "0.1", features = ["time"] } +tracing-subscriber = { version = "0.2", features = ["fmt"] } diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api-examples/examples/add_file.rs index a19e4a2..fc0ab1e 100644 --- a/ipfs-api/examples/add_file.rs +++ b/ipfs-api-examples/examples/add_file.rs @@ -6,13 +6,12 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; use std::fs::File; // Creates an Ipfs client, and adds this source file to Ipfs. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/add_tar.rs b/ipfs-api-examples/examples/add_tar.rs index e20cb1e..0098ded 100644 --- a/ipfs-api/examples/add_tar.rs +++ b/ipfs-api-examples/examples/add_tar.rs @@ -7,14 +7,13 @@ // use futures::TryStreamExt; -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; use std::io::Cursor; use tar::Builder; // Creates an Ipfs client, and adds this source file to Ipfs. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/bootstrap_default.rs b/ipfs-api-examples/examples/bootstrap_default.rs index f693341..f4d83fb 100644 --- a/ipfs-api/examples/bootstrap_default.rs +++ b/ipfs-api-examples/examples/bootstrap_default.rs @@ -6,13 +6,12 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; // Lists clients in bootstrap list, then adds the default list, then removes // them, and readds them. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/config.rs b/ipfs-api-examples/examples/config.rs index 1e0a3c3..a927a58 100644 --- a/ipfs-api/examples/config.rs +++ b/ipfs-api-examples/examples/config.rs @@ -6,12 +6,11 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; // Creates an Ipfs client, read & set config values. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/dag.rs b/ipfs-api-examples/examples/dag.rs index 5632021..be04cb9 100644 --- a/ipfs-api/examples/dag.rs +++ b/ipfs-api-examples/examples/dag.rs @@ -7,13 +7,12 @@ // use futures::TryStreamExt; -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; use std::io::Cursor; // Creates an Ipfs client, and adds this dag object to Ipfs then fetch it back. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/default_config.json b/ipfs-api-examples/examples/default_config.json index 89a87f4..89a87f4 100644 --- a/ipfs-api/examples/default_config.json +++ b/ipfs-api-examples/examples/default_config.json diff --git a/ipfs-api/examples/dns.rs b/ipfs-api-examples/examples/dns.rs index 4a262c9..ea2cf8d 100644 --- a/ipfs-api/examples/dns.rs +++ b/ipfs-api-examples/examples/dns.rs @@ -6,12 +6,11 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; // Creates an Ipfs client, resolves ipfs.io, and lists the contents of it. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/get_commands.rs b/ipfs-api-examples/examples/get_commands.rs index fb019b6..ea5d350 100644 --- a/ipfs-api/examples/get_commands.rs +++ b/ipfs-api-examples/examples/get_commands.rs @@ -6,7 +6,7 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::{response, IpfsClient}; +use ipfs_api_examples::ipfs_api::{response, IpfsApi, IpfsClient}; fn print_recursive(indent: usize, cmd: &response::CommandsResponse) { let cmd_indent = " ".repeat(indent * 4); @@ -32,8 +32,7 @@ fn print_recursive(indent: usize, cmd: &response::CommandsResponse) { // Creates an Ipfs client, and gets a list of available commands from the // Ipfs server. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/get_stats.rs b/ipfs-api-examples/examples/get_stats.rs index f51a9da..f701329 100644 --- a/ipfs-api/examples/get_stats.rs +++ b/ipfs-api-examples/examples/get_stats.rs @@ -6,12 +6,11 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; // Creates an Ipfs client, and gets some stats about the Ipfs server. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/get_swarm.rs b/ipfs-api-examples/examples/get_swarm.rs index 9f30b12..02ea599 100644 --- a/ipfs-api/examples/get_swarm.rs +++ b/ipfs-api-examples/examples/get_swarm.rs @@ -6,13 +6,12 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; // Creates an Ipfs client, and gets information about your local address, and // connected peers. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/get_version.rs b/ipfs-api-examples/examples/get_version.rs index 83c3f90..adc6ee0 100644 --- a/ipfs-api/examples/get_version.rs +++ b/ipfs-api-examples/examples/get_version.rs @@ -6,12 +6,11 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; // Creates an Ipfs client, and gets the version of the Ipfs server. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/log_tail.rs b/ipfs-api-examples/examples/log_tail.rs index e590a61..c9bf309 100644 --- a/ipfs-api/examples/log_tail.rs +++ b/ipfs-api-examples/examples/log_tail.rs @@ -7,12 +7,11 @@ // use futures::{future, TryStreamExt}; -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; // Tails the log of IPFS. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api-examples/examples/mfs.rs index 836e238..e644872 100644 --- a/ipfs-api/examples/mfs.rs +++ b/ipfs-api-examples/examples/mfs.rs @@ -6,7 +6,7 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::{response, IpfsClient}; +use ipfs_api_examples::ipfs_api::{response, IpfsApi, IpfsClient}; use std::fs::File; fn print_stat(stat: response::FilesStatResponse) { @@ -20,8 +20,7 @@ fn print_stat(stat: response::FilesStatResponse) { // Creates an Ipfs client, and makes some calls to the Mfs Api. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/ping_peer.rs b/ipfs-api-examples/examples/ping_peer.rs index eddc3ba..5c5de44 100644 --- a/ipfs-api/examples/ping_peer.rs +++ b/ipfs-api-examples/examples/ping_peer.rs @@ -7,13 +7,12 @@ // use futures::{future, TryStreamExt}; -use ipfs_api::{response::PingResponse, IpfsClient}; +use ipfs_api_examples::ipfs_api::{response::PingResponse, IpfsApi, IpfsClient}; // Creates an Ipfs client, discovers a connected peer, and pings it using the // streaming Api, and by collecting it into a collection. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/pubsub.rs b/ipfs-api-examples/examples/pubsub.rs index 1c6a34c..0311ed7 100644 --- a/ipfs-api/examples/pubsub.rs +++ b/ipfs-api-examples/examples/pubsub.rs @@ -6,13 +6,12 @@ // copied, modified, or distributed except according to those terms. // -#[macro_use] -extern crate futures; - -use futures::{future, FutureExt, StreamExt, TryStreamExt}; -use ipfs_api::IpfsClient; +use futures::{future, select, FutureExt, StreamExt, TryStreamExt}; +use ipfs_api_examples::{ + ipfs_api::{IpfsApi, IpfsClient}, + tokio::time, +}; use std::time::Duration; -use tokio::time; use tokio_stream::wrappers::IntervalStream; static TOPIC: &'static str = "test"; @@ -26,8 +25,7 @@ fn get_client() -> IpfsClient { // Creates an Ipfs client, and simultaneously publishes and reads from a pubsub // topic. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/replace_config.rs b/ipfs-api-examples/examples/replace_config.rs index 0647b38..41c2040 100644 --- a/ipfs-api/examples/replace_config.rs +++ b/ipfs-api-examples/examples/replace_config.rs @@ -6,13 +6,12 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; use std::io::Cursor; // Creates an Ipfs client, and replaces the config file with the default one. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api/examples/resolve_name.rs b/ipfs-api-examples/examples/resolve_name.rs index a419511..ac0a0d5 100644 --- a/ipfs-api/examples/resolve_name.rs +++ b/ipfs-api-examples/examples/resolve_name.rs @@ -6,15 +6,14 @@ // copied, modified, or distributed except according to those terms. // -use ipfs_api::IpfsClient; +use ipfs_api_examples::ipfs_api::{IpfsApi, IpfsClient}; const IPFS_IPNS: &str = "/ipns/ipfs.io"; // Creates an Ipfs client, and resolves the Ipfs domain name, and // publishes a path to Ipns. // -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] +#[ipfs_api_examples::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/ipfs-api-examples/src/lib.rs b/ipfs-api-examples/src/lib.rs new file mode 100644 index 0000000..b3e8c42 --- /dev/null +++ b/ipfs-api-examples/src/lib.rs @@ -0,0 +1,25 @@ +// Copyright 2021 rust-ipfs-api Developers +// +// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or +// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or +// http://opensource.org/licenses/MIT>, at your option. This file may not be +// copied, modified, or distributed except according to those terms. +// + +#[cfg(feature = "with-actix")] +pub use actix_rt::main; + +#[cfg(feature = "with-actix")] +pub use ipfs_api_backend_actix as ipfs_api; + +#[cfg(feature = "with-actix")] +pub use tokio_actix as tokio; // Compatibilty for actix-rt 1.0 + +#[cfg(feature = "with-hyper")] +pub use tokio::main; + +#[cfg(feature = "with-hyper")] +pub use ipfs_api_backend_hyper as ipfs_api; + +#[cfg(feature = "with-hyper")] +pub use tokio_hyper as tokio; |