bardecoder/decode/
mod.rs

1//! Decode data extracted from an image
2
3mod qr;
4
5pub use self::qr::decoder::{QRDecoder, QRDecoderWithInfo};
6
7/// Decode extracted data into a resulting String
8///
9/// DATA type must equal the output type of the matching [`Extract`] implementation
10///
11/// For convenience and easy pipelining the input for decode is the [`Result`] returned from the extract method.
12/// Implementors should return any Error passed to the decode function as-is.
13///
14/// Pre-implemented Decodes provided by this library that are included in the default [`Decoder`]:
15/// * [`QRDecoder`]
16///
17/// # Example
18/// ```
19/// # extern crate bardecoder;
20/// # use bardecoder::util::qr::{QRData, QRError};
21/// use bardecoder::decode::Decode;
22///
23/// struct MyDecoder {}
24///
25/// impl Decode<QRData, String, QRError> for MyDecoder {
26///     fn decode(&self, data: Result<QRData, QRError>) -> Result<String, QRError> {
27///         // process data here
28/// #        Ok(String::from("ok!"))
29///     }
30/// }
31/// ```
32///
33/// with the corresponding impl Extract being the Example [`here`]
34///
35/// [`Extract`]: ../extract/trait.Extract.html
36/// [`here`]: ../extract/trait.Extract.html
37/// [`Decoder`]: ../struct.Decoder.html
38
39pub trait Decode<DATA, RESULT, ERROR> {
40    /// Does the actual decoding
41    fn decode(&self, data: Result<DATA, ERROR>) -> Result<RESULT, ERROR>;
42}