diff options
Diffstat (limited to 'ipfs-api/src/lib.rs')
-rw-r--r-- | ipfs-api/src/lib.rs | 206 |
1 files changed, 140 insertions, 66 deletions
diff --git a/ipfs-api/src/lib.rs b/ipfs-api/src/lib.rs index 503e482..64ea2f4 100644 --- a/ipfs-api/src/lib.rs +++ b/ipfs-api/src/lib.rs @@ -17,78 +17,152 @@ //! ipfs-api = "0.5.0-alpha2" //! ``` //! -//! ## Examples -//! -//! Write a file to IPFS: -//! -//! ```no_run -//! # extern crate hyper; -//! # extern crate ipfs_api; -//! # -//! use hyper::rt::Future; -//! use ipfs_api::IpfsClient; -//! use std::io::Cursor; -//! -//! # fn main() { -//! let client = IpfsClient::default(); -//! let data = Cursor::new("Hello World!"); -//! -//! let req = client -//! .add(data) -//! .map(|res| { -//! println!("{}", res.hash); -//! }) -//! .map_err(|e| eprintln!("{}", e)); -//! -//! hyper::rt::run(req); -//! # } -//! ``` -//! -//! Read a file from IPFS: -//! -//! ```no_run -//! # extern crate futures; -//! # extern crate hyper; -//! # extern crate ipfs_api; -//! # -//! use futures::{Future, Stream}; -//! use ipfs_api::IpfsClient; -//! use std::io::{self, Write}; -//! -//! # fn main() { -//! let client = IpfsClient::default(); -//! -//! let req = client -//! .get("/test/file.json") -//! .concat2() -//! .map(|res| { -//! let out = io::stdout(); -//! let mut out = out.lock(); -//! -//! out.write_all(&res).unwrap(); -//! }) -//! .map_err(|e| eprintln!("{}", e)); -//! -//! hyper::rt::run(req); -//! # } -//! ``` -//! -//! There are also a bunch of examples included in the project, which -//! I used for testing -//! -//! You can run any of the examples with cargo: -//! -//! ```sh -//! $ cargo run -p ipfs-api --example add_file -//! ``` + +#[cfg(feature = "actix")] +extern crate actix_multipart_rfc7578 as actix_multipart; + +/// ## Examples +/// +/// Write a file to IPFS: +/// +/// ```no_run +/// # extern crate actix_web; +/// # extern crate futures; +/// # extern crate ipfs_api; +/// # +/// use futures::future::Future; +/// use ipfs_api::IpfsClient; +/// use std::io::Cursor; +/// +/// # fn main() { +/// let client = IpfsClient::default(); +/// let data = Cursor::new("Hello World!"); +/// +/// let req = client +/// .add(data) +/// .map(|res| { +/// println!("{}", res.hash); +/// }) +/// .map_err(|e| eprintln!("{}", e)); +/// +/// tokio::runtime::current_thread::run(req); +/// # } +/// ``` +/// +/// Read a file from IPFS: +/// +/// ```no_run +/// # extern crate futures; +/// # extern crate actix_web; +/// # extern crate ipfs_api; +/// # +/// use futures::{Future, Stream}; +/// use ipfs_api::IpfsClient; +/// use std::io::{self, Write}; +/// +/// # fn main() { +/// let client = IpfsClient::default(); +/// +/// let req = client +/// .get("/test/file.json") +/// .concat2() +/// .map(|res| { +/// let out = io::stdout(); +/// let mut out = out.lock(); +/// +/// out.write_all(&res).unwrap(); +/// }) +/// .map_err(|e| eprintln!("{}", e)); +/// +/// tokio::runtime::current_thread::run(req); +/// # } +/// ``` +/// +/// There are also a bunch of examples included in the project, which +/// I used for testing +/// +/// You can run any of the examples with cargo: +/// +/// ```sh +/// $ cargo run -p ipfs-api --example add_file +/// ``` +#[cfg(feature = "actix")] +extern crate actix_web; + +/// ## Examples +/// +/// Write a file to IPFS: +/// +/// ```no_run +/// # extern crate hyper; +/// # extern crate ipfs_api; +/// # +/// use hyper::rt::Future; +/// use ipfs_api::IpfsClient; +/// use std::io::Cursor; +/// +/// # fn main() { +/// let client = IpfsClient::default(); +/// let data = Cursor::new("Hello World!"); +/// +/// let req = client +/// .add(data) +/// .map(|res| { +/// println!("{}", res.hash); +/// }) +/// .map_err(|e| eprintln!("{}", e)); +/// +/// hyper::rt::run(req); +/// # } +/// ``` +/// +/// Read a file from IPFS: +/// +/// ```no_run +/// # extern crate futures; +/// # extern crate hyper; +/// # extern crate ipfs_api; +/// # +/// use futures::{Future, Stream}; +/// use ipfs_api::IpfsClient; +/// use std::io::{self, Write}; +/// +/// # fn main() { +/// let client = IpfsClient::default(); +/// +/// let req = client +/// .get("/test/file.json") +/// .concat2() +/// .map(|res| { +/// let out = io::stdout(); +/// let mut out = out.lock(); +/// +/// out.write_all(&res).unwrap(); +/// }) +/// .map_err(|e| eprintln!("{}", e)); +/// +/// hyper::rt::run(req); +/// # } +/// ``` +/// +/// There are also a bunch of examples included in the project, which +/// I used for testing +/// +/// You can run any of the examples with cargo: +/// +/// ```sh +/// $ cargo run -p ipfs-api --example add_file +/// ``` +#[cfg(feature = "hyper")] +extern crate hyper; +#[cfg(feature = "hyper")] +extern crate hyper_multipart_rfc7578 as hyper_multipart; extern crate bytes; #[macro_use] extern crate failure; extern crate futures; extern crate http; -extern crate hyper; -extern crate hyper_multipart_rfc7578 as hyper_multipart; extern crate serde; #[macro_use] extern crate serde_derive; |