Skip to content

Commit

Permalink
update: panic if tuple is not frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
GoranBrkuljan committed May 30, 2024
1 parent 334d05f commit a47be2a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions charybdis-parser/src/fields.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::{HashMap, HashSet};

use darling::FromAttributes;
use syn::{Data, DeriveInput, Fields, FieldsNamed, GenericArgument, PathArguments, Type};
use syn::spanned::Spanned;
use syn::{Data, DeriveInput, Fields, FieldsNamed, GenericArgument, PathArguments, Type};

use crate::traits::CharybdisMacroArgs;

Expand Down Expand Up @@ -33,7 +33,6 @@ pub enum CqlType {
List,
Set,
Tuple,
Frozen,
Ignored,
/// This is used when the type is not recognized. In future we might want to extend recognition to UDTs,
/// so we can panic if type is not recognized.
Expand Down Expand Up @@ -153,6 +152,18 @@ impl<'a> Field<'a> {
pub fn is_counter(&self) -> bool {
self.outer_type == CqlType::Counter
}

pub fn is_tuple(&self) -> bool {
self.outer_type == CqlType::Tuple
}

pub fn is_frozen(&self) -> bool {
self.ty_path
.path
.segments
.iter()
.any(|segment| segment.ident == "Frozen")
}
}

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

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

if ch_field.is_tuple() && !ch_field.is_frozen() {
panic!("Tuple field {} must be frozen. Use Frozen<Tuple<T>>.", field_name);
}

if is_partition_key && is_clustering_key {
panic!("Field {} cannot be both partition and clustering key", field_name);
}
Expand Down

0 comments on commit a47be2a

Please sign in to comment.