Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd20793

Browse filesBrowse files
committed
docs: split axum and progress bar examples
1 parent d9bb084 commit cd20793
Copy full SHA for cd20793

File tree

Expand file treeCollapse file tree

5 files changed

+79
-16
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+79
-16
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+14-2Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/axum_embedded/Cargo.toml

Copy file name to clipboardExpand all lines: examples/axum_embedded/Cargo.toml
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ version.workspace = true
88
[dependencies]
99
anyhow = { workspace = true }
1010
axum = { workspace = true }
11-
indicatif = { workspace = true }
1211
postgresql_embedded = { path = "../../postgresql_embedded" }
1312
postgresql_extensions = { path = "../../postgresql_extensions" }
1413
sqlx = { workspace = true, features = ["runtime-tokio"] }
1514
tracing = { workspace = true }
16-
tracing-indicatif = { workspace = true }
1715
tracing-subscriber = { workspace = true }
1816
tokio = { workspace = true, features = ["full"] }

‎examples/axum_embedded/src/main.rs

Copy file name to clipboardExpand all lines: examples/axum_embedded/src/main.rs
+1-12Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,18 @@
44
use anyhow::Result;
55
use axum::extract::State;
66
use axum::{http::StatusCode, routing::get, Json, Router};
7-
use indicatif::ProgressStyle;
87
use postgresql_embedded::{PostgreSQL, Settings, VersionReq};
98
use sqlx::postgres::PgPoolOptions;
109
use sqlx::PgPool;
1110
use std::env;
1211
use std::time::Duration;
1312
use tokio::net::TcpListener;
1413
use tracing::info;
15-
use tracing_indicatif::IndicatifLayer;
16-
use tracing_subscriber::filter::LevelFilter;
17-
use tracing_subscriber::prelude::*;
18-
use tracing_subscriber::{fmt, Registry};
1914

2015
/// Example of how to use postgresql embedded with axum.
2116
#[tokio::main]
2217
async fn main() -> Result<()> {
23-
let progress_style = ProgressStyle::with_template("{span_child_prefix}{spinner} {span_name} [{elapsed_precise}] [{wide_bar:.green.bold}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})")?
24-
.progress_chars("=> ");
25-
let indicatif_layer = IndicatifLayer::new().with_progress_style(progress_style);
26-
let subscriber = Registry::default()
27-
.with(fmt::Layer::default().with_filter(LevelFilter::INFO))
28-
.with(indicatif_layer);
29-
subscriber.init();
18+
tracing_subscriber::fmt().compact().init();
3019

3120
let db_url =
3221
env::var("DATABASE_URL").unwrap_or_else(|_| "postgresql://postgres@localhost".to_string());
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
edition.workspace = true
3+
name = "download_progress_bar"
4+
publish = false
5+
license.workspace = true
6+
version.workspace = true
7+
8+
[dependencies]
9+
anyhow = { workspace = true }
10+
indicatif = { workspace = true }
11+
postgresql_embedded = { path = "../../postgresql_embedded" }
12+
postgresql_extensions = { path = "../../postgresql_extensions" }
13+
tracing = { workspace = true }
14+
tracing-indicatif = { workspace = true }
15+
tracing-subscriber = { workspace = true }
16+
tokio = { workspace = true, features = ["full"] }
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#![forbid(unsafe_code)]
2+
#![deny(clippy::pedantic)]
3+
4+
use anyhow::Result;
5+
use indicatif::ProgressStyle;
6+
use postgresql_embedded::{PostgreSQL, Settings, VersionReq};
7+
use tracing_indicatif::IndicatifLayer;
8+
use tracing_subscriber::filter::LevelFilter;
9+
use tracing_subscriber::prelude::*;
10+
use tracing_subscriber::{fmt, Registry};
11+
12+
/// Example of how to display a progress bar for the postgresql embedded archive download
13+
#[tokio::main]
14+
async fn main() -> Result<()> {
15+
let progress_style = ProgressStyle::with_template("{span_child_prefix}{spinner} {span_name} [{elapsed_precise}] [{wide_bar:.green.bold}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})")?
16+
.progress_chars("=> ");
17+
let indicatif_layer = IndicatifLayer::new().with_progress_style(progress_style);
18+
let subscriber = Registry::default()
19+
.with(fmt::Layer::default().with_filter(LevelFilter::INFO))
20+
.with(indicatif_layer);
21+
subscriber.init();
22+
23+
let settings = Settings {
24+
version: VersionReq::parse("=16.4.0")?,
25+
..Default::default()
26+
};
27+
let mut postgresql = PostgreSQL::new(settings);
28+
postgresql.setup().await?;
29+
postgresql.start().await?;
30+
31+
let database_name = "test";
32+
postgresql.create_database(database_name).await?;
33+
postgresql.database_exists(database_name).await?;
34+
postgresql.drop_database(database_name).await?;
35+
36+
postgresql.stop().await?;
37+
Ok(())
38+
}
39+
40+
#[cfg(test)]
41+
mod test {
42+
use super::*;
43+
44+
#[test]
45+
fn test_main() -> Result<()> {
46+
main()
47+
}
48+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.