mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-08 10:02:55 +00:00
feat: Add ability to construct a SegmentId from raw bytes (#24)
This allows a `SegmentId` to be constructed from a `[u8; 16]` byte array. It also adds a `impl Default for SegementId`, which defaults to all nulls
This commit is contained in:
@@ -21,6 +21,14 @@ use uuid::Uuid;
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct SegmentId(Uuid);
|
||||
|
||||
impl Default for SegmentId {
|
||||
fn default() -> Self {
|
||||
Self(Uuid::from_bytes(uuid::Bytes::from([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
])))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
static AUTO_INC_COUNTER: Lazy<atomic::AtomicUsize> = Lazy::new(atomic::AtomicUsize::default);
|
||||
|
||||
@@ -84,6 +92,10 @@ impl SegmentId {
|
||||
pub fn from_uuid_string(uuid_string: &str) -> Result<SegmentId, SegmentIdParseError> {
|
||||
FromStr::from_str(uuid_string)
|
||||
}
|
||||
|
||||
pub fn from_bytes(uuid_bytes: [u8; 16]) -> SegmentId {
|
||||
SegmentId(Uuid::from_bytes(uuid::Bytes::from(uuid_bytes)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Error type used when parsing a `SegmentId` from a string fails.
|
||||
|
||||
Reference in New Issue
Block a user