Skip to content

Commit

Permalink
book: update examples to use DeserializeValue
Browse files Browse the repository at this point in the history
Also, no longer mention the limitations of old derive macros.
The new macros have no limitations compared to Serialize macros.
  • Loading branch information
wprzytula committed Nov 13, 2024
1 parent 3711afc commit b6a7b6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 5 additions & 4 deletions docs/source/data-types/udt.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ and `DeserializeValue` macros documentation.
```rust
# extern crate scylla;
# async fn check_only_compiles() {
use scylla::macros::{FromUserType, SerializeValue};
use scylla::macros::{DeserializeValue, SerializeValue};

// Define a custom struct that matches the User Defined Type created earlier.
// Fields must be in the same order as they are in the database and also
// have the same names.
// Fields don't have to be in the same order as they are in the database.
// By default, they must have the same names, but this can be worked around
// using `#[rename] field attribute.
// Wrapping a field in Option will gracefully handle null field values.
#[derive(Debug, FromUserType, SerializeValue)]
#[derive(Debug, DeserializeValue, SerializeValue)]
struct MyType {
int_val: i32,
text_val: Option<String>,
Expand Down
2 changes: 0 additions & 2 deletions docs/source/migration-guides/0.11-serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ The driver comes a set of `impl`s of those traits which allow to represent any C

By default, the `SerializeRow` and `SerializeValue` **will match the fields in the Rust struct by name to bind marker names** (in case of `SerializeRow`) **or UDT field names** (in case of `SerializeValue`). This is different from the old `ValueList` and `IntoUserType` macros which did not look at the field names at all and would expect the user to order the fields correctly. While the new behavior is much more ergonomic, you might have reasons not to use it.

> **NOTE:** The deserialization macro counterparts `FromRow` and `FromUserType` have the same limitation as the old serialization macros - they require struct fields to be properly ordered. While a similar rework is planned for the deserialization traits in a future release, for the time being it might not be worth keeping the column names in sync with the database.
In order to bring the old behavior to the new macros (the only difference being type checking which cannot be disabled right now) you can configure it using attributes, as shown in the snippet below:

```rust
Expand Down

0 comments on commit b6a7b6d

Please sign in to comment.