pub struct Document {
pub id: String,
pub content: Cow<'static, str>,
pub metadata: Metadata,
pub content_hash: Option<String>,
pub created_at: DateTime<Utc>,
}Expand description
Core document type optimized for Rust patterns
Uses Cow<str> for flexible string handling:
- Borrowed strings when possible (zero-copy)
- Owned strings when necessary (after processing)
Fields§
§id: StringUnique document identifier
content: Cow<'static, str>Document content - uses Cow for efficient string handling
metadata: MetadataDocument metadata
content_hash: Option<String>Content hash for deduplication
created_at: DateTime<Utc>Document creation timestamp
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(content: impl Into<Cow<'static, str>>) -> Self
pub fn new(content: impl Into<Cow<'static, str>>) -> Self
Create a new document with generated ID
Sourcepub fn with_id(
id: impl Into<String>,
content: impl Into<Cow<'static, str>>,
) -> Self
pub fn with_id( id: impl Into<String>, content: impl Into<Cow<'static, str>>, ) -> Self
Create document with specific ID
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add metadata using builder pattern
Sourcepub fn with_metadata_map(self, metadata: Metadata) -> Self
pub fn with_metadata_map(self, metadata: Metadata) -> Self
Add multiple metadata entries
Sourcepub fn with_content_hash(self) -> Self
pub fn with_content_hash(self) -> Self
Generate content hash for deduplication
Sourcepub fn content_str(&self) -> &str
pub fn content_str(&self) -> &str
Get content as string slice
Sourcepub fn content_length(&self) -> usize
pub fn content_length(&self) -> usize
Get content length in characters
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more