|
1 | 1 | use std::collections::{HashMap, HashSet}; |
2 | 2 |
|
3 | 3 | use darling::FromAttributes; |
4 | | -use syn::{Data, DeriveInput, Fields, FieldsNamed, GenericArgument, PathArguments, Type}; |
5 | 4 | use syn::spanned::Spanned; |
| 5 | +use syn::{Data, DeriveInput, Fields, FieldsNamed, GenericArgument, PathArguments, Type}; |
6 | 6 |
|
7 | 7 | use crate::traits::CharybdisMacroArgs; |
8 | 8 |
|
@@ -33,7 +33,6 @@ pub enum CqlType { |
33 | 33 | List, |
34 | 34 | Set, |
35 | 35 | Tuple, |
36 | | - Frozen, |
37 | 36 | Ignored, |
38 | 37 | /// This is used when the type is not recognized. In future we might want to extend recognition to UDTs, |
39 | 38 | /// so we can panic if type is not recognized. |
@@ -153,6 +152,18 @@ impl<'a> Field<'a> { |
153 | 152 | pub fn is_counter(&self) -> bool { |
154 | 153 | self.outer_type == CqlType::Counter |
155 | 154 | } |
| 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 | + } |
156 | 167 | } |
157 | 168 |
|
158 | 169 | #[derive(Default)] |
@@ -192,6 +203,10 @@ impl<'a> CharybdisFields<'a> { |
192 | 203 |
|
193 | 204 | let ch_field = Field::from_field(field, is_partition_key, is_clustering_key, is_static_column); |
194 | 205 |
|
| 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 | + |
195 | 210 | if is_partition_key && is_clustering_key { |
196 | 211 | panic!("Field {} cannot be both partition and clustering key", field_name); |
197 | 212 | } |
|
0 commit comments