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
use crate::prelude::*;
///
/// PrimaryKey
///
/// Structured primary-key metadata for an entity schema.
///
#[derive(Clone, Debug, Serialize)]
pub struct PrimaryKey {
fields: &'static [&'static str],
source: PrimaryKeySource,
}
impl PrimaryKey {
/// Build one primary-key declaration from ordered field names and source.
#[must_use]
pub const fn new(fields: &'static [&'static str], source: PrimaryKeySource) -> Self {
Self { fields, source }
}
/// Borrow the ordered primary-key field names.
#[must_use]
pub const fn fields(&self) -> &'static [&'static str] {
self.fields
}
/// Borrow the scalar primary-key field name, if this primary-key
/// declaration is the one-component scalar case.
#[must_use]
pub const fn scalar_field(&self) -> Option<&'static str> {
if self.fields.len() == 1 {
Some(self.fields[0])
} else {
None
}
}
/// Borrow the primary-key source declaration.
#[must_use]
pub const fn source(&self) -> PrimaryKeySource {
self.source
}
}
///
/// PrimaryKeySource
///
/// Declares where primary-key values originate.
///
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize)]
pub enum PrimaryKeySource {
#[default]
Internal,
External,
}
#[cfg(test)]
mod tests;