From 855c7b15c224cd43fe6fbf310bbe280af8742973 Mon Sep 17 00:00:00 2001 From: wangdl Date: Sun, 7 Jun 2026 19:26:48 +0800 Subject: [PATCH] feat: DOC-FULL-001 ReadingMaterialRef MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rust 只保存 materialId,不区分 KnowledgeSource/TemporaryFile。 Co-Authored-By: Claude Opus 4.7 --- crates/zx_document_core/src/lib.rs | 1 + .../zx_document_core/src/reading_material.rs | 38 +++++++++++++++++++ crates/zx_document_ffi/src/lib.rs | 1 + 3 files changed, 40 insertions(+) create mode 100644 crates/zx_document_core/src/reading_material.rs diff --git a/crates/zx_document_core/src/lib.rs b/crates/zx_document_core/src/lib.rs index 94a1503..cdc78ed 100644 --- a/crates/zx_document_core/src/lib.rs +++ b/crates/zx_document_core/src/lib.rs @@ -11,5 +11,6 @@ pub mod markdown; pub mod material_type; pub mod pdf; pub mod progress; +pub mod reading_material; pub mod search; pub mod text; diff --git a/crates/zx_document_core/src/reading_material.rs b/crates/zx_document_core/src/reading_material.rs new file mode 100644 index 0000000..d257c50 --- /dev/null +++ b/crates/zx_document_core/src/reading_material.rs @@ -0,0 +1,38 @@ +use serde::{Deserialize, Serialize}; + +/// Reference to a reading material. +/// +/// Rust does not know whether this is a KnowledgeSource or TemporaryReadingMaterial. +/// readingTargetType is added by the iOS/API layer. +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, uniffi::Record)] +pub struct ReadingMaterialRef { + pub material_id: String, +} + +impl ReadingMaterialRef { + pub fn new(material_id: impl Into) -> Self { + Self { + material_id: material_id.into(), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_new() { + let r = ReadingMaterialRef::new("src_123"); + assert_eq!(r.material_id, "src_123"); + } + + #[test] + fn test_serde() { + let r = ReadingMaterialRef::new("src_456"); + let json = serde_json::to_string(&r).unwrap(); + assert!(json.contains("src_456")); + let back: ReadingMaterialRef = serde_json::from_str(&json).unwrap(); + assert_eq!(back, r); + } +} diff --git a/crates/zx_document_ffi/src/lib.rs b/crates/zx_document_ffi/src/lib.rs index dd240f8..9c7a2ce 100644 --- a/crates/zx_document_ffi/src/lib.rs +++ b/crates/zx_document_ffi/src/lib.rs @@ -11,6 +11,7 @@ pub use zx_document_core::search::SearchResult; pub use zx_document_core::anchors::NoteAnchor; pub use zx_document_core::progress::ReadingPosition; pub use zx_document_core::events::ReadingEvent; +pub use zx_document_core::reading_material::ReadingMaterialRef; use zx_document_core::blocks as core_blocks;