conjure_cp_core/ast/
metadata.rs1use crate::ast::ReturnType;
2use polyquine::Quine;
3use serde::{Deserialize, Serialize};
4use std::fmt::{Debug, Display};
5use std::hash::Hash;
6use uniplate::derive_unplateable;
7
8derive_unplateable!(Metadata);
9
10#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default, Quine)]
11#[path_prefix(conjure_cp::ast)]
12pub struct Metadata {
13 pub clean: bool,
14 pub etype: Option<ReturnType>,
15 #[serde(default, skip_serializing_if = "Option::is_none")]
16 pub span_id: Option<u32>,
17}
18
19impl Metadata {
20 pub fn new() -> Metadata {
21 Metadata {
22 clean: false,
23 etype: None,
24 span_id: None,
25 }
26 }
27
28 pub fn with_span_id(span_id: u32) -> Metadata {
29 Metadata {
30 clean: false,
31 etype: None,
32 span_id: Some(span_id),
33 }
34 }
35
36 pub fn clone_dirty(&self) -> Metadata {
37 Metadata {
38 clean: false,
39 ..self.clone()
40 }
41 }
42}
43
44impl Display for Metadata {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 write!(f, "Metadata")
47 }
48}
49
50impl Hash for Metadata {
51 fn hash<H: std::hash::Hasher>(&self, _state: &mut H) {
52 }
54}