Skip to content

Commit 580bfd6

Browse files
committed
macros: share Flavor between ser and deser macros
1 parent 0399b2f commit 580bfd6

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

scylla-macros/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use darling::ToTokens;
1+
use darling::{FromMeta, ToTokens};
22
use proc_macro::TokenStream;
33

44
mod from_row;
@@ -7,6 +7,24 @@ mod into_user_type;
77
mod parser;
88
mod value_list;
99

10+
// Flavor of serialization/deserialization macros ({De,S}erialize{Value,Row}).
11+
#[derive(Copy, Clone, PartialEq, Eq, Default)]
12+
enum Flavor {
13+
#[default]
14+
MatchByName,
15+
EnforceOrder,
16+
}
17+
18+
impl FromMeta for Flavor {
19+
fn from_string(value: &str) -> darling::Result<Self> {
20+
match value {
21+
"match_by_name" => Ok(Self::MatchByName),
22+
"enforce_order" => Ok(Self::EnforceOrder),
23+
_ => Err(darling::Error::unknown_value(value)),
24+
}
25+
}
26+
}
27+
1028
mod serialize;
1129

1230
/// Documentation for this macro can only be found

scylla-macros/src/serialize/mod.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,2 @@
1-
use darling::FromMeta;
2-
31
pub(crate) mod row;
42
pub(crate) mod value;
5-
6-
#[derive(Copy, Clone, PartialEq, Eq, Default)]
7-
enum Flavor {
8-
#[default]
9-
MatchByName,
10-
EnforceOrder,
11-
}
12-
13-
impl FromMeta for Flavor {
14-
fn from_string(value: &str) -> darling::Result<Self> {
15-
match value {
16-
"match_by_name" => Ok(Self::MatchByName),
17-
"enforce_order" => Ok(Self::EnforceOrder),
18-
_ => Err(darling::Error::unknown_value(value)),
19-
}
20-
}
21-
}

scylla-macros/src/serialize/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use proc_macro::TokenStream;
55
use proc_macro2::Span;
66
use syn::parse_quote;
77

8-
use super::Flavor;
8+
use crate::Flavor;
99

1010
#[derive(FromAttributes)]
1111
#[darling(attributes(scylla))]

scylla-macros/src/serialize/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use proc_macro::TokenStream;
55
use proc_macro2::Span;
66
use syn::parse_quote;
77

8-
use super::Flavor;
8+
use crate::Flavor;
99

1010
#[derive(FromAttributes)]
1111
#[darling(attributes(scylla))]

0 commit comments

Comments
 (0)