Skip to content

Commit

Permalink
Remove some use of once_cell with new std alternatives
Browse files Browse the repository at this point in the history
`OnceCell` and `OnceLock` was stabilized in Rust `1.70.0`, which allow
us to refactor some use of the `once_cell` crate to use the
implementations in the standard library.
  • Loading branch information
MarkusPettersson98 committed Jun 22, 2023
1 parent cf1a3c9 commit 3400972
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mullvad_types::{
account::{AccountToken, VoucherSubmission},
version::AppVersion,
};
use once_cell::sync::OnceCell;
use std::sync::OnceLock;
use proxy::ApiConnectionMode;
use std::{
cell::Cell,
Expand Down Expand Up @@ -66,18 +66,18 @@ const APP_URL_PREFIX: &str = "app/v1";

pub static API: LazyManual<ApiEndpoint> = LazyManual::new(ApiEndpoint::from_env_vars);

unsafe impl<T, F: Send> Sync for LazyManual<T, F> where OnceCell<T>: Sync {}
unsafe impl<T, F: Send> Sync for LazyManual<T, F> where OnceLock<T>: Sync {}

/// A value that is either initialized on access or explicitly.
pub struct LazyManual<T, F = fn() -> T> {
cell: OnceCell<T>,
cell: OnceLock<T>,
lazy_fn: Cell<Option<F>>,
}

impl<T, F> LazyManual<T, F> {
const fn new(lazy_fn: F) -> Self {
Self {
cell: OnceCell::new(),
cell: OnceLock::new(),
lazy_fn: Cell::new(Some(lazy_fn)),
}
}
Expand Down

0 comments on commit 3400972

Please sign in to comment.