feat: DOC-FULL-001 ReadingMaterialRef
Rust 只保存 materialId,不区分 KnowledgeSource/TemporaryFile。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
22276bd44e
commit
855c7b15c2
@ -11,5 +11,6 @@ pub mod markdown;
|
|||||||
pub mod material_type;
|
pub mod material_type;
|
||||||
pub mod pdf;
|
pub mod pdf;
|
||||||
pub mod progress;
|
pub mod progress;
|
||||||
|
pub mod reading_material;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|||||||
38
crates/zx_document_core/src/reading_material.rs
Normal file
38
crates/zx_document_core/src/reading_material.rs
Normal file
@ -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<String>) -> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,7 @@ pub use zx_document_core::search::SearchResult;
|
|||||||
pub use zx_document_core::anchors::NoteAnchor;
|
pub use zx_document_core::anchors::NoteAnchor;
|
||||||
pub use zx_document_core::progress::ReadingPosition;
|
pub use zx_document_core::progress::ReadingPosition;
|
||||||
pub use zx_document_core::events::ReadingEvent;
|
pub use zx_document_core::events::ReadingEvent;
|
||||||
|
pub use zx_document_core::reading_material::ReadingMaterialRef;
|
||||||
|
|
||||||
use zx_document_core::blocks as core_blocks;
|
use zx_document_core::blocks as core_blocks;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user