ephemeris_documents/spec/
text.rs1use facet::Facet;
4
5use super::Payload;
6use crate::error::DocumentError;
7use crate::line_ending::LineEndingSpec;
8use crate::source::Source;
9use crate::text::{CommentSyntax, DocumentNode, TextDocument};
10
11#[derive(Debug, Clone, Facet)]
13#[facet(deny_unknown_fields)]
14pub struct TextSpec {
15 #[facet(default)]
17 pub comment_syntax: Option<CommentSyntax>,
18 pub nodes: Vec<DocumentNode>,
20 #[facet(default)]
22 pub line_ending: LineEndingSpec,
23}
24
25impl Payload for TextSpec {
26 fn line_ending(&self) -> LineEndingSpec {
27 self.line_ending
28 }
29
30 fn reconcile(&self, source: &Source<'_>) -> Result<Vec<u8>, DocumentError> {
31 let document = TextDocument::new(self.comment_syntax, &self.nodes)?;
32 Ok(source.write(&document.generated(self.comment_syntax)))
33 }
34
35 fn validate(&self) -> Result<(), DocumentError> {
36 TextDocument::new(self.comment_syntax, &self.nodes)?;
37 Ok(())
38 }
39}