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 CFPropertyList and methods for casting to subclasses #131
Changes from 1 commit
File filter...
Jump to…
Improve documentation with links
- Loading branch information
| @@ -60,9 +60,13 @@ pub fn create_data(property_list: *const c_void, format: CFPropertyListFormat) - | ||
| } | ||
|
|
||
|
|
||
| /// Trait for all subclasses of CFPropertyList. | ||
| /// Trait for all subclasses of [`CFPropertyList`]. | ||
| /// | ||
| /// [`CFPropertyList`]: struct.CFPropertyList.html | ||
| pub trait CFPropertyListSubClass<Raw>: TCFType<*const Raw> { | ||
faern
Author
Contributor
|
||
| /// Create an instance of the superclass type `CFPropertyList` for this instance. | ||
| /// Create an instance of the superclass type [`CFPropertyList`] for this instance. | ||
| /// | ||
| /// [`CFPropertyList`]: struct.CFPropertyList.html | ||
| fn to_CFPropertyList(&self) -> CFPropertyList { | ||
| unsafe { CFPropertyList::wrap_under_get_rule(self.as_concrete_TypeRef() as *const c_void) } | ||
| } | ||
| @@ -76,12 +80,22 @@ impl CFPropertyListSubClass<::date::__CFDate> for ::date::CFDate {} | ||
| impl CFPropertyListSubClass<::number::__CFBoolean> for ::boolean::CFBoolean {} | ||
| impl CFPropertyListSubClass<::number::__CFNumber> for ::number::CFNumber {} | ||
|
|
||
| /// A CFPropertyList struct. This is superclass to CFData, CFString, CFArray, CFDictionary, | ||
| /// CFDate, CFBoolean, and CFNumber. | ||
| /// A CFPropertyList struct. This is superclass to [`CFData`], [`CFString`], [`CFArray`], | ||
| /// [`CFDictionary`], [`CFDate`], [`CFBoolean`], and [`CFNumber`]. | ||
| /// | ||
| /// This superclass type does not have its own CFTypeID, instead each instance has the CFTypeID of | ||
| /// the subclass it is an instance of. Thus, this type cannot implement the `TCFType` trait, since | ||
| /// it cannot implement the static `TCFType::type_id()` method. | ||
| /// This superclass type does not have its own `CFTypeID`, instead each instance has the `CFTypeID` | ||
| /// of the subclass it is an instance of. Thus, this type cannot implement the [`TCFType`] trait, | ||
| /// since it cannot implement the static [`TCFType::type_id()`] method. | ||
| /// | ||
| /// [`CFData`]: ../data/struct.CFData.html | ||
| /// [`CFString`]: ../string/struct.CFString.html | ||
| /// [`CFArray`]: ../array/struct.CFArray.html | ||
| /// [`CFDictionary`]: ../dictionary/struct.CFDictionary.html | ||
| /// [`CFDate`]: ../date/struct.CFDate.html | ||
| /// [`CFBoolean`]: ../boolean/struct.CFBoolean.html | ||
| /// [`CFNumber`]: ../number/struct.CFNumber.html | ||
| /// [`TCFType`]: ../base/trait.TCFType.html | ||
| /// [`TCFType::type_id()`]: ../base/trait.TCFType.html#method.type_of | ||
| pub struct CFPropertyList(CFPropertyListRef); | ||
|
|
||
| impl Drop for CFPropertyList { | ||
| @@ -162,9 +176,9 @@ impl PartialEq for CFPropertyList { | ||
| impl Eq for CFPropertyList {} | ||
|
|
||
| impl CFPropertyList { | ||
| /// Try to downcast the CFPropertyList to a subclass. Checking if the instance is the correct | ||
| /// Try to downcast the [`CFPropertyList`] to a subclass. Checking if the instance is the correct | ||
| /// subclass happens at runtime and an error is returned if it is not the correct type. | ||
| /// Works similar to `Box::downcast`. | ||
| /// Works similar to [`Box::downcast`]. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| @@ -179,6 +193,9 @@ impl CFPropertyList { | ||
| /// // Cast it down again. | ||
| /// assert!(propertylist.downcast::<_, CFString>().unwrap().to_string() == "FooBar"); | ||
| /// ``` | ||
| /// | ||
| /// [`CFPropertyList`]: struct.CFPropertyList.html | ||
| /// [`Box::downcast`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.downcast | ||
| pub fn downcast<Raw, T: CFPropertyListSubClass<Raw>>(&self) -> Result<T, CFPropertyListCastError> { | ||
| if self.instance_of::<_, T>() { | ||
| Ok(unsafe { T::wrap_under_get_rule(self.0 as *const Raw) }) | ||
We should be able to do
pub trait CFPropertyListSubClass: TCFType<*const Self> {and avoid some redundancy in the implementations.