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
//!Extractors that provides notification on progress.
//!
//!These are the same as in root module,
//!but allow to notify when each data chunk arrieves
//!with their size
//!
//!## Notifier
//!
//!The trait that describes how to send notification.
//!User may use already existing impls or create own `Notifier`
//!

use std::sync::mpsc as std_mpsc;

///Describes Body download progress
pub trait Notifier {
    ///Sends data over Notifier.
    fn send(&mut self, num: usize);
}

///Noop Notifier.
///
///This one is used by default
pub struct Noop;

impl Notifier for Noop {
    #[inline]
    fn send(&mut self, _: usize) { }
}

impl Notifier for std_mpsc::Sender<usize> {
    #[inline]
    fn send(&mut self, num: usize) {
        let _ = std_mpsc::Sender::send(self, num);
    }
}