mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Add documentation for channel macro
This commit is contained in:
parent
2c187eb3ae
commit
ec0e81f0ae
1 changed files with 58 additions and 0 deletions
|
@ -1,3 +1,61 @@
|
|||
/// Creates an implentation of sender which can be used to share an async channel for multiple message types.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// struct D;
|
||||
/// struct A;
|
||||
///
|
||||
/// enum Msg {
|
||||
/// FirstType(D),
|
||||
/// SecondType(A)
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let (tx, rx) = channel::<Msg>();
|
||||
///
|
||||
/// let d_sender = DSender::create(tx.clone());
|
||||
/// let a_sender = ASender::create(tx.clone());
|
||||
/// subscribe(d_sender.clone());
|
||||
/// subscribe2(d_sender.clone());
|
||||
/// subscribe3(a_sender.clone());
|
||||
//
|
||||
/// let mut i = 0;
|
||||
//
|
||||
/// for m in rx {
|
||||
/// i += 1;
|
||||
/// match m {
|
||||
/// Msg::FirstType(_) => println!("m: D {}", i),
|
||||
/// Msg::SecondType(_) => println!("m: A {}", i)
|
||||
/// };
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// fn subscribe(sender: DSender) {
|
||||
/// thread::spawn(move|| {
|
||||
/// sender.send(D).unwrap();
|
||||
/// });
|
||||
/// }
|
||||
/// fn subscribe2(sender: DSender) {
|
||||
/// thread::spawn(move|| {
|
||||
/// thread::sleep(time::Duration::from_millis(10));
|
||||
/// sender.send(D).unwrap();
|
||||
/// });
|
||||
/// }
|
||||
/// fn subscribe3(sender: ASender) {
|
||||
/// thread::spawn(move|| {
|
||||
/// sender.send(A).unwrap();
|
||||
/// });
|
||||
/// }
|
||||
/// implement_sender!(name => DSender,
|
||||
/// wrap => D,
|
||||
/// with => Msg,
|
||||
/// variant => FirstType)
|
||||
/// implement_sender!(name => ASender,
|
||||
/// wrap => A,
|
||||
/// with => Msg,
|
||||
/// variant => SecondType)
|
||||
/// ```
|
||||
macro_rules! implement_sender {
|
||||
(name => $name:ident,
|
||||
wrap => $wrap_type:ident,
|
||||
|
|
Loading…
Reference in a new issue