Skip to content

Commit e7e2322

Browse files
committed
refactor: turn COLUMN_NAME/COLUMN_COUNT consts into functions
1 parent 44525e4 commit e7e2322

15 files changed

+138
-77
lines changed

derive/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ fn column_names(data: &DataStruct, cx: &Ctxt, container: &Container) -> Result<T
2626
});
2727

2828
quote! {
29-
&[#( #column_names_iter,)*]
29+
[#( #column_names_iter,)*]
3030
}
3131
}
3232
Fields::Unnamed(_) => {
33-
quote! { &[] }
33+
quote! { [] }
3434
}
3535
Fields::Unit => unreachable!("checked by the caller"),
3636
})
@@ -94,8 +94,8 @@ fn row_impl(input: DeriveInput) -> Result<TokenStream> {
9494
#[automatically_derived]
9595
impl #impl_generics clickhouse::Row for #name #ty_generics #where_clause {
9696
const NAME: &'static str = stringify!(#name);
97-
const COLUMN_NAMES: &'static [&'static str] = #column_names;
98-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
97+
fn column_names() -> impl IntoIterator<Item = &'static str> { #column_names }
98+
fn column_count() -> usize { <Self as clickhouse::Row>::column_names().into_iter().count() }
9999
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
100100

101101
type Value<'__v> = #value;

derive/src/tests/snapshots/generic_borrowed_row-2.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ struct Sample<'a, A, B> {
1111
#[automatically_derived]
1212
impl<'a, A, B> clickhouse::Row for Sample<'a, A, B> {
1313
const NAME: &'static str = stringify!(Sample);
14-
const COLUMN_NAMES: &'static [&'static str] = &["a", "b"];
15-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
14+
fn column_names() -> impl IntoIterator<Item = &'static str> {
15+
["a", "b"]
16+
}
17+
fn column_count() -> usize {
18+
<Self as clickhouse::Row>::column_names().into_iter().count()
19+
}
1620
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
1721
type Value<'__v> = Sample<'__v, A, B>;
1822
}

derive/src/tests/snapshots/generic_borrowed_row-3.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ where
1717
T: Clone,
1818
{
1919
const NAME: &'static str = stringify!(Sample);
20-
const COLUMN_NAMES: &'static [&'static str] = &["a", "b"];
21-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
20+
fn column_names() -> impl IntoIterator<Item = &'static str> {
21+
["a", "b"]
22+
}
23+
fn column_count() -> usize {
24+
<Self as clickhouse::Row>::column_names().into_iter().count()
25+
}
2226
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
2327
type Value<'__v> = Sample<'__v, T>;
2428
}

derive/src/tests/snapshots/generic_borrowed_row.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ struct Sample<'a, T> {
1111
#[automatically_derived]
1212
impl<'a, T> clickhouse::Row for Sample<'a, T> {
1313
const NAME: &'static str = stringify!(Sample);
14-
const COLUMN_NAMES: &'static [&'static str] = &["a", "b"];
15-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
14+
fn column_names() -> impl IntoIterator<Item = &'static str> {
15+
["a", "b"]
16+
}
17+
fn column_count() -> usize {
18+
<Self as clickhouse::Row>::column_names().into_iter().count()
19+
}
1620
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
1721
type Value<'__v> = Sample<'__v, T>;
1822
}

derive/src/tests/snapshots/generic_owned_row-2.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ struct Sample<A, B> {
1111
#[automatically_derived]
1212
impl<A, B> clickhouse::Row for Sample<A, B> {
1313
const NAME: &'static str = stringify!(Sample);
14-
const COLUMN_NAMES: &'static [&'static str] = &["a", "b"];
15-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
14+
fn column_names() -> impl IntoIterator<Item = &'static str> {
15+
["a", "b"]
16+
}
17+
fn column_count() -> usize {
18+
<Self as clickhouse::Row>::column_names().into_iter().count()
19+
}
1620
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
1721
type Value<'__v> = Self;
1822
}

derive/src/tests/snapshots/generic_owned_row-3.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ where
1717
T: Clone,
1818
{
1919
const NAME: &'static str = stringify!(Sample);
20-
const COLUMN_NAMES: &'static [&'static str] = &["a", "b"];
21-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
20+
fn column_names() -> impl IntoIterator<Item = &'static str> {
21+
["a", "b"]
22+
}
23+
fn column_count() -> usize {
24+
<Self as clickhouse::Row>::column_names().into_iter().count()
25+
}
2226
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
2327
type Value<'__v> = Self;
2428
}

derive/src/tests/snapshots/generic_owned_row.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ struct Sample<T> {
1111
#[automatically_derived]
1212
impl<T> clickhouse::Row for Sample<T> {
1313
const NAME: &'static str = stringify!(Sample);
14-
const COLUMN_NAMES: &'static [&'static str] = &["a", "b"];
15-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
14+
fn column_names() -> impl IntoIterator<Item = &'static str> {
15+
["a", "b"]
16+
}
17+
fn column_count() -> usize {
18+
<Self as clickhouse::Row>::column_names().into_iter().count()
19+
}
1620
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
1721
type Value<'__v> = Self;
1822
}

derive/src/tests/snapshots/serde_rename.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ struct Sample {
1414
#[automatically_derived]
1515
impl clickhouse::Row for Sample {
1616
const NAME: &'static str = stringify!(Sample);
17-
const COLUMN_NAMES: &'static [&'static str] = &["a", "items.a", "items.b"];
18-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
17+
fn column_names() -> impl IntoIterator<Item = &'static str> {
18+
["a", "items.a", "items.b"]
19+
}
20+
fn column_count() -> usize {
21+
<Self as clickhouse::Row>::column_names().into_iter().count()
22+
}
1923
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
2024
type Value<'__v> = Self;
2125
}

derive/src/tests/snapshots/serde_skip_deserializing.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ struct Sample {
1212
#[automatically_derived]
1313
impl clickhouse::Row for Sample {
1414
const NAME: &'static str = stringify!(Sample);
15-
const COLUMN_NAMES: &'static [&'static str] = &["a"];
16-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
15+
fn column_names() -> impl IntoIterator<Item = &'static str> {
16+
["a"]
17+
}
18+
fn column_count() -> usize {
19+
<Self as clickhouse::Row>::column_names().into_iter().count()
20+
}
1721
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
1822
type Value<'__v> = Self;
1923
}

derive/src/tests/snapshots/serde_skip_serializing.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ struct Sample {
1212
#[automatically_derived]
1313
impl clickhouse::Row for Sample {
1414
const NAME: &'static str = stringify!(Sample);
15-
const COLUMN_NAMES: &'static [&'static str] = &["a"];
16-
const COLUMN_COUNT: usize = <Self as clickhouse::Row>::COLUMN_NAMES.len();
15+
fn column_names() -> impl IntoIterator<Item = &'static str> {
16+
["a"]
17+
}
18+
fn column_count() -> usize {
19+
<Self as clickhouse::Row>::column_names().into_iter().count()
20+
}
1721
const KIND: clickhouse::_priv::RowKind = clickhouse::_priv::RowKind::Struct;
1822
type Value<'__v> = Self;
1923
}

0 commit comments

Comments
 (0)