docs: mention ValueList macro in the values paragraph
The macro is now mentioned with a simple example of how to use
it to pass parameters to a query.
@@ -6,12 +6,13 @@ Each `?` in query text will be filled with the matching value.
> **Never** pass values by adding strings, this could lead to [SQL Injection](https://en.wikipedia.org/wiki/SQL_injection)
Each list of values to send in a query must implement the trait `ValueList`.
-By default this can be a slice `&[]` or a tuple `()` (max 16 elements) of values to send.
+By default this can be a slice `&[]`, a tuple `()` (max 16 elements) of values to send,
+or a custom struct which derives from `ValueList`.
A few examples:
```rust
# extern crate scylla;
-# use scylla::Session;
+# use scylla::{Session, ValueList};
# use std::error::Error;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
// Empty slice means that there are no values to send
@@ -30,6 +31,23 @@ session
.query("INSERT INTO ks.tab (a, b) VALUES(?, ?)", (2_i32, "Some text"))
.await?;
+// Sending an integer and a string using a named struct.
+// The values will be passed in the order from the struct definition
+#[derive(ValueList)]
+struct IntString {
+ first_col: i32,
+ second_col: String,
+}
+
+let int_string = IntString {
+ first_col: 42_i32,
+ second_col: "hello".to_owned(),
+};
+
+session
+ .query("INSERT INTO ks.tab (a, b) VALUES(?, ?)", int_string)
+ .await?;
+
// Sending a single value as a tuple requires a trailing coma (Rust syntax):
session.query("INSERT INTO ks.tab (a) VALUES(?)", (2_i32,)).await?;
