-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Labels
A-frameworkAffects the framework crates and the translator for themAffects the framework crates and the translator for themenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
It might make sense to add helper methods to AnyObject
and CFType
to allow more easily converting to common property list types (CF docs, Cocoa docs, core-foundation
source).
Something like the following:
/// Property list helpers.
impl [AnyObject|CFType] {
pub fn as_string(&self) -> Option<&[NS|CF]String> {
self.downcast_ref()
}
pub fn as_number(&self) -> Option<&[NS|CF]Number> {
self.downcast_ref()
}
pub fn as_data(&self) -> Option<&[NS|CF]Data> {
self.downcast_ref()
}
pub fn as_array(&self) -> Option<&[NS|CF]Array> {
self.downcast_ref()
}
pub fn as_dict(&self) -> Option<&[NS|CF]Dictionary> {
self.downcast_ref()
}
pub fn as_date(&self) -> Option<&[NS|CF]Date> {
self.downcast_ref()
}
// Only on CFType
pub fn as_bool(&self) -> Option<&[NS|CF]Boolean> {
self.downcast_ref()
}
}
An alternative would be to wrap these in a newtype that provided much the same, but I suspect that'd be less ergonomic. Yet another alternative would be to eagerly convert to an enum
, but that'd probably be less performant.
We should also make sure it's easy to use dictionary getter methods here.
Metadata
Metadata
Assignees
Labels
A-frameworkAffects the framework crates and the translator for themAffects the framework crates and the translator for themenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers