changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / rust/lib/obj/src/object/doc.rs

changeset 698: 96958d3eb5b0
parent: 8e94959e96bd
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 //! obj::doc
2 //!
3 //! Document object types
4 use crate::Objective;
5 use serde::{Deserialize, Serialize};
6 use std::{fmt, str::FromStr};
7 
8 /// Document object
9 #[derive(Serialize, Deserialize, Debug, Hash, PartialEq)]
10 pub struct Doc {
11  pub extension: DocExtension,
12 }
13 
14 impl Doc {
15  pub fn new(ext: &str) -> Self {
16  Doc {
17  extension: DocExtension::from_str(ext).unwrap(),
18  }
19  }
20 }
21 
22 impl Default for Doc {
23  fn default() -> Self {
24  Doc::new("org")
25  }
26 }
27 
28 impl Objective for Doc {}
29 
30 /// Document extensions. Use in filenames and IO matching in some
31 /// cases
32 #[derive(Serialize, Deserialize, Debug, Hash, PartialEq)]
33 pub enum DocExtension {
34  OrgExt,
35  PdfExt,
36  HtmlExt,
37  None,
38 }
39 
40 impl fmt::Display for DocExtension {
41  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42  match self {
43  DocExtension::OrgExt => write!(f, "org"),
44  DocExtension::PdfExt => write!(f, "pdf"),
45  DocExtension::HtmlExt => write!(f, "html"),
46  DocExtension::None => write!(f, ""),
47  }
48  }
49 }
50 
51 impl FromStr for DocExtension {
52  type Err = ();
53  fn from_str(input: &str) -> Result<DocExtension, Self::Err> {
54  match input {
55  "org" => Ok(DocExtension::OrgExt),
56  "pdf" => Ok(DocExtension::PdfExt),
57  "html" => Ok(DocExtension::HtmlExt),
58  "" => Ok(DocExtension::None),
59  _ => Err(()),
60  }
61  }
62 }