diff --git a/src/cff/subroutines.rs b/src/cff/subroutines.rs index 2eeb044d..4c6181a7 100644 --- a/src/cff/subroutines.rs +++ b/src/cff/subroutines.rs @@ -14,7 +14,7 @@ impl<'a> SubroutineCollection<'a> { } } - pub fn get_handler(&self, fd_index: u8) -> Option { + pub fn get_handler(&self, fd_index: u8) -> Option> { self.subroutines.get(fd_index as usize).map(|s| s.get_handler()) } } @@ -29,7 +29,7 @@ impl<'a> SubroutineContainer<'a> { Self { subroutines } } - pub fn get_handler(&self) -> SubroutineHandler { + pub fn get_handler(&self) -> SubroutineHandler<'_> { SubroutineHandler::new(self.subroutines.as_ref()) } } diff --git a/src/lib.rs b/src/lib.rs index cff72616..ad380cef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,9 +92,11 @@ use crate::read::{Readable, Reader}; pub use crate::remapper::GlyphRemapper; use crate::write::{Writeable, Writer}; use crate::Error::{MalformedFont, Unimplemented, UnknownKind}; +use std::array::TryFromSliceError; use std::borrow::Cow; use std::fmt::{self, Debug, Display, Formatter}; use std::marker::PhantomData; +use std::str::FromStr; /// Subset the font face to include only the necessary glyphs and tables. /// @@ -169,7 +171,7 @@ fn prepare_context<'a>( let _ = variation_coordinates; #[cfg(not(feature = "variable-fonts"))] - let interjector = Interjector::Dummy(PhantomData::default()); + let interjector = Interjector::Dummy(PhantomData); // For CFF, we _always_ want to do normal subsetting, since CFF cannot have variations. // For TrueType, we prefer normal subsetting in case no variation was requested. If we do have // variations, we use `skrifa` to instance. @@ -181,7 +183,7 @@ fn prepare_context<'a>( { // For TrueType and CFF, we are still best off using the normal subsetting logic in case no variation coordinates // have been passed. - Interjector::Dummy(PhantomData::default()) + Interjector::Dummy(PhantomData) } else { Interjector::Skrifa( interjector::skrifa::SkrifaInterjector::new( @@ -494,21 +496,23 @@ impl Tag { Self(*tag) } - /// Try to create a new tag from a string. - /// - /// Return `None` if the string is not 4 bytes in size. - pub fn from_str(s: &str) -> Option { - let tag: [u8; 4] = s.as_bytes().try_into().ok()?; - - Some(Self(tag)) - } - /// Return the value of the tag. pub fn get(&self) -> &[u8; 4] { &self.0 } } +impl FromStr for Tag { + type Err = TryFromSliceError; + + /// Tries to create a new tag from a string. + /// + /// Return `Err(_)` if the string is not 4 bytes in size. + fn from_str(s: &str) -> std::result::Result { + s.as_bytes().try_into().map(Self) + } +} + #[allow(unused)] impl Tag { // General tables. diff --git a/tests/src/main.rs b/tests/src/main.rs index 21ba43d0..16b602a7 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -5,6 +5,7 @@ use skrifa::MetadataProvider; use std::error::Error; use std::path::{Path, PathBuf}; use std::process::Command; +use std::str::FromStr; use subsetter::{subset, subset_with_variations, GlyphRemapper, Tag}; use ttf_parser::GlyphId;