Skip to content

Commit

Permalink
Upgrade to use Rust 1.80 and replace Lazy-Static crate with LazyLock …
Browse files Browse the repository at this point in the history
…from std library
  • Loading branch information
shartrec committed Jul 27, 2024
1 parent a8b8430 commit 6ab1a99
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 48 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license = "MIT"

[dependencies]
home = "0.5.9"
lazy_static = "^1.4.0"
log = "^0.4"
palette = "^0.7.6"
preferences = "2.0.0"
Expand Down
10 changes: 4 additions & 6 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ use std::collections::VecDeque;
use std::fs::File;
use std::io::{self, Read, Write};
use std::path::PathBuf;
use std::sync::RwLock;
use std::sync::{LazyLock, RwLock};

use lazy_static::lazy_static;
use log::{info, warn};
use serde::{Deserialize, Serialize};

static HISTORY_FILE: &str = "rusty-calc-history.json";
static HISTORY_SIZE: usize = 100;

lazy_static! {
static ref HISTORY_MANAGER: HistoryManager = {
static HISTORY_MANAGER: LazyLock<HistoryManager> = LazyLock::new(|| -> HistoryManager{
let mut contents = String::new();
let history = if let Some(path) = get_history_path() {
match File::open(path)
Expand All @@ -56,8 +54,8 @@ static ref HISTORY_MANAGER: HistoryManager = {
};

HistoryManager { history }
};
}
});


pub struct HistoryManager {
history: History,
Expand Down
56 changes: 27 additions & 29 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
*
*/

use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use iced::{Color, Theme};
use iced::theme::Custom;
use iced::theme::Palette;
use iced::theme::palette::{Background, Danger, Extended, Pair, Primary, Secondary, Success};
use lazy_static::lazy_static;

pub(crate) mod calculator;
pub(crate) mod messages;
Expand Down Expand Up @@ -58,33 +57,32 @@ pub static PALETT_LCD: Palette = Palette {
),
};

lazy_static! {
static ref LCD_THEME: Theme =
Theme::Custom(Arc::new(Custom::with_fn(String::from("Lcd Calculator"), PALETT_LCD, |palette| -> Extended {
Extended {
background: Background{
weak: Pair::new(Color::from_rgb8(0x00,0x50,0x60), palette.text), // Grey Blue
.. Background::new(palette.background, palette.text)
},
primary: Primary::generate(palette.primary, palette.background, palette.text),
secondary: Secondary{
strong: Pair::new(Color::from_rgb8(0x04,0x04,0x04,), palette.text),
.. Secondary::generate(Color::BLACK, Color::WHITE)
},
success: Success::generate(
palette.primary,
Color::BLACK,
Color::WHITE,
),
danger: Danger::generate(
palette.danger,
palette.background,
palette.text,
),
is_dark: false,
}
})));
}
static LCD_THEME: LazyLock<Theme> = LazyLock::new( || {
Theme::Custom(Arc::new(Custom::with_fn(String::from("Lcd Calculator"), PALETT_LCD, |palette| -> Extended {
Extended {
background: Background {
weak: Pair::new(Color::from_rgb8(0x00, 0x50, 0x60), palette.text), // Grey Blue
..Background::new(palette.background, palette.text)
},
primary: Primary::generate(palette.primary, palette.background, palette.text),
secondary: Secondary {
strong: Pair::new(Color::from_rgb8(0x04, 0x04, 0x04, ), palette.text),
..Secondary::generate(Color::BLACK, Color::WHITE)
},
success: Success::generate(
palette.primary,
Color::BLACK,
Color::WHITE,
),
danger: Danger::generate(
palette.danger,
palette.background,
palette.text,
),
is_dark: true,
}
})))
});

fn lcd_theme() -> &'static Theme {
&LCD_THEME
Expand Down
10 changes: 5 additions & 5 deletions src/ui/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use std::{
str::FromStr,
sync::{Arc, RwLock},
};
use std::sync::LazyLock;

use lazy_static::lazy_static;
use log::{error, info, warn};
use preferences::{AppInfo, Preferences, PreferencesMap};

Expand All @@ -41,8 +41,8 @@ pub static APP_INFO: AppInfo = AppInfo {
pub static ANGLE_MODE: &str = "angle-mode";
pub static THEME: &str = "theme";

lazy_static! {
static ref MANAGER: PreferenceManager = PreferenceManager {
static MANAGER: LazyLock<PreferenceManager> = LazyLock::new( || {
PreferenceManager {
preferences: {
match PreferencesMap::<String>::load(&APP_INFO, PREFS_PATH) {
Ok(map) => Arc::new(RwLock::new(map)),
Expand All @@ -54,8 +54,8 @@ lazy_static! {
}
},
path: PREFS_PATH,
};
}
}
});

pub struct PreferenceManager {
preferences: Arc<RwLock<PreferencesMap>>,
Expand Down

0 comments on commit 6ab1a99

Please sign in to comment.