Skip to main content

xrust/
output.rs

1/*! How to serialise a tree structure.
2*/
3
4use core::fmt;
5use qualname::QName;
6
7/// An output definition. See XSLT v3.0 26 Serialization
8#[derive(Clone, Debug)]
9pub struct OutputDefinition {
10    name: Option<QName>, // TODO: EQName
11    indent: bool,
12    // TODO: all the other myriad output parameters
13}
14
15impl Default for OutputDefinition {
16    fn default() -> Self {
17        Self::new()
18    }
19}
20
21impl OutputDefinition {
22    pub fn new() -> OutputDefinition {
23        OutputDefinition {
24            name: None,
25            indent: false,
26        }
27    }
28    pub fn get_name(&self) -> Option<QName> {
29        self.name.clone()
30    }
31    pub fn set_name(&mut self, name: Option<QName>) {
32        match name {
33            Some(n) => {
34                self.name.replace(n);
35            }
36            None => {
37                self.name = None;
38            }
39        }
40    }
41    pub fn get_indent(&self) -> bool {
42        self.indent
43    }
44    pub fn set_indent(&mut self, ind: bool) {
45        self.indent = ind;
46    }
47}
48impl fmt::Display for OutputDefinition {
49    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50        if self.indent {
51            f.write_str("indent output")
52        } else {
53            f.write_str("do not indent output")
54        }
55    }
56}
57
58/// Directive for how to treat a [Value](crate::value::Value) upon serialisation.
59#[derive(Clone, Debug, PartialEq)]
60pub enum OutputSpec {
61    Normal,
62    Escaped,
63    NoEscape,
64}