1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! This crate implements a minimal abstraction over UNIX domain sockets for
//! the purpose of IPC.  It lets you send both file handles and rust objects
//! between processes.
//!
//! # Example
//!
//! ```rust
//! # use ::serde_ as serde;
//! use std::env;
//! use std::process;
//! use unix_ipc::{channel, Bootstrapper, Receiver, Sender};
//! use serde::{Deserialize, Serialize};
//!
//! const ENV_VAR: &str = "PROC_CONNECT_TO";
//!
//! #[derive(Serialize, Deserialize, Debug)]
//! # #[serde(crate = "serde_")]
//! pub enum Task {
//!     Sum(Vec<i64>, Sender<i64>),
//!     Shutdown,
//! }
//!
//! fn main() {
//!     if let Ok(path) = env::var(ENV_VAR) {
//!         let receiver = Receiver::<Task>::connect(path).unwrap();
//!         loop {
//!             match receiver.recv().unwrap() {
//!                 Task::Sum(values, tx) => {
//!                     tx.send(values.into_iter().sum::<i64>()).unwrap();
//!                 }
//!                 Task::Shutdown => break,
//!             }
//!         }
//!     } else {
//!         let bootstrapper = Bootstrapper::new().unwrap();
//!         let mut child = process::Command::new(env::current_exe().unwrap())
//!             .env(ENV_VAR, bootstrapper.path())
//!             .spawn()
//!             .unwrap();
//!
//!         let (tx, rx) = channel().unwrap();
//!         bootstrapper.send(Task::Sum(vec![23, 42], tx)).unwrap();
//!         println!("sum: {}", rx.recv().unwrap());
//!         bootstrapper.send(Task::Shutdown).unwrap();
//!     }
//! }
//! ```
//!
//! # Feature Flags
//! 
//! All features are enabled by default but a lot can be turned off to
//! cut down on dependencies.  With all default features enabled only
//! the raw types are available.
//!
//! * `serde`: enables serialization and deserialization.
//! * `bootstrap`: adds the `Bootstrapper` type.
//! * `bootstrap-simple`: adds the default `new` constructor to the
//!   bootstrapper.
mod raw_channel;

#[cfg(feature = "bootstrap")]
mod bootstrap;
#[cfg(feature = "serde")]
mod serde;
#[cfg(feature = "serde")]
mod typed_channel;

pub use self::raw_channel::*;

#[cfg(feature = "bootstrap")]
pub use self::bootstrap::*;

#[cfg(feature = "serde")]
pub use self::{serde::*, typed_channel::*};

#[doc(hidden)]
#[cfg(feature = "serde")]
pub use ::serde_ as _serde_ref;