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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Stable identifiers for stored vectors.
//!
//! A [`VectorId`] is either a compact 64-bit integer or an opaque byte key, so
//! a caller can use whichever id space their data already has (a row id, a
//! content hash, a UUID's bytes) without the iqdb spine imposing one.
use fmt;
use crateIqdbError;
/// A stable identifier for a stored vector.
///
/// Either a compact [`U64`](VectorId::U64) integer id or an opaque
/// [`Bytes`](VectorId::Bytes) key. Build a `U64` id with
/// [`From<u64>`](VectorId::from); build a `Bytes` id with
/// [`TryFrom<Vec<u8>>`](VectorId::try_from), which rejects an empty key.
///
/// # Examples
///
/// ```
/// use iqdb_types::VectorId;
///
/// let numeric = VectorId::from(7u64);
/// assert_eq!(numeric, VectorId::U64(7));
///
/// let key = VectorId::try_from(vec![0xde, 0xad]).expect("non-empty key");
/// assert_eq!(key, VectorId::Bytes(vec![0xde, 0xad].into_boxed_slice()));
///
/// // An empty byte key is rejected.
/// assert!(VectorId::try_from(Vec::new()).is_err());
/// ```
/// Operator-facing rendering: `U64` is the decimal integer; `Bytes` is
/// lowercase hex with no prefix and no separators (so a 32-byte
/// SHA-256-shaped id renders as 64 hex characters). `Debug` keeps the
/// `Bytes([...])` shape for in-source troubleshooting; `Display` is the
/// shape that lands in operator-facing logs and error messages.
///
/// # Examples
///
/// ```
/// use iqdb_types::VectorId;
///
/// assert_eq!(VectorId::from(7u64).to_string(), "7");
///
/// let key = VectorId::try_from(vec![0xde, 0xad, 0xbe, 0xef]).expect("non-empty");
/// assert_eq!(key.to_string(), "deadbeef");
/// ```