Skip to content

Commit c5470a0

Browse files
nrxusLorak-mmk
authored andcommitted
improved compile-time error when fields cannot be flattened
This uses `diagnostic::on_unimplemented` to hint the users to derive `SerializeRow` with the correct flavor
1 parent 78d2de6 commit c5470a0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

scylla-cql/src/_macro_internal.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ pub use crate::serialize::{CellValueBuilder, CellWriter, RowWriter, Serializatio
3838
///
3939
/// For now this trait is an implementation detail of `#[derive(SerializeRow)]` when
4040
/// serializing by name
41+
#[diagnostic::on_unimplemented(
42+
message = "`{Self}` cannot be flattened here",
43+
label = "`{Self}` is not a struct that derives `SerializeRow` with `match_by_name` flavor",
44+
note = "There are two common reasons for that:
45+
- `{Self}` does not use `#[derive(SerializeRow)]`
46+
- `{Self}` uses `#[scylla(flavor = \"enforce_order\")]`"
47+
)]
4148
pub trait SerializeRowByName {
4249
/// A type that can handle serialization of this struct column-by-column
4350
type Partial<'d>: PartialSerializeRowByName
@@ -83,6 +90,13 @@ pub trait PartialSerializeRowByName {
8390
///
8491
/// For now this trait is an implementation detail of `#[derive(SerializeRow)]` when
8592
/// serializing in order
93+
#[diagnostic::on_unimplemented(
94+
message = "`{Self}` cannot be flattened here",
95+
label = "`{Self}` is not a struct that derives `SerializeRow` with `enforce_order` flavor",
96+
note = "There are two common reasons for that:
97+
- `{Self}` does not use `#[derive(SerializeRow)]`
98+
- `{Self}` uses `#[scylla(flavor = \"match_by_name\")]` (which is the default)"
99+
)]
86100
pub trait SerializeRowInOrder {
87101
fn serialize_in_order(
88102
&self,

0 commit comments

Comments
 (0)