From b152dda75b596788209d79e1f0caf567b3336f3d Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 22 Mar 2017 18:58:09 +0300 Subject: [PATCH] doc test and travis --- .travis.yml | 8 ++++++++ src/lib.rs | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8c91a74 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: rust +rust: + - stable + - beta + - nightly +matrix: + allow_failures: + - rust: nightly diff --git a/src/lib.rs b/src/lib.rs index c90ff1e..7e3ea12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ extern crate futures; extern crate tokio_uds; extern crate tokio_named_pipes; -#[macro_use] extern crate tokio_core; +extern crate tokio_core; #[macro_use] extern crate log; #[cfg(windows)] @@ -20,7 +20,40 @@ use tokio_core::reactor::Handle; #[cfg(windows)] use tokio_named_pipes::NamedPipe; -/// IPC Endpoint (UnixListener or rolling NamedPipe) +/// For testing/examples +pub fn dummy_endpoint() -> String { + extern crate rand; + + let num: u64 = rand::Rng::gen(&mut rand::thread_rng()); + if cfg!(windows) { + format!(r"\\.\pipe\my-pipe-{}", num) + } else { + format!(r"/tmp/my-uds-{}", num) + } +} + +/// Endpoint for IPC transport +/// +/// # Examples +/// +/// ``` +/// extern crate tokio_core; +/// extern crate futures; +/// extern crate parity_tokio_ipc; +/// +/// use parity_tokio_ipc::{Endpoint, dummy_endpoint}; +/// use tokio_core::reactor::Core; +/// use futures::{future, Stream}; +/// +/// fn main() { +/// let core = Core::new().unwrap(); +/// let endpoint = Endpoint::new(dummy_endpoint(), &core.handle()).unwrap(); +/// endpoint.incoming().for_each(|(stream, _)| { +/// println!("Connection received"); +/// future::ok(()) +/// }); +/// } +/// ``` pub struct Endpoint { _path: String, _handle: Handle,