Debian Codegraph @

.cargo/vendor/onenote_parser/src/one/property/paragraph_alignment.rs

raw
1 use crate::errors::{ErrorKind, Result};
2 use crate::one::property::PropertyType;
3 use crate::onestore::object::Object;
4
5 /// A paragraph's alignment.
6 ///
7 /// See [\[MS-ONE\] 2.3.94].
8 ///
9 /// [\[MS-ONE\] 2.3.94]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/36edb135-5e8e-400f-9394-82853d662d90
10 #[allow(missing_docs)]
11 #[derive(Debug, Copy, Clone, PartialEq)]
12 pub enum ParagraphAlignment {
13 Unknown,
14 Left,
15 Center,
16 Right,
17 }
18
19 impl ParagraphAlignment {
20 pub(crate) fn parse(object: &Object) -> Result<Option<ParagraphAlignment>> {
21 let value = match object.props().get(PropertyType::ParagraphAlignment) {
22 Some(value) => value.to_u8().ok_or_else(|| {
23 ErrorKind::MalformedOneNoteFileData("page size is not a u8".into())
24 })?,
25 None => return Ok(None),
26 };
27
28 Ok(Some(match value {
29 0 => ParagraphAlignment::Left,
30 1 => ParagraphAlignment::Center,
31 2 => ParagraphAlignment::Right,
32 _ => ParagraphAlignment::Unknown,
33 }))
34 }
35 }
36
37 impl Default for ParagraphAlignment {
38 fn default() -> Self {
39 ParagraphAlignment::Left
40 }
41 }