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
//! Decode data extracted from an image

use failure::Fail;

mod qr;

pub use self::qr::decoder::QRDecoder;

/// Decode extracted data into a resulting String
///
/// DATA type must equal the output type of the matching [`Extract`] implementation
///
/// For convenience and easy pipelining the input for decode is the [`Result`] returned from the extract method.
/// Implementors should return any Error passed to the decode function as-is.
///
/// Pre-implemented Decodes provided by this library that are included in the default [`Decoder`]:
/// * [`QRDecoder`]
///
/// # Example
/// ```
/// # extern crate bardecoder;
/// # use bardecoder::util::qr::{QRData, QRError};
/// use bardecoder::decode::Decode;
///
/// struct MyDecoder {}
///
/// impl Decode<QRData, QRError> for MyDecoder {
///     fn decode(&self, data: Result<QRData, QRError>) -> Result<String, QRError> {
///         // process data here
/// #        Ok(String::from("ok!"))
///     }
/// }
/// ```
///
/// with the corresponding impl Extract being the Example [`here`]
///
/// [`Extract`]: ../extract/trait.Extract.html
/// [`here`]: ../extract/trait.Extract.html
/// [`Decoder`]: ../struct.Decoder.html

pub trait Decode<DATA, ERROR>
where
    ERROR: Fail,
{
    /// Does the actual decoding
    fn decode(&self, data: Result<DATA, ERROR>) -> Result<String, ERROR>;
}