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
//! Module that adds fasterxml annotations to generated classes.

use Options;
use backend::Initializer;
use core::errors::Result;
use genco::{Cons, Python, Tokens};
use std::rc::Rc;
use utils::VersionHelper;

#[derive(Debug, Default, Deserialize)]
pub struct Config {}

pub struct Module {
    #[allow(dead_code)]
    config: Config,
}

impl Module {
    pub fn new(config: Config) -> Module {
        Module { config: config }
    }
}

#[derive(Debug, PartialEq, Eq)]
struct Python2VersionHelper {}

impl VersionHelper for Python2VersionHelper {
    fn is_string<'el>(&self, var: Cons<'el>) -> Tokens<'el, Python<'el>> {
        toks!["isinstance(", var, ", unicode)"]
    }
}

impl Initializer for Module {
    type Options = Options;

    fn initialize(&self, options: &mut Options) -> Result<()> {
        options.version_helper = Rc::new(Box::new(Python2VersionHelper {}));

        Ok(())
    }
}