Skip to content
Snippets Groups Projects
Commit 3e35e85d authored by Samuel Tardieu's avatar Samuel Tardieu Committed by Samuel Tardieu
Browse files

Use LazyLock from Rust 1.80.0

parent 64761262
No related branches found
No related tags found
1 merge request!3Use LazyLock from Rust 1.80.0
Pipeline #97867 passed
......@@ -4,6 +4,7 @@ description = "Firmware updater for DC Motor Driver Hat DFR0592"
authors = ["Samuel Tardieu <sam@rfc1149.net>"]
version = "0.1.0"
edition = "2021"
rust-version = "1.80.0"
[dependencies]
bootloader-params = { path = "../bootloader-params" }
......
......@@ -6,7 +6,7 @@ use elf::ParseError;
use elf_loader::Firmware;
use indicatif::{HumanBytes, MultiProgress, ProgressBar, ProgressFinish, ProgressStyle};
use rppal::i2c::{self, I2c};
use std::{borrow::Cow, fmt::Debug, sync::OnceLock, thread, time::Duration};
use std::{borrow::Cow, fmt::Debug, sync::LazyLock, thread, time::Duration};
mod bootloader;
mod cli;
......@@ -58,31 +58,22 @@ fn cmd_check_file(args: CheckFileArgs) -> Result<()> {
Ok(())
}
fn success_msg_style() -> ProgressStyle {
static STYLE: OnceLock<ProgressStyle> = OnceLock::new();
STYLE
.get_or_init(|| ProgressStyle::with_template("{spinner} [{prefix:1.green}] {msg}").unwrap())
.clone()
}
fn failure_msg_style() -> ProgressStyle {
static STYLE: OnceLock<ProgressStyle> = OnceLock::new();
STYLE
.get_or_init(|| ProgressStyle::with_template("{spinner} [{prefix:1.red}] {msg}").unwrap())
.clone()
}
static SUCCES_MSG_STYLE: LazyLock<ProgressStyle> =
LazyLock::new(|| ProgressStyle::with_template("{spinner} [{prefix:1.green}] {msg}").unwrap());
static FAILURE_MSG_STYLE: LazyLock<ProgressStyle> =
LazyLock::new(|| ProgressStyle::with_template("{spinner} [{prefix:1.red}] {msg}").unwrap());
fn msg(msg: impl Into<Cow<'static, str>>) -> ProgressBar {
ProgressBar::new_spinner()
.with_message(msg)
.with_prefix(" ")
.with_style(success_msg_style())
.with_style(SUCCES_MSG_STYLE.clone())
.with_finish(ProgressFinish::AndLeave)
}
fn success(bar: &ProgressBar) {
bar.finish();
bar.set_style(success_msg_style());
bar.set_style(SUCCES_MSG_STYLE.clone());
bar.set_prefix("✓");
}
......@@ -94,7 +85,7 @@ fn success_msg(bar: &ProgressBar, msg: impl Into<Cow<'static, str>>) {
fn failure(bar: &ProgressBar) {
bar.finish();
bar.set_style(failure_msg_style());
bar.set_style(FAILURE_MSG_STYLE.clone());
bar.set_prefix("✕");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment