Remove once_cell dependency

This commit is contained in:
Bilal Elmoussaoui 2024-10-20 20:56:03 +02:00
parent 4e8dba793b
commit ab1efc4075
17 changed files with 51 additions and 50 deletions

1
Cargo.lock generated
View file

@ -293,7 +293,6 @@ dependencies = [
"hex",
"image 0.25.4",
"libadwaita",
"once_cell",
"oo7",
"percent-encoding",
"prost",

View file

@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "authenticator"
rust-version = "1.70"
rust-version = "1.80"
[profile.release]
debug = true
@ -29,7 +29,6 @@ gettext-rs = {version = "0.7", features = ["gettext-system"]}
gtk = {package = "gtk4", version = "0.9", features = ["v4_10"]}
hex = {version = "0.4.3", features = ["serde"]}
image = {version = "0.25", default-features = false, features = ["png"]}
once_cell = "1.9"
oo7 = {version = "0.3", default-features = false, features = ["tokio", "native_crypto", "tracing"]}
percent-encoding = "2.1"
prost = "0.13"

View file

@ -1,6 +1,6 @@
use std::{fmt, io::Cursor, path::PathBuf};
use image::io::Reader as ImageReader;
use image::ImageReader;
use tokio::{io::AsyncWriteExt, sync::Mutex};
use url::Url;

View file

@ -90,9 +90,7 @@ impl Restorable for Google {
secret: {
let string = data_encoding::BASE32_NOPAD.encode(&otp.secret);
string
.trim_end_matches(|c| c == '\0' || c == '=')
.to_owned()
string.trim_end_matches(['\0', '=']).to_owned()
},
label: otp.name.clone(),
issuer: otp.issuer.clone(),

View file

@ -34,10 +34,12 @@ pub struct DieselAccount {
#[doc(hidden)]
mod imp {
use std::cell::{Cell, OnceCell, RefCell};
use std::{
cell::{Cell, OnceCell, RefCell},
sync::LazyLock,
};
use glib::ParamSpecObject;
use once_cell::sync::Lazy;
use super::*;
@ -79,7 +81,7 @@ mod imp {
impl ObjectImpl for Account {
fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
static PROPERTIES: LazyLock<Vec<glib::ParamSpec>> = LazyLock::new(|| {
let mut props = Account::derived_properties().to_vec();
props.push(ParamSpecObject::builder::<Provider>("provider").build());
props

View file

@ -1,14 +1,14 @@
use std::{fs, fs::File, path::PathBuf};
use std::{fs, fs::File, path::PathBuf, sync::LazyLock};
use anyhow::Result;
use diesel::{prelude::*, r2d2, r2d2::ConnectionManager};
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use once_cell::sync::Lazy;
type Pool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
static DB_PATH: Lazy<PathBuf> = Lazy::new(|| gtk::glib::user_data_dir().join("authenticator"));
static POOL: Lazy<Pool> = Lazy::new(|| init_pool().expect("Failed to create a pool"));
static DB_PATH: LazyLock<PathBuf> =
LazyLock::new(|| gtk::glib::user_data_dir().join("authenticator"));
static POOL: LazyLock<Pool> = LazyLock::new(|| init_pool().expect("Failed to create a pool"));
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations/");

View file

@ -1,11 +1,10 @@
use std::collections::HashMap;
use std::{collections::HashMap, sync::OnceLock};
use once_cell::sync::OnceCell;
use rand::RngCore;
use crate::config;
pub static SECRET_SERVICE: OnceCell<oo7::Keyring> = OnceCell::new();
pub static SECRET_SERVICE: OnceLock<oo7::Keyring> = OnceLock::new();
fn token_attributes(token_id: &str) -> HashMap<&str, &str> {
HashMap::from([

View file

@ -1,4 +1,4 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;
mod account;
mod accounts;
@ -13,10 +13,10 @@ mod providers;
mod search_provider;
mod settings;
pub static RUNTIME: Lazy<tokio::runtime::Runtime> =
Lazy::new(|| tokio::runtime::Runtime::new().unwrap());
pub static SETTINGS: Lazy<Settings> = Lazy::new(Settings::default);
pub static FAVICONS_PATH: Lazy<std::path::PathBuf> = Lazy::new(|| {
pub static RUNTIME: LazyLock<tokio::runtime::Runtime> =
LazyLock::new(|| tokio::runtime::Runtime::new().unwrap());
pub static SETTINGS: LazyLock<Settings> = LazyLock::new(Settings::default);
pub static FAVICONS_PATH: LazyLock<std::path::PathBuf> = LazyLock::new(|| {
gtk::glib::user_cache_dir()
.join("authenticator")
.join("favicons")

View file

@ -206,10 +206,9 @@ impl Provider {
.load::<DieselProvider>(&mut conn)?
.into_iter()
.map(From::from)
.map(|p: Provider| {
let accounts = Account::load(&p).unwrap().collect::<Vec<_>>();
.inspect(|p: &Provider| {
let accounts = Account::load(p).unwrap().collect::<Vec<_>>();
p.add_accounts(&accounts);
p
});
Ok(results)
}

View file

@ -13,10 +13,12 @@ use crate::{
};
mod imp {
use std::cell::{OnceCell, RefCell};
use std::{
cell::{OnceCell, RefCell},
sync::LazyLock,
};
use glib::subclass::{InitializingObject, Signal};
use once_cell::sync::Lazy;
use super::*;
@ -118,8 +120,8 @@ mod imp {
#[glib::derived_properties]
impl ObjectImpl for AccountAddDialog {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> =
Lazy::new(|| vec![Signal::builder("added").action().build()]);
static SIGNALS: LazyLock<Vec<Signal>> =
LazyLock::new(|| vec![Signal::builder("added").action().build()]);
SIGNALS.as_ref()
}

View file

@ -12,10 +12,12 @@ use crate::{
widgets::UrlRow,
};
mod imp {
use std::cell::{OnceCell, RefCell};
use std::{
cell::{OnceCell, RefCell},
sync::LazyLock,
};
use glib::subclass::Signal;
use once_cell::sync::Lazy;
use super::*;
@ -87,7 +89,7 @@ mod imp {
impl ObjectImpl for AccountDetailsPage {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
vec![
Signal::builder("removed")
.param_types([Account::static_type()])

View file

@ -1,4 +1,8 @@
use std::{cell::OnceCell, os::fd::OwnedFd, sync::Once};
use std::{
cell::OnceCell,
os::fd::OwnedFd,
sync::{LazyLock, Once},
};
use adw::subclass::prelude::*;
use anyhow::Result;
@ -9,7 +13,6 @@ use gtk::{
prelude::*,
};
use image::GenericImageView;
use once_cell::sync::Lazy;
use super::CameraRow;
use crate::utils::spawn_tokio;
@ -99,7 +102,7 @@ mod imp {
impl ObjectImpl for Camera {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
vec![
Signal::builder("close").action().build(),
Signal::builder("code-detected")

View file

@ -22,11 +22,11 @@ mod imp {
use std::{
cell::{Cell, OnceCell, RefCell},
collections::HashMap,
sync::LazyLock,
};
use adw::subclass::prelude::*;
use glib::subclass::Signal;
use once_cell::sync::Lazy;
use super::*;
@ -97,8 +97,8 @@ mod imp {
#[glib::derived_properties]
impl ObjectImpl for PreferencesWindow {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> =
Lazy::new(|| vec![Signal::builder("restore-completed").action().build()]);
static SIGNALS: LazyLock<Vec<Signal>> =
LazyLock::new(|| vec![Signal::builder("restore-completed").action().build()]);
SIGNALS.as_ref()
}

View file

@ -12,10 +12,9 @@ enum View {
}
mod imp {
use std::cell::OnceCell;
use std::{cell::OnceCell, sync::LazyLock};
use glib::subclass::Signal;
use once_cell::sync::Lazy;
use super::*;
use crate::config;
@ -82,8 +81,8 @@ mod imp {
#[glib::derived_properties]
impl ObjectImpl for ProvidersDialog {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> =
Lazy::new(|| vec![Signal::builder("changed").build()]);
static SIGNALS: LazyLock<Vec<Signal>> =
LazyLock::new(|| vec![Signal::builder("changed").build()]);
SIGNALS.as_ref()
}

View file

@ -15,6 +15,8 @@ pub enum ProvidersListView {
}
mod imp {
use std::sync::LazyLock;
use glib::subclass::Signal;
use super::*;
@ -52,8 +54,7 @@ mod imp {
}
fn signals() -> &'static [Signal] {
use once_cell::sync::Lazy;
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
vec![Signal::builder("shared")
.param_types([Account::static_type()])
.action()

View file

@ -14,7 +14,7 @@ use crate::{
};
mod imp {
use std::cell::RefCell;
use std::{cell::RefCell, sync::LazyLock};
use glib::subclass::Signal;
@ -114,8 +114,7 @@ mod imp {
impl ObjectImpl for ProviderPage {
fn signals() -> &'static [Signal] {
use once_cell::sync::Lazy;
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
vec![
Signal::builder("created")
.param_types([Provider::static_type()])

View file

@ -12,10 +12,9 @@ use crate::{
};
mod imp {
use std::cell::OnceCell;
use std::{cell::OnceCell, sync::LazyLock};
use glib::subclass::Signal;
use once_cell::sync::Lazy;
use super::*;
@ -53,7 +52,7 @@ mod imp {
#[glib::derived_properties]
impl ObjectImpl for ProviderRow {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
vec![
Signal::builder("changed").action().build(),
Signal::builder("shared")