catcolab_document_types/v0/
cell.rs1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
5#[serde(tag = "tag")]
6pub enum NotebookCell<T> {
7 #[serde(rename = "rich-text")]
8 RichText { id: Uuid, content: String },
9 #[serde(rename = "formal")]
10 Formal { id: Uuid, content: T },
11 #[serde(rename = "stem")]
12 Stem { id: Uuid },
13}
14
15pub type Cell<T> = NotebookCell<T>;
16
17#[cfg(feature = "property-tests")]
19pub(crate) mod arbitrary {
20 use super::*;
21 use proptest::prelude::*;
22 use uuid::Uuid;
23
24 fn arb_uuid() -> BoxedStrategy<Uuid> {
25 any::<u128>().prop_map(Uuid::from_u128).boxed()
26 }
27
28 pub fn arb_notebook_cell<T: std::fmt::Debug + 'static>(
30 arb_t: impl Strategy<Value = T> + Clone + 'static,
31 ) -> BoxedStrategy<NotebookCell<T>> {
32 prop_oneof![
33 (arb_uuid(), any::<String>())
34 .prop_map(|(id, content)| NotebookCell::RichText { id, content }),
35 (arb_uuid(), arb_t).prop_map(|(id, content)| NotebookCell::Formal { id, content }),
36 arb_uuid().prop_map(|id| NotebookCell::Stem { id }),
37 ]
38 .boxed()
39 }
40}