pub struct Document {
pub version: SchemaVersion,
pub creator: Option<String>,
pub root: Element,
}Expand description
A design document: its schema version, the program that wrote it, and the whole XML tree.
Fields§
§version: SchemaVersionThe root element’s version attribute.
creator: Option<String>The root element’s creator attribute, for example OpenRocket 24.12. Absent in files
some other program wrote.
root: ElementThe <openrocket> element, with every attribute and child it was written with.
Implementations§
Source§impl Document
impl Document
Sourcepub fn parse(text: &str) -> Result<Imported<Self>, OrkError>
pub fn parse(text: &str) -> Result<Imported<Self>, OrkError>
Reads a design document from XML text.
Fails when the text is not well-formed XML, when its root is not <openrocket>, or when
the root carries no readable version. Everything else is a warning: a schema version
newer than MAX_KNOWN_MINOR, a missing creator, or a comment (which is dropped).
Blank text between child elements (the indentation OpenRocket writes) is not kept, so
that writing the document back out is free to lay it out again. Text an element holds
beside child elements is kept: OpenRocket writes a simulation <warning> that way.
Sourcepub fn to_xml(&self) -> String
pub fn to_xml(&self) -> String
Writes the document back out as XML.
The result is written in one fixed style rather than byte-identical to the file it was
read from: two-space indentation, attributes in the order they were read, and <tag/> for
an empty element. Reading it again gives an equal Document, which is what makes the
tree lossless.
version and creator are written onto the root, so
changing either changes the file. Everything else comes from root.
This is defined for a document that came from parse. Element’s fields
are public, and a tree built by hand can hold a name that is not an XML name, or nest
deeper than MAX_DEPTH. Writing either gives XML that will not read back.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Document
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.