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
use ron;

use crate::base;
use crate::error::{Error, Result};

pub struct Context {
    root: base::Root,
}

impl Context {
    pub(super) fn root(&self) -> &base::Root {
        &self.root
    }
}

impl Context {
    pub fn from_ron(s: &str) -> Result<Context> {
        ron::from_str(s)
            .map(|root| Context { root })
            .map_err(|error| Error::RonError(error))
    }

    pub fn to_ron(&self) -> Result<String> {
        ron::to_string(&self.root).map_err(|error| Error::RonError(error))
    }
}