Skip to content

Commit

Permalink
Close#74issues (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathNuba authored Feb 29, 2024
1 parent 27b37a5 commit e68d8a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 0 additions & 1 deletion dessin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dessin-macros = { path = "../dessin-macros", version = "0.8.19-pre" }
fontdue = "^0.8.0"
image = "^0.24.8"
nalgebra = "^0.32.3"
once_cell = "^1.19.0"
# palette = "^0.7.2"

[dev-dependencies]
Expand Down
13 changes: 5 additions & 8 deletions dessin/src/shapes/text/font.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use super::FontWeight;
use once_cell::sync::OnceCell;
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};
use std::sync::OnceLock;
use std::{collections::HashMap, sync::RwLock};

static FONT_HOLDER: OnceCell<Arc<RwLock<FontHolder>>> = OnceCell::new();
static FONT_HOLDER: OnceLock<RwLock<FontHolder>> = OnceLock::new();

fn font_holder<T, F: FnOnce(&FontHolder) -> T>(f: F) -> T {
f(&FONT_HOLDER
.get_or_init(|| Arc::new(RwLock::new(FontHolder::new())))
.get_or_init(|| RwLock::new(FontHolder::new()))
.read()
.unwrap())
}

fn font_holder_mut<T, F: FnOnce(&mut FontHolder) -> T>(f: F) -> T {
f(&mut FONT_HOLDER
.get_or_init(|| Arc::new(RwLock::new(FontHolder::new())))
.get_or_init(|| RwLock::new(FontHolder::new())) // RwLock is needed to have a mutable case
.write()
.unwrap())
}
Expand Down

0 comments on commit e68d8a1

Please sign in to comment.