-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathmetadata.rs
More file actions
63 lines (54 loc) · 1.77 KB
/
metadata.rs
File metadata and controls
63 lines (54 loc) · 1.77 KB
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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::fmt;
use std::hash::Hash;
use std::hash::Hasher;
use uuid::Version;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
/// Converts a `u8` discriminant back to a [`uuid::Version`].
pub(crate) fn u8_to_version(b: u8) -> VortexResult<Version> {
match b {
0 => Ok(Version::Nil),
1 => Ok(Version::Mac),
2 => Ok(Version::Dce),
3 => Ok(Version::Md5),
4 => Ok(Version::Random),
5 => Ok(Version::Sha1),
6 => Ok(Version::SortMac),
7 => Ok(Version::SortRand),
8 => Ok(Version::Custom),
0xff => Ok(Version::Max),
_ => vortex_bail!("unknown UUID version discriminant: {b}"),
}
}
/// Metadata for the UUID extension type.
///
/// Optionally records which UUID version the column contains (e.g. v4 random, v7
/// sort-random). When `None`, the column may contain any mix of versions.
#[derive(Clone, Debug, Default)]
pub struct UuidMetadata {
/// The UUID version, if known.
pub version: Option<Version>,
}
impl fmt::Display for UuidMetadata {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.version {
None => write!(f, ""),
Some(v) => write!(f, "v{}", v as u8),
}
}
}
// `uuid::Version` derives `PartialEq` but not `Eq` or `Hash`, so we implement these
// manually using the `#[repr(u8)]` discriminant.
impl PartialEq for UuidMetadata {
fn eq(&self, other: &Self) -> bool {
self.version.map(|v| v as u8) == other.version.map(|v| v as u8)
}
}
impl Eq for UuidMetadata {}
impl Hash for UuidMetadata {
fn hash<H: Hasher>(&self, state: &mut H) {
self.version.map(|v| v as u8).hash(state);
}
}