vrl/value/kind/collection/
field.rs1use crate::path::OwnedSegment;
2use crate::value::KeyString;
3use crate::value::kind::Collection;
4use crate::value::kind::collection::{CollectionKey, CollectionRemove};
5
6#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
8pub struct Field(KeyString);
9
10impl std::fmt::Display for Field {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 write!(f, "{}", OwnedSegment::field(&self.0))
13 }
14}
15
16impl CollectionKey for Field {
17 fn to_segment(&self) -> OwnedSegment {
18 OwnedSegment::Field(self.0.clone())
19 }
20}
21
22impl Field {
23 #[must_use]
25 pub fn as_str(&self) -> &str {
26 &self.0
27 }
28}
29
30impl CollectionRemove for Collection<Field> {
31 type Key = Field;
32
33 fn remove_known(&mut self, key: &Field) {
34 self.known.remove(key);
35 }
36}
37
38impl std::ops::Deref for Field {
39 type Target = KeyString;
40
41 fn deref(&self) -> &Self::Target {
42 &self.0
43 }
44}
45
46impl From<&str> for Field {
47 fn from(field: &str) -> Self {
48 Self(field.into())
49 }
50}
51
52impl From<String> for Field {
53 fn from(field: String) -> Self {
54 Self(field.into())
55 }
56}
57
58impl From<KeyString> for Field {
59 fn from(field: KeyString) -> Self {
60 Self(field)
61 }
62}