Skip to content

Commit 416b913

Browse files
committed
doc: document #[derive(Row)]
1 parent aa7c809 commit 416b913

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

derive/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ mod attributes;
1212
#[cfg(test)]
1313
mod tests;
1414

15+
// TODO: support wrappers `Wrapper(Inner)` and `Wrapper<T>(T)`.
16+
// TODO: support the `nested` attribute.
17+
#[proc_macro_derive(Row, attributes(clickhouse))]
18+
pub fn row(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
19+
let input = parse_macro_input!(input as DeriveInput);
20+
row_impl(input)
21+
.unwrap_or_else(Error::into_compile_error)
22+
.into()
23+
}
24+
1525
fn column_names(data: &DataStruct, cx: &Ctxt, container: &Container) -> Result<TokenStream> {
1626
Ok(match &data.fields {
1727
Fields::Named(fields) => {
@@ -39,16 +49,6 @@ fn column_names(data: &DataStruct, cx: &Ctxt, container: &Container) -> Result<T
3949
})
4050
}
4151

42-
// TODO: support wrappers `Wrapper(Inner)` and `Wrapper<T>(T)`.
43-
// TODO: support the `nested` attribute.
44-
#[proc_macro_derive(Row, attributes(clickhouse))]
45-
pub fn row(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
46-
let input = parse_macro_input!(input as DeriveInput);
47-
row_impl(input)
48-
.unwrap_or_else(Error::into_compile_error)
49-
.into()
50-
}
51-
5252
fn row_impl(input: DeriveInput) -> Result<TokenStream> {
5353
let cx = Ctxt::new();
5454

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ pub use self::{
1010
row::{Row, RowOwned, RowRead, RowWrite},
1111
};
1212
use self::{error::Result, http_client::HttpClient};
13+
14+
#[doc = include_str!("row_derive.md")]
1315
pub use clickhouse_derive::Row;
16+
1417
use std::{collections::HashMap, fmt::Display, sync::Arc};
1518

1619
pub mod error;

src/row.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ pub enum RowKind {
1313
/// Represents a row that can be used in queries.
1414
///
1515
/// Implemented for:
16-
/// * All `#[derive(Row)]` items
16+
/// * All [`#[derive(Row)]`][row-derive] items
1717
/// * `(P1, P2, ...)` where P* is a primitive type or string
1818
///
19-
/// Do not implement this trait directly, use `#[derive(Row)]` instead.
19+
/// Do not implement this trait directly, use [`#[derive(Row)]`][row-derive] instead.
2020
///
2121
/// In order to write a generic code over rows, check
2222
/// * [`RowRead`] for reading queries.
2323
/// * [`RowWrite`] for writing queries.
2424
/// * [`RowOwned`] for rows that do not hold any references.
25+
///
26+
/// [row-derive]: derive@crate::Row
2527
pub trait Row {
2628
// NOTE: all properties are unstable and, hence, not following semver.
2729

src/row_derive.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Derive macro for [`Row`][trait@crate::Row].
2+
3+
```rust,no_run
4+
use clickhouse::Row;
5+
6+
#[derive(Row)]
7+
struct MyRow {
8+
foo: u32,
9+
bar: String,
10+
baz: bool,
11+
}
12+
```
13+
14+
# `#[clickhouse(crate = "...")]`
15+
16+
Override the name of the `clickhouse` crate where referenced by the macro.
17+
18+
Useful if the `clickhouse` package is renamed in Cargo.
19+
20+
21+
## Example
22+
`Cargo.toml`:
23+
```toml
24+
# Renames the `clickhouse` dependency to `foo`
25+
[dependencies.foo]
26+
package = "clickhouse"
27+
version = "0.14"
28+
```
29+
30+
```rust,no_run
31+
# extern crate clickhouse as foo;
32+
use foo::Row;
33+
34+
#[derive(Row)]
35+
#[clickhouse(crate = "foo")]
36+
struct MyRow {
37+
foo: u32,
38+
bar: String,
39+
baz: bool,
40+
}
41+
```

0 commit comments

Comments
 (0)