~jpastuszek/nanotemplate

20f6a7a507954a8a0d2c62735a60bb28cc365005 — Jakub Pastuszek 10 months ago 16e6ca2
ref to String
1 files changed, 26 insertions(+), 0 deletions(-)

M src/lib.rs
M src/lib.rs => src/lib.rs +26 -0
@@ 75,6 75,27 @@ impl<'k, 'v> PlaceholderValuePair<'k, 'v> for &(&'k str, &'v str) {
    }
}


impl<'k, 'v> PlaceholderValuePair<'k, 'v> for (&'k str, &'v String) {
    fn get_placeholder(&self) -> &'k str {
        self.0
    }

    fn get_value(&self) -> &'v str {
        &self.1
    }
}

impl<'k, 'v> PlaceholderValuePair<'k, 'v> for &(&'k str, &'v String) {
    fn get_placeholder(&self) -> &'k str {
        self.0
    }

    fn get_value(&self) -> &'v str {
        &self.1
    }
}

impl<'t> PlaceholderValuePair<'t, 't> for [&'t str; 2] {
    fn get_placeholder(&self) -> &'t str {
        self[0]


@@ 214,6 235,11 @@ mod tests {
    }

    #[test]
    fn test_template_many_vars_slice_string() {
        assert_eq!(&template("{foo} hello {bar} world {baz}", &[("foo", &"1".to_string()), ("bar", &"2".to_string()), ("baz" ,&"3".to_string())]).unwrap(), "1 hello 2 world 3");
    }

    #[test]
    fn test_template_many_vars_slice_array() {
        assert_eq!(&template("{foo} hello {bar} world {baz}", &[["foo", "1"], ["bar", "2"], ["baz" ,"3"]]).unwrap(), "1 hello 2 world 3");
    }