Skip to content

Commit 0341076

Browse files
committed
Driver/Rust: Implement suggestions by CodeRabbit
1 parent 1aabf65 commit 0341076

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

docs/connect/rust.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,29 @@ Connect to CrateDB from Rust applications.
1111

1212
[postgres] is a synchronous Rust client for the PostgreSQL database.
1313

14-
:::{rubric} Synopsis
14+
:::{rubric} Install
1515
:::
16+
```shell
17+
cargo add postgres
18+
```
1619

20+
:::{rubric} Synopsis
21+
:::
1722
```rust
1823
use postgres::{Client, NoTls};
1924

20-
let mut client = Client::connect("host=localhost user=crate", NoTls)?;
21-
22-
for row in client.query("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3", &[])? {
23-
let mountain: &str = row.get(0);
24-
let height: i32 = row.get(1);
25-
26-
println!("found mountain: {} {}", mountain, height);
25+
fn main() -> Result<(), Box<dyn std::error::Error>> {
26+
let mut client = Client::connect("host=localhost user=crate", NoTls)?;
27+
28+
for row in client.query(
29+
"SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3",
30+
&[],
31+
)? {
32+
let mountain: &str = row.get(0);
33+
let height: i32 = row.get(1);
34+
println!("found mountain: {} {}", mountain, height);
35+
}
36+
Ok(())
2737
}
2838
```
2939

0 commit comments

Comments
 (0)