-
Notifications
You must be signed in to change notification settings - Fork 14
add analogous fallible font fetching methods #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add analogous fallible font fetching methods #62
Conversation
src/font_family.rs
Outdated
.unwrap() | ||
} | ||
|
||
pub fn try_get_first_matching_font( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Rust idiomatically doesn't use the word get_
in method names, I wonder if a way to do this would be to make the fallible ones names like first_matching_font
and then to deprecate the non-fallible versions. That way we could gradually transition to a more idiomatically-Rust-like interface. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me! Will update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've updated the names and #[deprecated]
the old methods.
self.font(index).unwrap() | ||
} | ||
|
||
pub fn font(&self, index: u32) -> Result<Font, HRESULT> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little unsure about the name font
for this method. Any suggestions? font_from_index
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
font_at_index
or font_from_index
both sound good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I think this looks good. I do agree that font_at_index
/font_from_index
might be a better name, but this could probably land without that as well.
@acarl005 Thanks for the change! Let me know if you like to rename |
@mrobinson nah, I like the name actually. |
This closes #61
Some of the methods in
font_family::FontFamily
can cause a panic. I have added analogoustry_
methods for each which will return aResult
instead in order to let the caller handle the error.The next step would be to start migrating callers to use these new methods, e.g.
https://github.com/servo/font-kit/blob/d49041ca57da4e9b412951f96f74cb34e3b6324f/src/sources/directwrite.rs#L44