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