mz_storage_types/
collections.rs
1include!(concat!(env!("OUT_DIR"), "/mz_storage_types.collections.rs"));
13
14use mz_proto::{ProtoType, RustType, TryFromProtoError};
15use mz_repr::{GlobalId as RustGlobalId, Timestamp as RustTimestamp};
16use timely::progress::Antichain;
17
18use crate::controller::DurableCollectionMetadata as RustDurableCollectionMetadata;
19
20impl RustType<GlobalId> for RustGlobalId {
21 fn into_proto(&self) -> GlobalId {
22 GlobalId {
23 value: Some(match self {
24 RustGlobalId::System(x) => global_id::Value::System(*x),
25 RustGlobalId::IntrospectionSourceIndex(x) => {
26 global_id::Value::IntrospectionSourceIndex(*x)
27 }
28 RustGlobalId::User(x) => global_id::Value::User(*x),
29 RustGlobalId::Transient(x) => global_id::Value::Transient(*x),
30 RustGlobalId::Explain => global_id::Value::Explain(Default::default()),
31 }),
32 }
33 }
34
35 fn from_proto(proto: GlobalId) -> Result<Self, TryFromProtoError> {
36 match proto.value {
37 Some(global_id::Value::System(x)) => Ok(RustGlobalId::System(x)),
38 Some(global_id::Value::IntrospectionSourceIndex(x)) => {
39 Ok(RustGlobalId::IntrospectionSourceIndex(x))
40 }
41 Some(global_id::Value::User(x)) => Ok(RustGlobalId::User(x)),
42 Some(global_id::Value::Transient(x)) => Ok(RustGlobalId::Transient(x)),
43 Some(global_id::Value::Explain(_)) => Ok(RustGlobalId::Explain),
44 None => Err(TryFromProtoError::missing_field("GlobalId::kind")),
45 }
46 }
47}
48
49impl RustType<Timestamp> for RustTimestamp {
50 fn into_proto(&self) -> Timestamp {
51 Timestamp {
52 internal: self.into(),
53 }
54 }
55
56 fn from_proto(proto: Timestamp) -> Result<Self, TryFromProtoError> {
57 Ok(RustTimestamp::new(proto.internal))
58 }
59}
60
61impl<T> RustType<TimestampAntichain> for Antichain<T>
62where
63 T: RustType<Timestamp> + Clone + timely::PartialOrder,
64{
65 fn into_proto(&self) -> TimestampAntichain {
66 TimestampAntichain {
67 elements: self
68 .elements()
69 .into_iter()
70 .cloned()
71 .map(|e| e.into_proto())
72 .collect(),
73 }
74 }
75
76 fn from_proto(proto: TimestampAntichain) -> Result<Self, TryFromProtoError> {
77 let elements: Vec<_> = proto
78 .elements
79 .into_iter()
80 .map(|e| T::from_proto(e))
81 .collect::<Result<_, _>>()?;
82
83 Ok(Antichain::from_iter(elements))
84 }
85}
86
87impl RustType<DurableCollectionMetadata> for RustDurableCollectionMetadata {
88 fn into_proto(&self) -> DurableCollectionMetadata {
89 DurableCollectionMetadata {
90 data_shard: self.data_shard.into_proto(),
91 }
92 }
93
94 fn from_proto(proto: DurableCollectionMetadata) -> Result<Self, TryFromProtoError> {
95 Ok(RustDurableCollectionMetadata {
96 data_shard: proto.data_shard.into_rust()?,
97 })
98 }
99}