Skip to main content

morphir_core/ir/classic/
documented.rs

1//! Classic IR Documented wrapper
2//!
3//! Documentation wrapper for the Classic Morphir IR format.
4
5use serde::{Deserialize, Serialize};
6
7/// Type that represents a documented value.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub struct Documented<A> {
10    pub doc: String,
11    pub value: A,
12}
13
14impl<A> Documented<A> {
15    /// Create a new documented value.
16    pub fn new(doc: impl Into<String>, value: A) -> Self {
17        Self {
18            doc: doc.into(),
19            value,
20        }
21    }
22
23    /// Map over the value inside Documented.
24    pub fn map<B, F: FnOnce(A) -> B>(self, f: F) -> Documented<B> {
25        Documented {
26            doc: self.doc,
27            value: f(self.value),
28        }
29    }
30}