Skip to content

Commit

Permalink
Make hashbrown optional (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-fl3 committed May 13, 2024
1 parent 350a689 commit c86ce94
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ exclude = ["dev/**"]
maintenance = { status = "experimental" }

[features]
default = ["simd"]
default = ["simd", "hashbrown"]
# Enable this flag to use std::HashMap instead of hashbrown::HashMap
std = []
# Enable this flag to leverage SIMD usage on x86/x86_64 platforms.
simd = []
# Enable this flag to parallelize font loading using threads.
parallel = ["rayon", "hashbrown/rayon"]
parallel = ["rayon", "hashbrown", "hashbrown/rayon"]

[dependencies]
ttf-parser = { version = "0.20", default-features = false, features = [
"opentype-layout",
] }
hashbrown = "0.14"
hashbrown = { version = "0.14", optional = true }
rayon = { version = "1.5.1", optional = true }
3 changes: 3 additions & 0 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use core::hash::{Hash, Hasher};
use core::mem;
use core::num::NonZeroU16;
use core::ops::Deref;
#[cfg(feature = "hashbrown")]
use hashbrown::{HashMap, HashSet};
#[cfg(not(feature = "hashbrown"))]
use std::collections::{HashMap, HashSet};

Check failure on line 18 in src/font.rs

View workflow job for this annotation

GitHub Actions / src

failed to resolve: use of undeclared crate or module `std`

Check failure on line 18 in src/font.rs

View workflow job for this annotation

GitHub Actions / src

failed to resolve: use of undeclared crate or module `std`
use ttf_parser::{Face, FaceParsingError, GlyphId, Tag};

#[cfg(feature = "parallel")]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This is a no_std crate, but still requires the alloc crate.

#![no_std]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
#![allow(dead_code)]
#![allow(clippy::style)]
#![allow(clippy::complexity)]
Expand Down
3 changes: 3 additions & 0 deletions src/table/gsub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[cfg(feature = "hashbrown")]
use hashbrown::HashSet;
#[cfg(not(feature = "hashbrown"))]
use std::collections::HashSet;

Check failure on line 4 in src/table/gsub.rs

View workflow job for this annotation

GitHub Actions / src

failed to resolve: use of undeclared crate or module `std`

Check failure on line 4 in src/table/gsub.rs

View workflow job for this annotation

GitHub Actions / src

failed to resolve: use of undeclared crate or module `std`
use ttf_parser::Face;

pub fn load_gsub(face: &Face, indices_to_load: &mut HashSet<u16>) {
Expand Down
3 changes: 3 additions & 0 deletions src/table/kern.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::table::parse::*;
#[cfg(feature = "hashbrown")]
use hashbrown::HashMap;
#[cfg(not(feature = "hashbrown"))]
use std::collections::HashMap;

Check failure on line 5 in src/table/kern.rs

View workflow job for this annotation

GitHub Actions / src

failed to resolve: use of undeclared crate or module `std`

Check failure on line 5 in src/table/kern.rs

View workflow job for this annotation

GitHub Actions / src

failed to resolve: use of undeclared crate or module `std`

// Apple: https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6kern.html
// Microsoft: https://docs.microsoft.com/en-us/typography/opentype/spec/kern
Expand Down

0 comments on commit c86ce94

Please sign in to comment.