Skip to content

Commit 78423b4

Browse files
committed
docs: update examples in documentation to remove unnecessary use of .unwrap()
1 parent 6084fa5 commit 78423b4

File tree

5 files changed

+44
-43
lines changed

5 files changed

+44
-43
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ bundled with your application, or downloaded on demand.
1616

1717
### Example
1818
```rust
19-
use postgresql_embedded::PostgreSQL;
19+
use postgresql_embedded::{PostgreSQL, Result};
2020

2121
#[tokio::main]
22-
async fn main() {
22+
async fn main() -> Result<()> {
2323
let mut postgresql = PostgreSQL::default();
24-
postgresql.setup().await.unwrap();
25-
postgresql.start().await.unwrap();
24+
postgresql.setup().await?;
25+
postgresql.start().await?;
2626

2727
let database_name = "test";
28-
postgresql.create_database(database_name).await.unwrap();
29-
postgresql.database_exists(database_name).await.unwrap();
30-
postgresql.drop_database(database_name).await.unwrap();
28+
postgresql.create_database(database_name).await?;
29+
postgresql.database_exists(database_name).await?;
30+
postgresql.drop_database(database_name).await?;
3131

32-
postgresql.stop().await.unwrap();
32+
postgresql.stop().await
3333
}
3434
```
3535

postgresql_archive/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ A library for downloading and extracting PostgreSQL archives from
1515
### Asynchronous API
1616

1717
```rust
18-
use postgresql_archive::{extract, get_archive, LATEST};
18+
use postgresql_archive::{extract, get_archive, Result, LATEST};
1919

2020
#[tokio::main]
21-
async fn main() {
22-
let (archive_version, archive, hash) = get_archive(&LATEST).await.unwrap();
21+
async fn main() -> Result<()> {
22+
let (archive_version, archive, hash) = get_archive(&LATEST).await?;
2323
let out_dir = std::env::temp_dir();
24-
let result = extract(&archive, &out_dir).await.unwrap();
24+
extract(&archive, &out_dir).await;
2525
}
2626
```
2727

2828
### Synchronous API
2929
```rust
30-
use postgresql_archive::LATEST;
30+
use postgresql_archive::{Result, LATEST};
3131
use postgresql_archive::blocking::{extract, get_archive};
3232

33-
fn main() {
34-
let (archive_version, archive, hash) = get_archive(&LATEST).unwrap();
33+
fn main() -> Result<()> {
34+
let (archive_version, archive, hash) = get_archive(&LATEST);
3535
let out_dir = std::env::temp_dir();
36-
let result = extract(&archive, &out_dir).unwrap();
36+
extract(&archive, &out_dir)
3737
}
3838
```
3939

postgresql_archive/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
//! ### Asynchronous API
2323
//!
2424
//! ```no_run
25-
//! use postgresql_archive::{extract, get_archive, LATEST};
25+
//! use postgresql_archive::{extract, get_archive, Result, LATEST};
2626
//!
2727
//! #[tokio::main]
28-
//! async fn main() {
29-
//! let (archive_version, archive, hash) = get_archive(&LATEST).await.unwrap();
28+
//! async fn main() -> Result<()> {
29+
//! let (archive_version, archive, hash) = get_archive(&LATEST).await?;
3030
//! let out_dir = std::env::temp_dir();
31-
//! let result = extract(&archive, &out_dir).await.unwrap();
31+
//! extract(&archive, &out_dir).await
3232
//! }
3333
//! ```
3434
//!

postgresql_embedded/README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,39 @@ bundled with your application, or downloaded on demand.
1515
### Asynchronous API
1616

1717
```rust
18-
use postgresql_embedded::PostgreSQL;
18+
use postgresql_embedded::{PostgreSQL, Result};
1919

2020
#[tokio::main]
21-
async fn main() {
21+
async fn main() -> Result<()> {
2222
let mut postgresql = PostgreSQL::default();
23-
postgresql.setup().await.unwrap();
24-
postgresql.start().await.unwrap();
23+
postgresql.setup().await?;
24+
postgresql.start().await?;
2525

2626
let database_name = "test";
27-
postgresql.create_database(database_name).await.unwrap();
28-
postgresql.database_exists(database_name).await.unwrap();
29-
postgresql.drop_database(database_name).await.unwrap();
27+
postgresql.create_database(database_name).await?;
28+
postgresql.database_exists(database_name).await?;
29+
postgresql.drop_database(database_name).await?;
3030

31-
postgresql.stop().await.unwrap();
31+
postgresql.stop().await;
3232
}
3333
```
3434

3535
### Synchronous API
3636
```rust
37+
use postgresql_embedded::Result;
3738
use postgresql_embedded::blocking::PostgreSQL;
3839

39-
fn main() {
40+
fn main() -> Result<()> {
4041
let mut postgresql = PostgreSQL::default();
41-
postgresql.setup().unwrap();
42-
postgresql.start().unwrap();
42+
postgresql.setup()?;
43+
postgresql.start()?;
4344

4445
let database_name = "test";
45-
postgresql.create_database(database_name).unwrap();
46-
postgresql.database_exists(database_name).unwrap();
47-
postgresql.drop_database(database_name).unwrap();
46+
postgresql.create_database(database_name)?;
47+
postgresql.database_exists(database_name)?;
48+
postgresql.drop_database(database_name)?;
4849

49-
postgresql.stop().unwrap();
50+
postgresql.stop()
5051
}
5152
```
5253

postgresql_embedded/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
//! ### Asynchronous API
2424
//!
2525
//! ```no_run
26-
//! use postgresql_embedded::PostgreSQL;
26+
//! use postgresql_embedded::{PostgreSQL, Result};
2727
//!
2828
//! #[tokio::main]
29-
//! async fn main() {
29+
//! async fn main() -> Result<()> {
3030
//! let mut postgresql = PostgreSQL::default();
31-
//! postgresql.setup().await.unwrap();
32-
//! postgresql.start().await.unwrap();
31+
//! postgresql.setup().await?;
32+
//! postgresql.start().await?;
3333
//!
3434
//! let database_name = "test";
35-
//! postgresql.create_database(database_name).await.unwrap();
36-
//! postgresql.database_exists(database_name).await.unwrap();
37-
//! postgresql.drop_database(database_name).await.unwrap();
35+
//! postgresql.create_database(database_name).await?;
36+
//! postgresql.database_exists(database_name).await?;
37+
//! postgresql.drop_database(database_name).await?;
3838
//!
39-
//! postgresql.stop().await.unwrap();
39+
//! postgresql.stop().await
4040
//! }
4141
//! ```
4242
//!

0 commit comments

Comments
 (0)