1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! [`IntoDoc`] trait and its companion derive.
//!
//! The `derive` cargo feature enables `#[derive(IntoDoc)]`, which
//! emits an `IntoDoc` impl that reads fields off a user-owned struct
//! and writes them into a freshly-allocated [`Doc`]. Field-level
//! `#[zvec(...)]` attributes pick the primary key, override field
//! names, skip fields, and disambiguate collection types that the
//! derive can't map on its own (e.g. `Vec<f32>`).
//!
//! ```no_run
//! # #[cfg(feature = "derive")]
//! # fn main() -> zvec::Result<()> {
//! use zvec::{Doc, IntoDoc};
//!
//! #[derive(IntoDoc)]
//! struct Article {
//! #[zvec(pk)]
//! id: String,
//! title: String,
//! #[zvec(vector_fp32)]
//! embedding: Vec<f32>,
//! summary: Option<String>,
//! }
//!
//! let a = Article {
//! id: "a".into(),
//! title: "Hello".into(),
//! embedding: vec![0.1, 0.2, 0.3],
//! summary: None,
//! };
//! let _doc: Doc = a.into_doc()?;
//! # Ok(()) }
//! # #[cfg(not(feature = "derive"))]
//! # fn main() {}
//! ```
use crateDoc;
use crateResult;
/// Convert `&self` into a freshly-allocated [`Doc`].
///
/// Implemented by the `#[derive(IntoDoc)]` macro from the `zvec-derive`
/// crate (enabled via the `derive` cargo feature). You can also
/// implement this manually if the derive's rules don't fit your shape.
///
/// The `into_` prefix here follows the pattern set by `serde::Serialize`
/// rather than the `Into` trait — the conversion is read-only (`&self`)
/// and leaves the source intact.