Skip to content

Commit a47be2a

Browse files
committed
update: panic if tuple is not frozen
1 parent 334d05f commit a47be2a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

charybdis-parser/src/fields.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::{HashMap, HashSet};
22

33
use darling::FromAttributes;
4-
use syn::{Data, DeriveInput, Fields, FieldsNamed, GenericArgument, PathArguments, Type};
54
use syn::spanned::Spanned;
5+
use syn::{Data, DeriveInput, Fields, FieldsNamed, GenericArgument, PathArguments, Type};
66

77
use crate::traits::CharybdisMacroArgs;
88

@@ -33,7 +33,6 @@ pub enum CqlType {
3333
List,
3434
Set,
3535
Tuple,
36-
Frozen,
3736
Ignored,
3837
/// This is used when the type is not recognized. In future we might want to extend recognition to UDTs,
3938
/// so we can panic if type is not recognized.
@@ -153,6 +152,18 @@ impl<'a> Field<'a> {
153152
pub fn is_counter(&self) -> bool {
154153
self.outer_type == CqlType::Counter
155154
}
155+
156+
pub fn is_tuple(&self) -> bool {
157+
self.outer_type == CqlType::Tuple
158+
}
159+
160+
pub fn is_frozen(&self) -> bool {
161+
self.ty_path
162+
.path
163+
.segments
164+
.iter()
165+
.any(|segment| segment.ident == "Frozen")
166+
}
156167
}
157168

158169
#[derive(Default)]
@@ -192,6 +203,10 @@ impl<'a> CharybdisFields<'a> {
192203

193204
let ch_field = Field::from_field(field, is_partition_key, is_clustering_key, is_static_column);
194205

206+
if ch_field.is_tuple() && !ch_field.is_frozen() {
207+
panic!("Tuple field {} must be frozen. Use Frozen<Tuple<T>>.", field_name);
208+
}
209+
195210
if is_partition_key && is_clustering_key {
196211
panic!("Field {} cannot be both partition and clustering key", field_name);
197212
}

0 commit comments

Comments
 (0)