diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/rust/core-foundation/src/propertylist.rs | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/core-foundation/src/propertylist.rs')
-rw-r--r-- | third_party/rust/core-foundation/src/propertylist.rs | 109 |
1 files changed, 57 insertions, 52 deletions
diff --git a/third_party/rust/core-foundation/src/propertylist.rs b/third_party/rust/core-foundation/src/propertylist.rs index e8fceac58d..de5d1d87ba 100644 --- a/third_party/rust/core-foundation/src/propertylist.rs +++ b/third_party/rust/core-foundation/src/propertylist.rs @@ -9,30 +9,34 @@ //! Core Foundation property lists -use std::ptr; use std::mem; use std::os::raw::c_void; +use std::ptr; -use error::CFError; -use data::CFData; -use base::{CFType, TCFType, TCFTypeRef}; +use crate::base::{CFType, TCFType, TCFTypeRef}; +use crate::data::CFData; +use crate::error::CFError; -pub use core_foundation_sys::propertylist::*; +use core_foundation_sys::base::{ + kCFAllocatorDefault, CFGetRetainCount, CFGetTypeID, CFIndex, CFRetain, CFShow, CFTypeID, +}; use core_foundation_sys::error::CFErrorRef; -use core_foundation_sys::base::{CFGetRetainCount, CFGetTypeID, CFIndex, CFRetain, - CFShow, CFTypeID, kCFAllocatorDefault}; +pub use core_foundation_sys::propertylist::*; -pub fn create_with_data(data: CFData, - options: CFPropertyListMutabilityOptions) - -> Result<(*const c_void, CFPropertyListFormat), CFError> { +pub fn create_with_data( + data: CFData, + options: CFPropertyListMutabilityOptions, +) -> Result<(*const c_void, CFPropertyListFormat), CFError> { unsafe { let mut error: CFErrorRef = ptr::null_mut(); let mut format: CFPropertyListFormat = 0; - let property_list = CFPropertyListCreateWithData(kCFAllocatorDefault, - data.as_concrete_TypeRef(), - options, - &mut format, - &mut error); + let property_list = CFPropertyListCreateWithData( + kCFAllocatorDefault, + data.as_concrete_TypeRef(), + options, + &mut format, + &mut error, + ); if property_list.is_null() { Err(TCFType::wrap_under_create_rule(error)) } else { @@ -41,14 +45,14 @@ pub fn create_with_data(data: CFData, } } -pub fn create_data(property_list: *const c_void, format: CFPropertyListFormat) -> Result<CFData, CFError> { +pub fn create_data( + property_list: *const c_void, + format: CFPropertyListFormat, +) -> Result<CFData, CFError> { unsafe { let mut error: CFErrorRef = ptr::null_mut(); - let data_ref = CFPropertyListCreateData(kCFAllocatorDefault, - property_list, - format, - 0, - &mut error); + let data_ref = + CFPropertyListCreateData(kCFAllocatorDefault, property_list, format, 0, &mut error); if data_ref.is_null() { Err(TCFType::wrap_under_create_rule(error)) } else { @@ -57,7 +61,6 @@ pub fn create_data(property_list: *const c_void, format: CFPropertyListFormat) - } } - /// Trait for all subclasses of [`CFPropertyList`]. /// /// [`CFPropertyList`]: struct.CFPropertyList.html @@ -84,16 +87,15 @@ pub trait CFPropertyListSubClass: TCFType { } } -impl CFPropertyListSubClass for ::data::CFData {} -impl CFPropertyListSubClass for ::string::CFString {} -impl CFPropertyListSubClass for ::array::CFArray {} -impl CFPropertyListSubClass for ::dictionary::CFDictionary {} -impl CFPropertyListSubClass for ::date::CFDate {} -impl CFPropertyListSubClass for ::boolean::CFBoolean {} -impl CFPropertyListSubClass for ::number::CFNumber {} - +impl CFPropertyListSubClass for crate::data::CFData {} +impl CFPropertyListSubClass for crate::string::CFString {} +impl CFPropertyListSubClass for crate::array::CFArray {} +impl CFPropertyListSubClass for crate::dictionary::CFDictionary {} +impl CFPropertyListSubClass for crate::date::CFDate {} +impl CFPropertyListSubClass for crate::boolean::CFBoolean {} +impl CFPropertyListSubClass for crate::number::CFNumber {} -declare_TCFType!{ +declare_TCFType! { /// A CFPropertyList struct. This is superclass to [`CFData`], [`CFString`], [`CFArray`], /// [`CFDictionary`], [`CFDate`], [`CFBoolean`], and [`CFNumber`]. /// @@ -161,8 +163,8 @@ impl CFPropertyList { unsafe { CFGetRetainCount(self.as_CFTypeRef()) } } - /// Returns the type ID of this object. Will be one of CFData, CFString, CFArray, CFDictionary, - /// CFDate, CFBoolean, or CFNumber. + /// Returns the type ID of this object. Will be one of `CFData`, `CFString`, `CFArray`, + /// `CFDictionary`, `CFDate`, `CFBoolean`, or `CFNumber`. #[inline] pub fn type_of(&self) -> CFTypeID { unsafe { CFGetTypeID(self.as_CFTypeRef()) } @@ -173,7 +175,7 @@ impl CFPropertyList { unsafe { CFShow(self.as_CFTypeRef()) } } - /// Returns true if this value is an instance of another type. + /// Returns `true` if this value is an instance of another type. #[inline] pub fn instance_of<OtherCFType: TCFType>(&self) -> bool { self.type_of() == OtherCFType::type_id() @@ -244,33 +246,33 @@ impl CFPropertyList { } } - - #[cfg(test)] pub mod test { use super::*; - use string::CFString; - use boolean::CFBoolean; + use crate::boolean::CFBoolean; + use crate::string::CFString; #[test] fn test_property_list_serialization() { - use base::{TCFType, CFEqual}; - use boolean::CFBoolean; - use number::CFNumber; - use dictionary::CFDictionary; - use string::CFString; use super::*; + use crate::base::{CFEqual, TCFType}; + use crate::boolean::CFBoolean; + use crate::dictionary::CFDictionary; + use crate::number::CFNumber; + use crate::string::CFString; let bar = CFString::from_static_string("Bar"); let baz = CFString::from_static_string("Baz"); let boo = CFString::from_static_string("Boo"); let foo = CFString::from_static_string("Foo"); let tru = CFBoolean::true_value(); - let n42 = CFNumber::from(1i64<<33); + let n42 = CFNumber::from(1i64 << 33); - let dict1 = CFDictionary::from_CFType_pairs(&[(bar.as_CFType(), boo.as_CFType()), - (baz.as_CFType(), tru.as_CFType()), - (foo.as_CFType(), n42.as_CFType())]); + let dict1 = CFDictionary::from_CFType_pairs(&[ + (bar.as_CFType(), boo.as_CFType()), + (baz.as_CFType(), tru.as_CFType()), + (foo.as_CFType(), n42.as_CFType()), + ]); let data = create_data(dict1.as_CFTypeRef(), kCFPropertyListXMLFormat_v1_0).unwrap(); let (dict2, _) = create_with_data(data, kCFPropertyListImmutable).unwrap(); @@ -281,7 +283,7 @@ pub mod test { #[test] fn to_propertylist_retain_count() { - let string = CFString::from_static_string("Bar"); + let string = CFString::from_static_string("alongerstring"); assert_eq!(string.retain_count(), 1); let propertylist = string.to_CFPropertyList(); @@ -295,7 +297,10 @@ pub mod test { #[test] fn downcast_string() { let propertylist = CFString::from_static_string("Bar").to_CFPropertyList(); - assert_eq!(propertylist.downcast::<CFString>().unwrap().to_string(), "Bar"); + assert_eq!( + propertylist.downcast::<CFString>().unwrap().to_string(), + "Bar" + ); assert!(propertylist.downcast::<CFBoolean>().is_none()); } @@ -308,7 +313,7 @@ pub mod test { #[test] fn downcast_into_fail() { - let string = CFString::from_static_string("Bar"); + let string = CFString::from_static_string("alongerstring"); let propertylist = string.to_CFPropertyList(); assert_eq!(string.retain_count(), 2); @@ -318,12 +323,12 @@ pub mod test { #[test] fn downcast_into() { - let string = CFString::from_static_string("Bar"); + let string = CFString::from_static_string("alongerstring"); let propertylist = string.to_CFPropertyList(); assert_eq!(string.retain_count(), 2); let string2 = propertylist.downcast_into::<CFString>().unwrap(); - assert_eq!(string2.to_string(), "Bar"); + assert_eq!(string2.to_string(), "alongerstring"); assert_eq!(string2.retain_count(), 2); } } |