he_di_derive 0.2.1

Code generation for he_di dependency injection / inversion of control framework
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use he_di_internals::error::Error as DIError;
use std::iter;
use syn::{ self, Path, Ty };

use parser::{ Extractor, ExtractorIterator };

/// If `Ty` is `Ty::Path` return path where `Ty::Path(_, path)`. Else return a `he_di::Error::ExtractError`
impl Extractor<Path> for syn::Ty {
    fn extract(&self) -> Result<ExtractorIterator<Path>, DIError> {
        match *self {
            Ty::Path(_, ref path) => Ok(ExtractorIterator::from(iter::once(path.clone()))),
            _ => Err(DIError::ExtractError(format!("unable to extract Path data from {:?}", self)))
        }
    }
}