Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
pub use core::borrow::Borrow;
pub use core::cmp::{Eq, PartialEq};
pub use core::convert::AsRef;
pub use core::fmt;
pub use core::hash::{Hash, Hasher};
pub use core::marker::Sized;
pub use core::mem::transmute;
pub use core::ops::Deref;
pub use core::primitive::bool;
pub use core::stringify;
#[cfg(feature = "objc2")]
pub use objc2::cf_objc2_type;

View File

@@ -0,0 +1,682 @@
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
use core::ffi::c_void;
use core::{borrow::Borrow, mem};
use crate::{kCFTypeArrayCallBacks, CFArray, CFIndex, CFMutableArray, CFRetained, Type};
#[inline]
fn get_len<T>(objects: &[T]) -> CFIndex {
// An allocation in Rust cannot be larger than isize::MAX, so this will
// never fail.
//
// Note that `CFArray::new` documents:
// > If this parameter is negative, [...] the behavior is undefined.
let len = objects.len();
debug_assert!(len < CFIndex::MAX as usize);
len as CFIndex
}
/// Reading the source code:
/// <https://github.com/apple-oss-distributions/CF/blob/CF-1153.18/CFArray.c#L391>
/// <https://github.com/apple-oss-distributions/CF/blob/CF-1153.18/CFRuntime.c#L323>
///
/// It is clear that creating arrays can only realistically fail if allocating
/// failed. So we choose to panic/abort in those cases, to roughly match
/// `Vec`'s behaviour.
#[cold]
fn failed_creating_array(len: CFIndex) -> ! {
#[cfg(feature = "alloc")]
{
use alloc::alloc::{handle_alloc_error, Layout};
use core::mem::align_of;
// The layout here is not correct, only best-effort (CFArray adds
// extra padding when allocating).
let layout = Layout::array::<*const ()>(len as usize).unwrap_or_else(|_| unsafe {
Layout::from_size_align_unchecked(0, align_of::<*const ()>())
});
handle_alloc_error(layout)
}
#[cfg(not(feature = "alloc"))]
{
panic!("failed allocating CFArray holding {len} elements")
}
}
/// Convenience creation methods.
impl<T: ?Sized> CFArray<T> {
/// Create a new empty `CFArray` capable of holding CoreFoundation
/// objects.
#[inline]
#[doc(alias = "CFArray::new")]
pub fn empty() -> CFRetained<Self>
where
T: Type,
{
// It may not strictly be necessary to use correct array callbacks
// here, though it's good to know that it's correct for use in e.g.
// `CFMutableArray::newCopy`.
Self::from_objects(&[])
}
/// Create a new `CFArray` with the given CoreFoundation objects.
#[inline]
#[doc(alias = "CFArray::new")]
pub fn from_objects(objects: &[&T]) -> CFRetained<Self>
where
T: Type,
{
let len = get_len(objects);
// `&T` has the same layout as `*const c_void`, and are non-NULL.
let ptr = objects.as_ptr().cast::<*const c_void>().cast_mut();
// SAFETY: The objects are CFTypes (`T: Type` bound), and the array
// callbacks are thus correct.
//
// The objects are retained internally by the array, so we do not need
// to keep them alive ourselves after this.
let array = unsafe { CFArray::new(None, ptr, len, &kCFTypeArrayCallBacks) }
.unwrap_or_else(|| failed_creating_array(len));
// SAFETY: The objects came from `T`.
unsafe { CFRetained::cast_unchecked::<Self>(array) }
}
/// Alias for easier transition from the `core-foundation` crate.
#[inline]
#[allow(non_snake_case)]
#[deprecated = "renamed to CFArray::from_objects"]
pub fn from_CFTypes(objects: &[&T]) -> CFRetained<Self>
where
T: Type,
{
Self::from_objects(objects)
}
/// Create a new `CFArray` with the given retained CoreFoundation objects.
#[inline]
#[doc(alias = "CFArray::new")]
pub fn from_retained_objects(objects: &[CFRetained<T>]) -> CFRetained<Self>
where
T: Type,
{
let len = get_len(objects);
// `CFRetained<T>` has the same layout as `*const c_void`.
let ptr = objects.as_ptr().cast::<*const c_void>().cast_mut();
// SAFETY: Same as in `from_objects`.
let array = unsafe { CFArray::new(None, ptr, len, &kCFTypeArrayCallBacks) }
.unwrap_or_else(|| failed_creating_array(len));
// SAFETY: The objects came from `T`.
unsafe { CFRetained::cast_unchecked::<Self>(array) }
}
}
/// Convenience creation methods.
impl<T: ?Sized> CFMutableArray<T> {
/// Create a new empty mutable array.
#[inline]
#[doc(alias = "CFMutableArray::new")]
pub fn empty() -> CFRetained<Self>
where
T: Type,
{
Self::with_capacity(0)
}
/// Create a new mutable array with the given capacity.
#[inline]
#[doc(alias = "CFMutableArray::new")]
pub fn with_capacity(capacity: usize) -> CFRetained<Self>
where
T: Type,
{
// User can pass wrong value here, we must check.
let capacity = capacity.try_into().expect("capacity too high");
// SAFETY: The objects are CFTypes (`T: Type` bound), and the array
// callbacks are thus correct.
let array = unsafe { CFMutableArray::new(None, capacity, &kCFTypeArrayCallBacks) }
.unwrap_or_else(|| failed_creating_array(capacity));
// SAFETY: The array contains no objects yet, and thus it's safe to
// cast them to `T` (as the array callbacks are matching).
unsafe { CFRetained::cast_unchecked::<Self>(array) }
}
}
// TODO: Do we want to pass NULL callbacks or `CFArrayEqualCallBack`.
// impl CFArray<()> {
// /// Create a new `CFArray` with the given retained CoreFoundation objects.
// pub fn from_usize(objects: &[usize]) -> CFRetained<Self> {
// let len = get_len(objects);
// // `CFRetained<T>` has the same layout as `*const c_void`.
// let ptr: *const c_void = objects.as_ptr().cast();
//
// // SAFETY: Same as in `from_objects`.
// let array = unsafe { CFArray::new(None, ptr, len, null) }
// .unwrap_or(|| failed_creating_array(len));
//
// // SAFETY: The objects came from `T`.
// unsafe { CFRetained::cast_unchecked::<Self>(array) }
// }
// }
/// Direct, unsafe object accessors.
///
/// CFArray stores its values directly, and you can get references to said
/// values data without having to retain it first - but only if the array
/// isn't mutated while doing so - otherwise, we might end up accessing a
/// deallocated object.
impl<T: ?Sized> CFArray<T> {
/// Get a direct reference to one of the array's objects.
///
/// Consider using the [`get`](Self::get) method instead, unless you're
/// seeing performance issues from the retaining.
///
/// # Safety
///
/// - The index must not be negative, and must be in bounds of the array.
/// - The array must not be mutated while the returned reference is live.
#[inline]
#[doc(alias = "CFArrayGetValueAtIndex")]
pub unsafe fn get_unchecked(&self, index: CFIndex) -> &T
where
T: Type + Sized,
{
// SAFETY: Caller ensures that `index` is in bounds.
let ptr = unsafe { self.as_opaque().value_at_index(index) };
// SAFETY: The array's values are of type `T`, and the objects are
// CoreFoundation types (and thus cannot be NULL).
//
// Caller ensures that the array isn't mutated for the lifetime of the
// reference.
unsafe { &*ptr.cast::<T>() }
}
/// A vector containing direct references to the array's objects.
///
/// Consider using the [`to_vec`](Self::to_vec) method instead, unless
/// you're seeing performance issues from the retaining.
///
/// # Safety
///
/// The array must not be mutated while the returned references are alive.
#[cfg(feature = "alloc")]
#[doc(alias = "CFArrayGetValues")]
pub unsafe fn to_vec_unchecked(&self) -> Vec<&T>
where
T: Type,
{
let len = self.len();
let range = crate::CFRange {
location: 0,
// Fine to cast, it came from CFIndex
length: len as CFIndex,
};
let mut vec = Vec::<&T>::with_capacity(len);
// `&T` has the same layout as `*const c_void`.
let ptr = vec.as_mut_ptr().cast::<*const c_void>();
// SAFETY: The range is in bounds
unsafe { self.as_opaque().values(range, ptr) };
// SAFETY: Just initialized the Vec above.
unsafe { vec.set_len(len) };
vec
}
/// Iterate over the array without touching the elements.
///
/// Consider using the [`iter`](Self::iter) method instead, unless you're
/// seeing performance issues from the retaining.
///
/// # Safety
///
/// The array must not be mutated for the lifetime of the iterator or for
/// the lifetime of the elements the iterator returns.
#[inline]
pub unsafe fn iter_unchecked(&self) -> CFArrayIterUnchecked<'_, T>
where
T: Type,
{
CFArrayIterUnchecked {
array: self,
index: 0,
len: self.len() as CFIndex,
}
}
}
/// Various accessor methods.
impl<T: ?Sized> CFArray<T> {
/// Convert to the opaque/untyped variant.
pub fn as_opaque(&self) -> &CFArray {
// SAFETY: The array stores objects behind a reference, and can all be
// represented by `crate::opaque::Opaque`.
unsafe { mem::transmute::<&CFArray<T>, &CFArray>(self) }
}
/// The amount of elements in the array.
#[inline]
#[doc(alias = "CFArrayGetCount")]
pub fn len(&self) -> usize {
// Fine to cast here, the count is never negative.
self.as_opaque().count() as _
}
/// Whether the array is empty or not.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Retrieve the object at the given index.
///
/// Returns `None` if the index was out of bounds.
#[doc(alias = "CFArrayGetValueAtIndex")]
pub fn get(&self, index: usize) -> Option<CFRetained<T>>
where
T: Type + Sized,
{
if index < self.len() {
// Index is `usize` and just compared below the length (which is
// at max `CFIndex::MAX`), so a cast is safe here.
let index = index as CFIndex;
// SAFETY:
// - Just checked that the index is in bounds.
// - We retain the value right away, so that the reference is not
// used while the array is mutated.
//
// Note that this is _technically_ wrong; the user _could_ have
// implemented a `retain` method that mutates the array. We're
// going to rule this out though, as that's basically never going
// to happen, and will make a lot of other things unsound too.
Some(unsafe { self.get_unchecked(index) }.retain())
} else {
None
}
}
/// Convert the array to a `Vec` of the array's objects.
#[cfg(feature = "alloc")]
#[doc(alias = "CFArrayGetValues")]
pub fn to_vec(&self) -> Vec<CFRetained<T>>
where
T: Type + Sized,
{
// SAFETY: We retain the elements below, so we know that the array
// isn't mutated while the references are alive.
let vec = unsafe { self.to_vec_unchecked() };
vec.into_iter().map(T::retain).collect()
}
/// Iterate over the array's elements.
#[inline]
pub fn iter(&self) -> CFArrayIter<'_, T> {
CFArrayIter {
array: self,
index: 0,
}
}
}
/// Various accessor methods.
impl<T: ?Sized> CFMutableArray<T> {
/// Convert to the opaque/untyped variant.
pub fn as_opaque(&self) -> &CFMutableArray {
// SAFETY: Same as `CFArray::as_opaque`.
unsafe { mem::transmute::<&CFMutableArray<T>, &CFMutableArray>(self) }
}
}
/// Convenience mutation methods.
impl<T> CFMutableArray<T> {
/// Push an object to the end of the array.
#[inline]
#[doc(alias = "CFArrayAppendValue")]
pub fn append(&self, obj: &T) {
let ptr: *const T = obj;
let ptr: *const c_void = ptr.cast();
// SAFETY: The pointer is valid.
unsafe { CFMutableArray::append_value(Some(self.as_opaque()), ptr) }
}
/// Insert an object into the array at the given index.
///
/// # Panics
///
/// Panics if the index is out of bounds.
#[doc(alias = "CFArrayInsertValueAtIndex")]
pub fn insert(&self, index: usize, obj: &T) {
// TODO: Replace this check with catching the thrown NSRangeException
let len = self.len();
if index <= len {
let ptr: *const T = obj;
let ptr: *const c_void = ptr.cast();
// SAFETY: The pointer is valid, and just checked that the index
// is in bounds.
unsafe {
CFMutableArray::insert_value_at_index(Some(self.as_opaque()), index as CFIndex, ptr)
}
} else {
panic!(
"insertion index (is {}) should be <= len (is {})",
index, len
);
}
}
}
/// An iterator over retained objects of an array.
#[derive(Debug)]
pub struct CFArrayIter<'a, T: ?Sized + 'a> {
array: &'a CFArray<T>,
index: usize,
}
impl<T: Type> Iterator for CFArrayIter<'_, T> {
type Item = CFRetained<T>;
fn next(&mut self) -> Option<CFRetained<T>> {
// We _must_ re-check the length on every loop iteration, since the
// array could have come from `CFMutableArray` and have been mutated
// while we're iterating.
let value = self.array.get(self.index)?;
self.index += 1;
Some(value)
}
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.array.len().saturating_sub(self.index);
(len, Some(len))
}
}
impl<T: Type> ExactSizeIterator for CFArrayIter<'_, T> {}
// TODO:
// impl<T: Type> DoubleEndedIterator for CFArrayIter<'_, T> { ... }
// Fused unless someone mutates the array, so we won't guarantee that (for now).
// impl<T: Type> FusedIterator for CFArrayIter<'_, T> {}
/// A retained iterator over the items of an array.
#[derive(Debug)]
pub struct CFArrayIntoIter<T: ?Sized> {
array: CFRetained<CFArray<T>>,
index: usize,
}
impl<T: Type> Iterator for CFArrayIntoIter<T> {
type Item = CFRetained<T>;
fn next(&mut self) -> Option<CFRetained<T>> {
// Same as `CFArrayIter::next`.
let value = self.array.get(self.index)?;
self.index += 1;
Some(value)
}
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.array.len().saturating_sub(self.index);
(len, Some(len))
}
}
impl<T: Type> ExactSizeIterator for CFArrayIntoIter<T> {}
impl<'a, T: Type> IntoIterator for &'a CFArray<T> {
type Item = CFRetained<T>;
type IntoIter = CFArrayIter<'a, T>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<'a, T: Type> IntoIterator for &'a CFMutableArray<T> {
type Item = CFRetained<T>;
type IntoIter = CFArrayIter<'a, T>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<T: Type> IntoIterator for CFRetained<CFArray<T>> {
type Item = CFRetained<T>;
type IntoIter = CFArrayIntoIter<T>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
CFArrayIntoIter {
array: self,
index: 0,
}
}
}
impl<T: Type> IntoIterator for CFRetained<CFMutableArray<T>> {
type Item = CFRetained<T>;
type IntoIter = CFArrayIntoIter<T>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
// SAFETY: Upcasting `CFMutableArray<T>` to `CFArray<T>`.
let array = unsafe { CFRetained::cast_unchecked::<CFArray<T>>(self) };
CFArrayIntoIter { array, index: 0 }
}
}
/// An iterator over raw items of an array.
///
/// # Safety
///
/// The array must not be mutated while this is alive.
#[derive(Debug)]
pub struct CFArrayIterUnchecked<'a, T: ?Sized + 'a> {
array: &'a CFArray<T>,
index: CFIndex,
len: CFIndex,
}
impl<'a, T: Type> Iterator for CFArrayIterUnchecked<'a, T> {
type Item = &'a T;
#[inline]
fn next(&mut self) -> Option<&'a T> {
debug_assert_eq!(
self.array.len(),
self.len as usize,
"array was mutated while iterating"
);
if self.index < self.len {
// SAFETY:
// - That the array isn't mutated while iterating is upheld by the
// caller of `CFArray::iter_unchecked`.
// - Index in bounds is ensured by the check above (which uses a
// pre-computed length, and thus also assumes that the array
// isn't mutated while iterating).
let value = unsafe { self.array.get_unchecked(self.index) };
self.index += 1;
Some(value)
} else {
None
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = (self.len - self.index) as usize;
(len, Some(len))
}
}
impl<T: Type> ExactSizeIterator for CFArrayIterUnchecked<'_, T> {}
// Allow easy conversion from `&CFArray<T>` to `&CFArray`.
// Requires `T: Type` because of reflexive impl in `cf_type!`.
impl<T: ?Sized + Type> AsRef<CFArray> for CFArray<T> {
fn as_ref(&self) -> &CFArray {
self.as_opaque()
}
}
impl<T: ?Sized + Type> AsRef<CFMutableArray> for CFMutableArray<T> {
fn as_ref(&self) -> &CFMutableArray {
self.as_opaque()
}
}
// `Eq`, `Ord` and `Hash` have the same semantics.
impl<T: ?Sized + Type> Borrow<CFArray> for CFArray<T> {
fn borrow(&self) -> &CFArray {
self.as_opaque()
}
}
impl<T: ?Sized + Type> Borrow<CFMutableArray> for CFMutableArray<T> {
fn borrow(&self) -> &CFMutableArray {
self.as_opaque()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[cfg(feature = "CFString")]
use crate::CFString;
use core::ptr::null;
#[test]
fn array_with_invalid_pointers() {
// without_provenance
let ptr = [0 as _, 1 as _, 2 as _, 3 as _, usize::MAX as _].as_mut_ptr();
let array = unsafe { CFArray::new(None, ptr, 1, null()) }.unwrap();
let value = unsafe { array.value_at_index(0) };
assert!(value.is_null());
}
#[test]
#[should_panic]
#[ignore = "aborts (as expected)"]
fn object_array_cannot_contain_null() {
let ptr = [null()].as_mut_ptr();
let _array = unsafe { CFArray::new(None, ptr, 1, &kCFTypeArrayCallBacks) };
}
#[test]
#[cfg(feature = "CFString")]
fn correct_retain_count() {
let objects = [
CFString::from_str("some long string that doesn't get small-string optimized"),
CFString::from_str("another long string that doesn't get small-string optimized"),
];
let array = CFArray::from_retained_objects(&objects);
// Creating array retains elements.
assert_eq!(array.retain_count(), 1);
assert_eq!(unsafe { array.get_unchecked(0) }.retain_count(), 2);
assert_eq!(unsafe { array.get_unchecked(1) }.retain_count(), 2);
drop(objects);
assert_eq!(unsafe { array.get_unchecked(0) }.retain_count(), 1);
assert_eq!(unsafe { array.get_unchecked(1) }.retain_count(), 1);
// Retaining array doesn't affect retain count of elements.
let _array2 = array.retain();
assert_eq!(unsafe { array.get_unchecked(0) }.retain_count(), 1);
assert_eq!(unsafe { array.get_unchecked(1) }.retain_count(), 1);
// Using retaining API changes retain count.
assert_eq!(array.get(0).unwrap().retain_count(), 2);
}
#[test]
#[cfg(feature = "CFString")]
fn iter() {
use alloc::vec::Vec;
let s1 = CFString::from_str("a");
let s2 = CFString::from_str("b");
let array = CFArray::from_objects(&[&*s1, &*s2, &*s1]);
assert_eq!(
array.iter().collect::<Vec<_>>(),
[s1.clone(), s2.clone(), s1.clone()]
);
assert_eq!(
unsafe { array.iter_unchecked() }.collect::<Vec<_>>(),
[&*s1, &*s2, &*s1]
);
}
#[test]
#[cfg(feature = "CFString")]
fn iter_fused() {
let s1 = CFString::from_str("a");
let s2 = CFString::from_str("b");
let array = CFArray::from_objects(&[&*s1, &*s2]);
let mut iter = array.iter();
assert_eq!(iter.next(), Some(s1.clone()));
assert_eq!(iter.next(), Some(s2.clone()));
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
let mut iter = unsafe { array.iter_unchecked() };
assert_eq!(iter.next(), Some(&*s1));
assert_eq!(iter.next(), Some(&*s2));
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None);
}
#[test]
#[cfg(feature = "CFString")]
fn mutate() {
let array = CFMutableArray::<CFString>::with_capacity(10);
array.insert(0, &CFString::from_str("a"));
array.append(&CFString::from_str("c"));
array.insert(1, &CFString::from_str("b"));
assert_eq!(
array.to_vec(),
[
CFString::from_str("a"),
CFString::from_str("b"),
CFString::from_str("c"),
]
);
}
#[test]
#[cfg(feature = "CFString")]
#[cfg_attr(
not(debug_assertions),
ignore = "not detected when debug assertions are off"
)]
#[should_panic = "array was mutated while iterating"]
fn mutate_while_iter_unchecked() {
let array = CFMutableArray::<CFString>::with_capacity(10);
assert_eq!(array.len(), 0);
let mut iter = unsafe { array.iter_unchecked() };
array.append(&CFString::from_str("a"));
// Should panic
let _ = iter.next();
}
}

252
vendor/objc2-core-foundation/src/base.rs vendored Normal file
View File

@@ -0,0 +1,252 @@
// The header `CoreFoundation/CFBase.h` contains:
//
// #if defined(__WIN64__) && !defined(__LLP64__)
// #define __LLP64__ 1
// #endif
//
// #if __LLP64__
// typedef unsigned long long CFTypeID;
// typedef unsigned long long CFOptionFlags;
// typedef unsigned long long CFHashCode;
// typedef signed long long CFIndex;
// #else
// typedef unsigned long CFTypeID;
// typedef unsigned long CFOptionFlags;
// typedef unsigned long CFHashCode;
// typedef signed long CFIndex;
// #endif
//
// Looking at the corresponding Rust definitions for longs:
// <https://doc.rust-lang.org/1.83.0/src/core/ffi/mod.rs.html#168-179>
// cfg_if! {
// if #[cfg(all(target_pointer_width = "64", not(windows)))] {
// pub type c_long = i64;
// pub type c_ulong = u64;
// } else {
// // The minimal size of `long` in the C standard is 32 bits
// pub type c_long = i32;
// pub type c_ulong = u32;
// }
// }
// <https://doc.rust-lang.org/1.83.0/src/core/ffi/mod.rs.html#65-66>
// pub type c_longlong = i64;
// pub type c_ulonglong = u64;
//
// It becomes easy to convince ourselves that combined, these amount to making
// these types be 32-bit on systems with 32-bit pointers and 64-bit on systems
// with 64-bit pointers.
//
// That means we can use `isize`/`usize`, which is more ergonomic.
use core::cell::UnsafeCell;
use core::cmp::Ordering;
use core::convert::AsRef;
use core::fmt;
use core::hash;
use core::marker::{PhantomData, PhantomPinned};
use crate::{
CFComparisonResult, CFEqual, CFGetRetainCount, CFGetTypeID, CFHash, CFRange, ConcreteType, Type,
};
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftypeid?language=objc)
pub type CFTypeID = usize;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfoptionflags?language=objc)
pub type CFOptionFlags = usize;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfhashcode?language=objc)
pub type CFHashCode = usize;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfindex?language=objc)
pub type CFIndex = isize;
// Manually define CFType
/// An instance of a Core Foundation type.
///
/// This is meant to be used behind a reference. In the future, this will be
/// defined as an [`extern type`][RFC-1861].
///
/// All Core Foundation types [`Deref`](std::ops::Deref) to this type (it can
/// be considered the "root" type).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftype?language=objc).
///
/// [RFC-1861]: https://rust-lang.github.io/rfcs/1861-extern-types.html
#[repr(C)]
pub struct CFType {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
impl CFType {
/// Attempt to downcast the type to that of type `T`.
///
/// This is the reference-variant. Use [`CFRetained::downcast`] if you
/// want to convert a retained type. See also [`ConcreteType`] for more
/// details on which types support being converted to.
///
/// [`CFRetained::downcast`]: crate::CFRetained::downcast
//
// Not #[inline], we call two functions here.
#[doc(alias = "CFGetTypeID")]
pub fn downcast_ref<T: ConcreteType>(&self) -> Option<&T> {
if CFGetTypeID(Some(self)) == T::type_id() {
let ptr: *const Self = self;
let ptr: *const T = ptr.cast();
// SAFETY: Just checked that the object is a class of type `T`.
// Additionally, `ConcreteType::type_id` is guaranteed to uniquely
// identify the class (including ruling out mutable subclasses),
// so we know for _sure_ that the class is actually of that type
// here.
let this: &T = unsafe { &*ptr };
Some(this)
} else {
None
}
}
/// Get the reference count of the object.
///
/// This function may be useful for debugging. You normally do not use
/// this function otherwise.
///
/// Beware that some things (like `CFNumber`s, small `CFString`s etc.) may
/// not have a normal retain count for optimization purposes, and can
/// return `usize::MAX` in that case.
#[doc(alias = "CFGetRetainCount")]
pub fn retain_count(&self) -> usize {
// Cast is fine, if the reference count is `-1` we want to return
// `usize::MAX` as a sentinel instead.
CFGetRetainCount(Some(self)) as _
}
}
// Reflexive AsRef impl.
impl AsRef<Self> for CFType {
#[inline]
fn as_ref(&self) -> &Self {
self
}
}
// SAFETY: CFType represents a CoreFoundation-like type (even though it isn't
// a real type itself).
unsafe impl Type for CFType {}
impl fmt::Debug for CFType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(feature = "CFString")]
{
let desc = crate::CFCopyDescription(Some(self)).expect("must have description");
write!(f, "{desc}")
}
#[cfg(not(feature = "CFString"))]
{
f.debug_struct("<CoreFoundation type (enable CFString feature for more info)>")
.finish_non_exhaustive()
}
}
}
// Equality in CF has approximately the same semantics as Rust equality.
//
// From the docs:
// > Equality is something specific to each Core Foundation opaque type. For
// > example, two CFNumber objects are equal if the numeric values they
// > represent are equal. Two CFString objects are equal if they represent
// > identical sequences of characters, regardless of encoding.
impl PartialEq for CFType {
#[inline]
#[doc(alias = "CFEqual")]
fn eq(&self, other: &Self) -> bool {
CFEqual(Some(self), Some(other))
}
}
// Similar to NSObject, most types' equality is reflexive.
impl Eq for CFType {}
// From the documentation for CFHash:
// > Two objects that are equal (as determined by the `CFEqual` function) have
// > the same hashing value. However, the converse is not true: two objects
// > with the same hashing value might not be equal. That is, hashing values
// > are not necessarily unique.
//
// I.e. the same semantics as Rust's `Hash`.
impl hash::Hash for CFType {
#[doc(alias = "CFHash")]
fn hash<H: hash::Hasher>(&self, state: &mut H) {
CFHash(Some(self)).hash(state);
}
}
// SAFETY: CFType is defined as the following in the header:
// typedef const CF_BRIDGED_TYPE(id) void * CFTypeRef;
#[cfg(feature = "objc2")]
unsafe impl objc2::encode::RefEncode for CFType {
const ENCODING_REF: objc2::encode::Encoding =
objc2::encode::Encoding::Pointer(&objc2::encode::Encoding::Void);
}
// SAFETY: CF types are message-able in the Objective-C runtime.
#[cfg(feature = "objc2")]
unsafe impl objc2::Message for CFType {}
#[cfg(feature = "objc2")]
impl AsRef<objc2::runtime::AnyObject> for CFType {
fn as_ref(&self) -> &objc2::runtime::AnyObject {
// SAFETY: CFType is valid to re-interpret as AnyObject.
unsafe { core::mem::transmute(self) }
}
}
#[cfg(feature = "objc2")]
impl core::borrow::Borrow<objc2::runtime::AnyObject> for CFType {
fn borrow(&self) -> &objc2::runtime::AnyObject {
<Self as AsRef<objc2::runtime::AnyObject>>::as_ref(self)
}
}
// NOTE: impl AsRef<CFType> for AnyObject would probably not be valid, since
// not all Objective-C objects can be used as CoreFoundation objects (?)
impl Default for CFComparisonResult {
#[inline]
fn default() -> Self {
Self::CompareEqualTo
}
}
impl From<Ordering> for CFComparisonResult {
#[inline]
fn from(order: Ordering) -> Self {
match order {
Ordering::Less => Self::CompareLessThan,
Ordering::Equal => Self::CompareEqualTo,
Ordering::Greater => Self::CompareGreaterThan,
}
}
}
impl From<CFComparisonResult> for Ordering {
#[inline]
fn from(comparison_result: CFComparisonResult) -> Self {
match comparison_result.0 {
..=-1 => Self::Less, // ..=CFComparisonResult::CompareLessThan
0 => Self::Equal, // CFComparisonResult::CompareEqualTo
1.. => Self::Greater, // CFComparisonResult::CompareGreaterThan..
#[allow(unreachable_patterns)] // MSRV between 1.73 and 1.76
_ => Self::Equal,
}
}
}
impl CFRange {
/// Create a new [`CFRange`].
#[doc(alias = "CFRangeMake")]
pub fn new(location: CFIndex, length: CFIndex) -> Self {
Self { location, length }
}
}

View File

@@ -0,0 +1,63 @@
#[cfg(target_pointer_width = "64")] // #if TARGET_RT_64_BIT
type Inner = core::ffi::c_int;
#[cfg(not(target_pointer_width = "64"))]
type Inner = i16; // SInt16
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbundlerefnum?language=objc)
pub type CFBundleRefNum = Inner;
#[cfg(test)]
#[cfg(all(feature = "CFString", feature = "CFURL"))]
mod tests {
use alloc::string::ToString;
use crate::{CFBundle, CFRetained, CFString, CFURLPathStyle, CFURL};
fn url_from_str(s: &str, is_dir: bool) -> CFRetained<CFURL> {
CFURL::with_file_system_path(
None,
Some(&CFString::from_str(s)),
CFURLPathStyle::CFURLPOSIXPathStyle,
is_dir as _,
)
.unwrap()
}
#[test]
fn safari_executable_url() {
let path = url_from_str("/Applications/Safari.app", true);
let bundle = CFBundle::new(None, Some(&path)).expect("Safari not present");
let executable = CFBundle::executable_url(&bundle).unwrap();
assert_eq!(
CFURL::file_system_path(
&CFURL::absolute_url(&executable).unwrap(),
CFURLPathStyle::CFURLPOSIXPathStyle,
)
.unwrap()
.to_string(),
"/Applications/Safari.app/Contents/MacOS/Safari"
);
}
#[test]
fn safari_private_frameworks_url() {
let path = url_from_str("/Applications/Safari.app", true);
let bundle = CFBundle::new(None, Some(&path)).expect("Safari not present");
let frameworks = CFBundle::private_frameworks_url(&bundle).unwrap();
assert_eq!(
CFURL::file_system_path(
&CFURL::absolute_url(&frameworks).unwrap(),
CFURLPathStyle::CFURLPOSIXPathStyle,
)
.unwrap()
.to_string(),
"/Applications/Safari.app/Contents/Frameworks"
);
}
#[test]
fn non_existent_bundle() {
let path = url_from_str("/usr/local/non_existent", true);
assert_eq!(CFBundle::new(None, Some(&path)), None);
}
}

View File

@@ -0,0 +1,190 @@
/// Implement necessary traits for the given type to act as a CoreFoundation
/// type.
///
///
/// # Stability
///
/// This is work in progress. The macro syntax will not change in
/// semver-incompatible versions (as other crates rely on this macro), but you
/// are not expected to use the macro yourself, and so error messages and
/// changelog notes may be absent.
///
///
/// # Safety
///
/// The type must be a type that represents a CoreFoundation type, and the
/// type must be declared as either an [`extern type`], or as a ZST with an
/// appropriate `#[repr(...)]`.
///
/// [`extern type`]: https://github.com/rust-lang/rust/issues/43467
///
///
/// # Generics
///
/// It is an explicit non-goal for this macro to support generic types, as
/// neither Swift nor Objective-C supports that for CoreFoundation types
/// either (and thus we wouldn't have any useful type-information in the
/// headers).
#[doc(hidden)] // For now, though still a breaking change to modify
#[macro_export]
macro_rules! cf_type {
(
$(#[encoding_name = $encoding_name:literal])? // TODO(breaking): Remove this.
unsafe impl $(<$($generic:ident : ?$sized:ident),* $(,)?>)? $ty:ident $(<$($generic_param:ident),* $(,)?>)? $(: $superclass:ty)? {}
) => {
// Reflexive AsRef impl.
impl $(<$($generic : ?$sized),*>)? $crate::__cf_macro_helpers::AsRef<Self> for $ty $(<$($generic_param),*>)? {
#[inline]
fn as_ref(&self) -> &Self {
self
}
}
// SAFETY: The type is a CoreFoundation-like type.
unsafe impl $(<$($generic : ?$sized),*>)? $crate::Type for $ty $(<$($generic_param),*>)? {}
// Implement Deref-chain to CFType.
$crate::__cf_type_superclass!(impl ($(<$($generic : ?$sized),*>)?) $ty $(<$($generic_param),*>)? $(: $superclass)?);
// Various trait impls.
impl $(<$($generic : ?$sized),*>)? $crate::__cf_macro_helpers::AsRef<$crate::CFType> for $ty $(<$($generic_param),*>)? {
#[inline]
fn as_ref(&self) -> &$crate::CFType {
self // Through Deref of self or superclass
}
}
impl $(<$($generic : ?$sized),*>)? $crate::__cf_macro_helpers::Borrow<$crate::CFType> for $ty $(<$($generic_param),*>)? {
#[inline]
fn borrow(&self) -> &$crate::CFType {
self // Through Deref of self or superclass
}
}
impl $(<$($generic : ?$sized),*>)? $crate::__cf_macro_helpers::PartialEq for $ty $(<$($generic_param),*>)? {
#[inline]
fn eq(&self, other: &Self) -> $crate::__cf_macro_helpers::bool {
let this: &$crate::CFType = self; // Through Deref
let other: &$crate::CFType = other; // Through Deref
$crate::__cf_macro_helpers::PartialEq::eq(this, other)
}
}
impl $(<$($generic : ?$sized),*>)? $crate::__cf_macro_helpers::Eq for $ty $(<$($generic_param),*>)? {}
impl $(<$($generic : ?$sized),*>)? $crate::__cf_macro_helpers::Hash for $ty $(<$($generic_param),*>)? {
#[inline]
fn hash<H: $crate::__cf_macro_helpers::Hasher>(&self, state: &mut H) {
let this: &$crate::CFType = self; // Through Deref
$crate::__cf_macro_helpers::Hash::hash(this, state);
}
}
impl $(<$($generic : ?$sized),*>)? $crate::__cf_macro_helpers::fmt::Debug for $ty $(<$($generic_param),*>)? {
fn fmt(
&self,
f: &mut $crate::__cf_macro_helpers::fmt::Formatter<'_>,
) -> $crate::__cf_macro_helpers::fmt::Result {
let this: &$crate::CFType = self; // Through Deref
$crate::__cf_macro_helpers::fmt::Debug::fmt(this, f)
}
}
// Objective-C interop
$crate::__cf_type_objc2!(
impl ($(<$($generic : ?$sized),*>)?) $ty $(<$($generic_param),*>)?;
$($encoding_name)?
);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __cf_type_superclass {
// No superclass
(impl ($($generics:tt)*) $ty:ty) => {
// NOTE: We intentionally don't implement `Deref` with
// `Target = AnyObject` when there isn't a superclass, as we want
// conversions to Objective-C types to be explicit.
//
// Instead, we prefer a `Deref` impl to `CFType`.
impl $($generics)* $crate::__cf_macro_helpers::Deref for $ty {
type Target = $crate::CFType;
#[inline]
fn deref(&self) -> &Self::Target {
// SAFETY: It is valid to re-interpret a type as CFType.
unsafe { $crate::__cf_macro_helpers::transmute(self) }
}
}
};
// If has superclass.
(impl ($($generics:tt)*) $ty:ty: $superclass:ty) => {
// Similar to `objc2::extern_class!`, we implement Deref for the
// type to allow easy conversion to the super class.
impl $($generics)* $crate::__cf_macro_helpers::Deref for $ty {
type Target = $superclass;
#[inline]
fn deref(&self) -> &Self::Target {
// SAFETY: It is valid to re-interpret a type as its superclass.
unsafe { $crate::__cf_macro_helpers::transmute(self) }
}
}
// Allow converting to superclasses.
// Similar to `objc2::__extern_class_impl_as_ref_borrow!`.
impl $($generics)* $crate::__cf_macro_helpers::AsRef<$superclass> for $ty {
#[inline]
fn as_ref(&self) -> &$superclass {
self // Through Deref
}
}
impl $($generics)* $crate::__cf_macro_helpers::Borrow<$superclass> for $ty {
#[inline]
fn borrow(&self) -> &$superclass {
self // Through Deref
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __cf_type_no_superclass {
(impl ($($generics:tt)*) $ty:ty) => {};
}
#[cfg(feature = "objc2")]
#[doc(hidden)]
#[macro_export]
macro_rules! __cf_type_objc2 {
(impl ($($generics:tt)*) $ty:ty;) => {};
(impl ($($generics:tt)*) $ty:ty; $encoding:literal) => {
$crate::__cf_macro_helpers::cf_objc2_type!(
unsafe impl $($generics)* RefEncode<$encoding> for $ty {}
);
};
}
#[cfg(not(feature = "objc2"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cf_type_objc2 {
($($t:tt)*) => {};
}
#[cfg(test)]
mod tests {
#[allow(dead_code)]
struct TISInputSource {}
// Test old syntax still works (used by dependencies).
cf_type!(
#[encoding_name = "__TISInputSource"]
unsafe impl TISInputSource {}
);
}

117
vendor/objc2-core-foundation/src/data.rs vendored Normal file
View File

@@ -0,0 +1,117 @@
use core::slice;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
use crate::{CFData, CFIndex};
fn get_len(bytes: &[u8]) -> CFIndex {
// An allocation in Rust cannot be larger than isize::MAX, so this will
// never fail.
let len = bytes.len();
debug_assert!(len < CFIndex::MAX as usize);
len as CFIndex
}
impl CFData {
/// Creates a new `CFData` from a byte slice.
#[inline]
#[doc(alias = "CFDataCreate")]
pub fn from_bytes(bytes: &[u8]) -> crate::CFRetained<Self> {
let len = get_len(bytes);
unsafe { crate::CFData::new(None, bytes.as_ptr(), len) }.expect("failed creating CFData")
}
/// Alias for easier transition from the `core-foundation` crate.
#[inline]
#[deprecated = "renamed to CFData::from_bytes"]
pub fn from_buffer(bytes: &[u8]) -> crate::CFRetained<Self> {
Self::from_bytes(bytes)
}
/// Creates a new `CFData` from a `'static` byte slice.
///
/// This may be slightly more efficient than [`CFData::from_bytes`], as it
/// may be able to re-use the existing buffer (since we know it won't be
/// deallocated).
#[inline]
#[doc(alias = "CFDataCreateWithBytesNoCopy")]
pub fn from_static_bytes(bytes: &'static [u8]) -> crate::CFRetained<Self> {
let len = get_len(bytes);
// SAFETY: Same as `CFString::from_static_str`.
unsafe { CFData::with_bytes_no_copy(None, bytes.as_ptr(), len, crate::kCFAllocatorNull) }
.expect("failed creating CFData")
}
/// The number of bytes contained by the `CFData`.
#[inline]
#[doc(alias = "CFDataGetLength")]
pub fn len(&self) -> usize {
self.length() as usize
}
/// Whether the `CFData` is empty.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// The underlying bytes in the `CFData`.
///
///
/// # Safety
///
/// The `CFData` must not be mutated for the lifetime of the returned
/// string. Consider using [`to_vec`] instead if this requirement is a bit
/// difficult to uphold.
///
/// [`to_vec`]: Self::to_vec
#[inline]
#[doc(alias = "CFDataGetBytePtr")]
pub unsafe fn as_bytes_unchecked(&self) -> &[u8] {
let ptr = self.byte_ptr();
if !ptr.is_null() {
// SAFETY: The pointer is valid, and caller ensures that the
// `CFData` is not mutated for the lifetime of it.
//
// Same as
unsafe { slice::from_raw_parts(ptr, self.len()) }
} else {
// The bytes pointer may be null for length zero
&[]
}
}
/// Copy the contents of the `CFData` into a new [`Vec`].
#[cfg(feature = "alloc")]
#[doc(alias = "CFDataGetBytePtr")]
pub fn to_vec(&self) -> Vec<u8> {
// NOTE: We don't do `Vec::from`, as that will call the allocator
// while the buffer is active, and we don't know if that allocator
// uses a CFMutableData under the hood (though very theoretical).
let mut vec = Vec::with_capacity(self.len());
// SAFETY: We've pre-allocated the Vec, so it won't call the allocator
// while the byte slice is alive (and hence it won't ).
vec.extend_from_slice(unsafe { self.as_bytes_unchecked() });
vec
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn roundtrip() {
let data = CFData::from_bytes(&[1, 2, 3]);
assert_eq!(data.to_vec(), [1, 2, 3]);
}
#[test]
fn empty() {
let data = CFData::from_bytes(&[]);
assert!(data.is_empty());
assert_eq!(data.to_vec(), []);
}
}

120
vendor/objc2-core-foundation/src/date.rs vendored Normal file
View File

@@ -0,0 +1,120 @@
use core::{cmp::Ordering, ptr};
use crate::CFDate;
impl CFDate {
/// Create a `CFDate` from a [`SystemTime`].
///
/// Nanosecond precision may be lost.
///
/// [`SystemTime`]: std::time::SystemTime
#[cfg(feature = "std")]
pub fn from_system_time(time: &std::time::SystemTime) -> crate::CFRetained<Self> {
let since_1970 = match time.duration_since(std::time::UNIX_EPOCH) {
Ok(duration) => duration.as_secs_f64(),
Err(err) => -err.duration().as_secs_f64(),
} as core::ffi::c_double;
let since_2001 = since_1970 - unsafe { crate::kCFAbsoluteTimeIntervalSince1970 };
Self::new(None, since_2001).expect("failed creating CFDate")
}
/// Try to construct a [`SystemTime`] from the `CFDate`.
///
/// Nanosecond precision may be lost.
///
/// Returns `None` if the `CFDate` is too large to fit inside
/// [`SystemTime`].
///
/// [`SystemTime`]: std::time::SystemTime
#[cfg(feature = "std")]
#[allow(clippy::unnecessary_cast)]
pub fn to_system_time(&self) -> Option<std::time::SystemTime> {
let since_2001 = self.absolute_time();
let since_1970 = (since_2001 + unsafe { crate::kCFAbsoluteTimeIntervalSince1970 }) as f64;
std::time::UNIX_EPOCH.checked_add(std::time::Duration::try_from_secs_f64(since_1970).ok()?)
}
}
impl PartialOrd for CFDate {
#[inline]
#[doc(alias = "CFDateCompare")]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for CFDate {
#[inline]
#[doc(alias = "CFDateCompare")]
fn cmp(&self, other: &Self) -> Ordering {
// Documented that one should pass NULL here.
let context = ptr::null_mut();
unsafe { self.compare(Some(other), context) }.into()
}
}
#[cfg(test)]
mod test {
use core::ffi::c_double;
use std::time::{Duration, SystemTime};
use crate::CFAbsoluteTimeGetCurrent;
use super::*;
#[test]
fn cmp() {
let now = CFDate::new(None, CFAbsoluteTimeGetCurrent()).unwrap();
let past = CFDate::new(None, now.absolute_time() - 1.0).unwrap();
assert_eq!(now.cmp(&past), Ordering::Greater);
assert_eq!(now.cmp(&now), Ordering::Equal);
assert_eq!(past.cmp(&now), Ordering::Less);
assert_eq!(now, now);
assert_ne!(now, past);
}
#[test]
fn system_time_roundtrip() {
let date1 = CFDate::new(None, CFAbsoluteTimeGetCurrent()).unwrap();
let date2 = CFDate::from_system_time(&date1.to_system_time().unwrap());
let diff = date1.absolute_time() - date2.absolute_time();
assert!(diff <= 1.0); // Some precision is lost
}
#[test]
fn system_time_cmp() {
let std_now_first = SystemTime::now();
let cf_now_first = CFDate::new(None, CFAbsoluteTimeGetCurrent() + 1.0).unwrap();
let std_now_second = std_now_first.checked_add(Duration::from_secs(2)).unwrap();
let cf_now_second = CFDate::new(None, CFAbsoluteTimeGetCurrent() + 3.0).unwrap();
assert!(std_now_first <= std_now_second);
assert!(cf_now_first <= cf_now_second);
assert!(std_now_first <= cf_now_first.to_system_time().unwrap());
assert!(cf_now_first.to_system_time().unwrap() <= std_now_second);
assert!(cf_now_first <= CFDate::from_system_time(&std_now_second));
assert!(CFDate::from_system_time(&std_now_second) <= cf_now_second);
}
#[test]
fn system_time_from_odd() {
let time = SystemTime::UNIX_EPOCH
.checked_sub(Duration::from_secs(10))
.unwrap();
let _ = CFDate::from_system_time(&time);
}
#[test]
fn system_time_unrepresentable() {
let date = CFDate::new(None, c_double::MIN).unwrap();
assert_eq!(date.to_system_time(), None);
let date = CFDate::new(None, c_double::MAX).unwrap();
assert_eq!(date.to_system_time(), None);
}
}

View File

@@ -0,0 +1,495 @@
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
use core::{borrow::Borrow, ffi::c_void, hash::Hash, mem};
use crate::{
kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks, CFDictionary, CFIndex,
CFMutableDictionary, CFRetained, Type,
};
/// Roughly same as `failed_creating_array`.
#[cold]
fn failed_creating_dictionary(len: CFIndex) -> ! {
#[cfg(feature = "alloc")]
{
use alloc::alloc::{handle_alloc_error, Layout};
use core::mem::align_of;
let layout =
Layout::array::<(*const (), *const ())>(len as usize).unwrap_or_else(|_| unsafe {
Layout::from_size_align_unchecked(0, align_of::<*const ()>())
});
handle_alloc_error(layout)
}
#[cfg(not(feature = "alloc"))]
{
panic!("failed allocating CFDictionary holding {len} elements")
}
}
/// These usually doesn't _have_ to be bound by `K: Type`, all that matters is
/// that they're valid for the dictionary at hand.
///
/// But let's keep the bound for now, it might turn out to be necessary.
#[inline]
fn to_void<K: ?Sized + Type>(key: &K) -> *const c_void {
let key: *const K = key;
key.cast()
}
/// Convenience creation methods.
impl<K: ?Sized, V: ?Sized> CFDictionary<K, V> {
/// Create a new empty dictionary.
#[inline]
#[doc(alias = "CFDictionaryCreate")]
pub fn empty() -> CFRetained<Self>
where
K: Type + PartialEq + Hash,
V: Type,
{
Self::from_slices(&[], &[])
}
/// Create a new dictionary from slices of keys and values.
///
/// # Panics
///
/// Panics if the slices have different lengths.
#[inline]
#[doc(alias = "CFDictionaryCreate")]
pub fn from_slices(keys: &[&K], values: &[&V]) -> CFRetained<Self>
where
K: Type + PartialEq + Hash,
V: Type,
{
assert_eq!(
keys.len(),
values.len(),
"key and object slices must have the same length",
);
// Can never happen, allocations in Rust cannot be this large.
debug_assert!(keys.len() < CFIndex::MAX as usize);
let len = keys.len() as CFIndex;
// `&T` has the same layout as `*const c_void`, and is non-NULL.
let keys = keys.as_ptr().cast::<*const c_void>().cast_mut();
let values = values.as_ptr().cast::<*const c_void>().cast_mut();
// SAFETY: The keys and values are CFTypes (`K: Type` and `V: Type`
// bounds), and the dictionary callbacks are thus correct.
//
// The keys and values are retained internally by the dictionary, so
// we do not need to keep them alive ourselves after this.
let dictionary = unsafe {
CFDictionary::new(
None,
keys,
values,
len,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks,
)
}
.unwrap_or_else(|| failed_creating_dictionary(len));
// SAFETY: The dictionary contains no keys and values yet, and thus
// it's safe to cast them to `K` and `V` (as the dictionary callbacks
// are valid for these types).
unsafe { CFRetained::cast_unchecked::<Self>(dictionary) }
}
}
/// Convenience creation methods.
impl<K: ?Sized, V: ?Sized> CFMutableDictionary<K, V> {
/// Create a new empty mutable dictionary.
#[inline]
#[doc(alias = "CFDictionaryCreateMutable")]
pub fn empty() -> CFRetained<Self>
where
K: Type + PartialEq + Hash,
V: Type,
{
Self::with_capacity(0)
}
/// Create a new mutable dictionary with the given capacity.
#[inline]
#[doc(alias = "CFDictionaryCreateMutable")]
pub fn with_capacity(capacity: usize) -> CFRetained<Self>
where
K: Type + PartialEq + Hash,
V: Type,
{
let capacity = capacity.try_into().expect("capacity too high");
// SAFETY: The keys and values are CFTypes (`K: Type` and `V: Type`
// bounds), and the dictionary callbacks are thus correct.
let dictionary = unsafe {
CFMutableDictionary::new(
None,
capacity,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks,
)
}
.unwrap_or_else(|| failed_creating_dictionary(capacity));
// SAFETY: The dictionary contains no keys and values yet, and thus
// it's safe to cast them to `K` and `V` (as the dictionary callbacks
// are valid for these types).
unsafe { CFRetained::cast_unchecked::<Self>(dictionary) }
}
}
/// Direct, unsafe object accessors.
///
/// CFDictionary stores its keys and values directly, and you can get
/// references to those without having to retain them first - but only if the
/// dictionary isn't mutated while doing so - otherwise, you might end up
/// accessing a deallocated object.
impl<K: ?Sized, V: ?Sized> CFDictionary<K, V> {
/// Get a direct reference to one of the dictionary's values.
///
/// Consider using the [`get`](Self::get) method instead, unless you're
/// seeing performance issues from the retaining.
///
/// # Safety
///
/// The dictionary must not be mutated while the returned reference is
/// live.
#[inline]
#[doc(alias = "CFDictionaryGetValue")]
pub unsafe fn get_unchecked(&self, key: &K) -> Option<&V>
where
K: Type + Sized,
V: Type + Sized,
{
// SAFETY: The key is valid for this dictionary.
//
// The values are CoreFoundation types, and thus cannot be NULL, so
// no need to use `CFDictionaryGetValueIfPresent`.
let value = unsafe { self.as_opaque().value(to_void(key)) };
// SAFETY: The dictionary's values are of type `V`.
//
// Caller ensures that the dictionary isn't mutated for the lifetime
// of the reference.
unsafe { value.cast::<V>().as_ref() }
}
/// A vector containing direct references to the dictionary's keys and
/// values.
///
/// Consider using the [`to_vecs`](Self::to_vecs) method instead, unless
/// you're seeing performance issues from the retaining.
///
/// # Safety
///
/// The array must not be mutated while the returned references are alive.
#[cfg(feature = "alloc")]
pub unsafe fn to_vecs_unchecked(&self) -> (Vec<&K>, Vec<&V>)
where
K: Type,
V: Type,
{
let len = self.len();
let mut keys = Vec::<&K>::with_capacity(len);
let mut values = Vec::<&V>::with_capacity(len);
// `&K`/`&V` has the same layout as `*const c_void`.
let keys_ptr = keys.as_mut_ptr().cast::<*const c_void>();
let values_ptr = values.as_mut_ptr().cast::<*const c_void>();
// SAFETY: The arrays are both of the right size.
unsafe { self.as_opaque().keys_and_values(keys_ptr, values_ptr) };
// SAFETY: Just initialized the `Vec`s above.
unsafe {
keys.set_len(len);
values.set_len(len);
}
(keys, values)
}
}
/// Various accessor methods.
impl<K: ?Sized, V: ?Sized> CFDictionary<K, V> {
/// Convert to the opaque/untyped variant.
pub fn as_opaque(&self) -> &CFDictionary {
// SAFETY: The dictionary stores keys and values behind a reference,
// and those can all be represented by `crate::opaque::Opaque`.
unsafe { mem::transmute::<&CFDictionary<K, V>, &CFDictionary>(self) }
}
/// The amount of elements in the dictionary.
#[inline]
#[doc(alias = "CFDictionaryGetCount")]
pub fn len(&self) -> usize {
// Fine to cast here, the count is never negative.
self.as_opaque().count() as _
}
/// Whether the dictionary is empty or not.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Retrieve the object at the given index.
///
/// Returns `None` if the index was out of bounds.
#[doc(alias = "CFDictionaryGetValue")]
pub fn get(&self, key: &K) -> Option<CFRetained<V>>
where
K: Type + Sized + PartialEq + Hash,
V: Type + Sized,
{
// SAFETY: We retain the value right away, so we know the reference is
// valid for the duration we use it.
unsafe { self.get_unchecked(key) }.map(V::retain)
}
/// Two vectors containing respectively the dictionary's keys and values.
#[cfg(feature = "alloc")]
#[doc(alias = "CFDictionaryGetKeysAndValues")]
pub fn to_vecs(&self) -> (Vec<CFRetained<K>>, Vec<CFRetained<V>>)
where
K: Type + Sized,
V: Type + Sized,
{
// SAFETY: We retain the elements below, so that we know that the
// dictionary isn't mutated while they are alive.
let (keys, objects) = unsafe { self.to_vecs_unchecked() };
(
keys.into_iter().map(K::retain).collect(),
objects.into_iter().map(V::retain).collect(),
)
}
/// Whether the key is in the dictionary.
#[inline]
#[doc(alias = "CFDictionaryContainsKey")]
pub fn contains_key(&self, key: &K) -> bool
where
K: Type + Sized + PartialEq + Hash,
{
// SAFETY: The key is bound by `K: Type`, and thus know to be valid
// for the callbacks in the dictionary.
unsafe { self.as_opaque().contains_ptr_key(to_void(key)) }
}
/// Whether the value can be found anywhere in the dictionary.
#[inline]
#[doc(alias = "CFDictionaryContainsValue")]
pub fn contains_value(&self, value: &V) -> bool
where
V: Type + Sized + PartialEq,
{
// SAFETY: The value is bound by `V: Type`, and thus know to be valid
// for the callbacks in the dictionary.
unsafe { self.as_opaque().contains_ptr_value(to_void(value)) }
}
}
/// Various mutation methods.
impl<K: ?Sized, V: ?Sized> CFMutableDictionary<K, V> {
/// Convert to the opaque/untyped variant.
pub fn as_opaque(&self) -> &CFMutableDictionary {
// SAFETY: Same as `CFDictionary::as_opaque`.
unsafe { mem::transmute::<&CFMutableDictionary<K, V>, &CFMutableDictionary>(self) }
}
/// Add the key-value pair to the dictionary if no such key already exist.
#[inline]
#[doc(alias = "CFDictionaryAddValue")]
pub fn add(&self, key: &K, value: &V)
where
K: Type + Sized + PartialEq + Hash,
V: Type + Sized,
{
unsafe {
CFMutableDictionary::add_value(Some(self.as_opaque()), to_void(key), to_void(value))
}
}
/// Set the value of the key in the dictionary.
#[inline]
#[doc(alias = "CFDictionarySetValue")]
pub fn set(&self, key: &K, value: &V)
where
K: Type + Sized + PartialEq + Hash,
V: Type + Sized,
{
unsafe {
CFMutableDictionary::set_value(Some(self.as_opaque()), to_void(key), to_void(value))
}
}
/// Replace the value of the key in the dictionary.
#[inline]
#[doc(alias = "CFDictionaryReplaceValue")]
pub fn replace(&self, key: &K, value: &V)
where
K: Type + Sized + PartialEq + Hash,
V: Type + Sized,
{
unsafe {
CFMutableDictionary::replace_value(Some(self.as_opaque()), to_void(key), to_void(value))
}
}
/// Remove the value from the dictionary associated with the key.
#[inline]
#[doc(alias = "CFDictionaryRemoveValue")]
pub fn remove(&self, key: &K)
where
K: Type + Sized + PartialEq + Hash,
{
unsafe { CFMutableDictionary::remove_value(Some(self.as_opaque()), to_void(key)) }
}
/// Remove all keys and values from the dictionary.
#[inline]
#[doc(alias = "CFDictionaryRemoveAllValues")]
pub fn clear(&self) {
CFMutableDictionary::remove_all_values(Some(self.as_opaque()))
}
}
// Allow easy conversion from `&CFDictionary<T>` to `&CFDictionary`.
// Requires `Type` bound because of reflexive impl in `cf_type!`.
impl<K: ?Sized + Type, V: ?Sized + Type> AsRef<CFDictionary> for CFDictionary<K, V> {
fn as_ref(&self) -> &CFDictionary {
self.as_opaque()
}
}
impl<K: ?Sized + Type, V: ?Sized + Type> AsRef<CFMutableDictionary> for CFMutableDictionary<K, V> {
fn as_ref(&self) -> &CFMutableDictionary {
self.as_opaque()
}
}
// `Eq`, `Ord` and `Hash` have the same semantics.
impl<K: ?Sized + Type, V: ?Sized + Type> Borrow<CFDictionary> for CFDictionary<K, V> {
fn borrow(&self) -> &CFDictionary {
self.as_opaque()
}
}
impl<K: ?Sized + Type, V: ?Sized + Type> Borrow<CFMutableDictionary> for CFMutableDictionary<K, V> {
fn borrow(&self) -> &CFMutableDictionary {
self.as_opaque()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::CFType;
#[test]
fn empty() {
let dict1 = CFDictionary::<CFType, CFType>::empty();
let dict2 = CFDictionary::<CFType, CFType>::empty();
assert_eq!(dict1, dict2);
assert_eq!(dict1.len(), 0);
assert_eq!(dict1.get(dict1.as_ref()), None);
assert!(!dict1.contains_key(dict1.as_ref()));
assert!(!dict1.contains_value(dict1.as_ref()));
#[cfg(feature = "alloc")]
assert_eq!(dict1.to_vecs(), (alloc::vec![], alloc::vec![]));
}
#[test]
#[cfg(feature = "CFString")]
fn mutable_dictionary() {
use crate::CFString;
let dict = CFMutableDictionary::<CFString, CFString>::empty();
dict.add(&CFString::from_str("a"), &CFString::from_str("b"));
dict.add(&CFString::from_str("c"), &CFString::from_str("d"));
assert_eq!(dict.len(), 2);
dict.add(&CFString::from_str("c"), &CFString::from_str("e"));
assert_eq!(dict.len(), 2);
assert_eq!(
dict.get(&CFString::from_str("c")),
Some(CFString::from_str("d")),
);
dict.replace(&CFString::from_str("c"), &CFString::from_str("f"));
assert_eq!(dict.len(), 2);
assert_eq!(
dict.get(&CFString::from_str("c")),
Some(CFString::from_str("f"))
);
dict.remove(&CFString::from_str("a"));
assert_eq!(dict.len(), 1);
dict.clear();
assert_eq!(dict.len(), 0);
}
#[test]
#[cfg(feature = "CFString")]
fn contains() {
use crate::CFString;
let dict = CFDictionary::from_slices(
&[&*CFString::from_str("key")],
&[&*CFString::from_str("value")],
);
assert!(dict.contains_key(&CFString::from_str("key")));
assert!(dict.get(&CFString::from_str("key")).is_some());
assert!(!dict.contains_key(&CFString::from_str("invalid key")));
assert!(dict.get(&CFString::from_str("invalid key")).is_none());
assert!(dict.contains_value(&CFString::from_str("value")));
assert!(!dict.contains_value(&CFString::from_str("invalid value")));
}
#[test]
#[cfg(all(feature = "CFString", feature = "CFNumber"))]
fn heterogenous() {
use crate::{CFBoolean, CFNumber, CFString, CFType};
let dict = CFDictionary::<CFType, CFType>::from_slices(
&[
CFString::from_str("string key").as_ref(),
CFNumber::new_isize(4).as_ref(),
CFBoolean::new(true).as_ref(),
],
&[
CFString::from_str("a string value").as_ref(),
CFNumber::new_isize(2).as_ref(),
CFBoolean::new(false).as_ref(),
],
);
assert_eq!(
dict.get(&CFString::from_str("string key")),
Some(CFString::from_str("a string value").into())
);
assert_eq!(
dict.get(&CFNumber::new_isize(4)),
Some(CFNumber::new_isize(2).into())
);
assert_eq!(
dict.get(CFBoolean::new(true)),
Some(CFBoolean::new(false).into())
);
assert_eq!(dict.get(CFBoolean::new(false)), None);
}
#[test]
#[cfg(feature = "CFString")]
#[should_panic = "key and object slices must have the same length"]
fn from_slices_not_same_length() {
use crate::CFString;
let _dict =
CFDictionary::<CFString, CFString>::from_slices(&[&*CFString::from_str("key")], &[]);
}
}

View File

@@ -0,0 +1,14 @@
#![cfg(feature = "CFString")]
use core::fmt;
use crate::CFError;
impl fmt::Display for CFError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let desc = self.description().unwrap();
write!(f, "{desc}")
}
}
#[cfg(feature = "std")] // use core::error::Error from Rust 1.81 once in MSRV.
impl std::error::Error for CFError {}

View File

@@ -0,0 +1,14 @@
#![cfg(unix)] // std::os::fd only available on unix platforms.
use std::os::fd::{AsRawFd, RawFd};
use crate::CFFileDescriptor;
impl AsRawFd for CFFileDescriptor {
fn as_raw_fd(&self) -> RawFd {
self.native_descriptor()
}
}
// NOTE: We cannot implement `AsFd`, since if `CFFileDescriptor` was created
// with `closeOnInvalidate`, the user could close the file descriptor while
// the `BorrowedFd` was alive, thus breaking its invariant.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,748 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfattributedstring?language=objc)
#[repr(C)]
pub struct CFAttributedString {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFAttributedString {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFAttributedString"> for CFAttributedString {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutableattributedstring?language=objc)
#[repr(C)]
pub struct CFMutableAttributedString {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFMutableAttributedString: CFAttributedString {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFAttributedString"> for CFMutableAttributedString {}
);
unsafe impl ConcreteType for CFAttributedString {
/// Returns the type identifier of all CFAttributedString instances.
#[doc(alias = "CFAttributedStringGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFAttributedStringGetTypeID() -> CFTypeID;
}
unsafe { CFAttributedStringGetTypeID() }
}
}
impl CFAttributedString {
/// Creates an attributed string with the specified string and attributes (both copied).
#[doc(alias = "CFAttributedStringCreate")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn new(
alloc: Option<&CFAllocator>,
str: Option<&CFString>,
attributes: Option<&CFDictionary>,
) -> Option<CFRetained<CFAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreate(
alloc: Option<&CFAllocator>,
str: Option<&CFString>,
attributes: Option<&CFDictionary>,
) -> Option<NonNull<CFAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreate(alloc, str, attributes) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a sub-attributed string from the specified range. It's a programming error for range to specify characters outside the bounds of aStr.
#[doc(alias = "CFAttributedStringCreateWithSubstring")]
#[inline]
pub unsafe fn with_substring(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
range: CFRange,
) -> Option<CFRetained<CFAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateWithSubstring(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
range: CFRange,
) -> Option<NonNull<CFAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateWithSubstring(alloc, a_str, range) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates an immutable attributed string copy.
#[doc(alias = "CFAttributedStringCreateCopy")]
#[inline]
pub fn new_copy(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
) -> Option<CFRetained<CFAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateCopy(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
) -> Option<NonNull<CFAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateCopy(alloc, a_str) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns the string for the attributed string. For performance reasons, this will often point at the backing store of the attributed string, and it might change if the attributed string is edited. However, this is an implementation detail, and definitely not something that should be counted on.
#[doc(alias = "CFAttributedStringGetString")]
#[inline]
pub fn string(self: &CFAttributedString) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFAttributedStringGetString(a_str: &CFAttributedString)
-> Option<NonNull<CFString>>;
}
let ret = unsafe { CFAttributedStringGetString(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the length of the attributed string in characters; same as CFStringGetLength(CFAttributedStringGetString(aStr))
#[doc(alias = "CFAttributedStringGetLength")]
#[inline]
pub fn length(self: &CFAttributedString) -> CFIndex {
extern "C-unwind" {
fn CFAttributedStringGetLength(a_str: &CFAttributedString) -> CFIndex;
}
unsafe { CFAttributedStringGetLength(self) }
}
/// Returns the attributes at the specified location. If effectiveRange is not NULL, upon return *effectiveRange contains a range over which the exact same set of attributes apply. Note that for performance reasons, the returned effectiveRange is not necessarily the maximal range - for that, use CFAttributedStringGetAttributesAndLongestEffectiveRange(). It's a programming error for loc to specify a location outside the bounds of the attributed string.
///
/// Note that the returned attribute dictionary might change in unpredictable ways from under the caller if the attributed string is edited after this call. If you wish to hang on to the dictionary long-term, you should make an actual copy of it rather than just retaining it. Also, no assumptions should be made about the relationship of the actual CFDictionaryRef returned by this call and the dictionary originally used to set the attributes, other than the fact that the values stored in the dictionary will be identical (that is, ==) to those originally specified.
#[doc(alias = "CFAttributedStringGetAttributes")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn attributes(
self: &CFAttributedString,
loc: CFIndex,
effective_range: *mut CFRange,
) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFAttributedStringGetAttributes(
a_str: &CFAttributedString,
loc: CFIndex,
effective_range: *mut CFRange,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFAttributedStringGetAttributes(self, loc, effective_range) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the value of a single attribute at the specified location. If the specified attribute doesn't exist at the location, returns NULL. If effectiveRange is not NULL, upon return *effectiveRange contains a range over which the exact same attribute value applies. Note that for performance reasons, the returned effectiveRange is not necessarily the maximal range - for that, use CFAttributedStringGetAttributeAndLongestEffectiveRange(). It's a programming error for loc to specify a location outside the bounds of the attributed string.
#[doc(alias = "CFAttributedStringGetAttribute")]
#[inline]
pub unsafe fn attribute(
self: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
effective_range: *mut CFRange,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFAttributedStringGetAttribute(
a_str: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
effective_range: *mut CFRange,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFAttributedStringGetAttribute(self, loc, attr_name, effective_range) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the attributes at the specified location. If longestEffectiveRange is not NULL, upon return *longestEffectiveRange contains the maximal range within inRange over which the exact same set of attributes apply. The returned range is clipped to inRange. It's a programming error for loc or inRange to specify locations outside the bounds of the attributed string.
#[doc(alias = "CFAttributedStringGetAttributesAndLongestEffectiveRange")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn attributes_and_longest_effective_range(
self: &CFAttributedString,
loc: CFIndex,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFAttributedStringGetAttributesAndLongestEffectiveRange(
a_str: &CFAttributedString,
loc: CFIndex,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe {
CFAttributedStringGetAttributesAndLongestEffectiveRange(
self,
loc,
in_range,
longest_effective_range,
)
};
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the value of a single attribute at the specified location. If longestEffectiveRange is not NULL, upon return *longestEffectiveRange contains the maximal range within inRange over which the exact same attribute value applies. The returned range is clipped to inRange. It's a programming error for loc or inRange to specify locations outside the bounds of the attributed string.
#[doc(alias = "CFAttributedStringGetAttributeAndLongestEffectiveRange")]
#[inline]
pub unsafe fn attribute_and_longest_effective_range(
self: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFAttributedStringGetAttributeAndLongestEffectiveRange(
a_str: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe {
CFAttributedStringGetAttributeAndLongestEffectiveRange(
self,
loc,
attr_name,
in_range,
longest_effective_range,
)
};
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
}
impl CFMutableAttributedString {
/// Creates a mutable attributed string copy. maxLength, if not 0, is a hard bound on the length of the attributed string; exceeding this size limit during any editing operation is a programming error. If 0, there is no limit on the length.
#[doc(alias = "CFAttributedStringCreateMutableCopy")]
#[inline]
pub fn new_copy(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
a_str: Option<&CFAttributedString>,
) -> Option<CFRetained<CFMutableAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateMutableCopy(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
a_str: Option<&CFAttributedString>,
) -> Option<NonNull<CFMutableAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateMutableCopy(alloc, max_length, a_str) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a mutable empty attributed string. maxLength, if not 0, is a hard bound on the length of the attributed string; exceeding this size limit during any editing operation is a programming error. If 0, there is no limit on the length.
#[doc(alias = "CFAttributedStringCreateMutable")]
#[inline]
pub fn new(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
) -> Option<CFRetained<CFMutableAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateMutable(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
) -> Option<NonNull<CFMutableAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateMutable(alloc, max_length) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Modifies the string for the attributed string, much like CFStringReplace(). It's an error for range to specify characters outside the bounds of aStr.
///
/// (Note: This function is a convenience on CFAttributedStringGetMutableString(); however, until CFAttributedStringGetMutableString() is implemented, it remains the only way to edit the string of the attributed string.)
#[doc(alias = "CFAttributedStringReplaceString")]
#[inline]
pub unsafe fn replace_string(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFString>,
) {
extern "C-unwind" {
fn CFAttributedStringReplaceString(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFString>,
);
}
unsafe { CFAttributedStringReplaceString(a_str, range, replacement) }
}
/// Gets the string for the attributed string as a mutable string, allowing editing the character contents of the string as if it were an CFMutableString. Attributes corresponding to the edited range are appropriately modified. If, as a result of the edit, new characters are introduced into the string, they inherit the attributes of the first replaced character from range. If no existing characters are replaced by the edit, the new characters inherit the attributes of the character preceding range if it has any, otherwise of the character following range. If the initial string is empty, the attributes for the new characters are also empty.
///
/// (Note: This function is not yet implemented and will return NULL except for toll-free bridged instances.)
#[doc(alias = "CFAttributedStringGetMutableString")]
#[inline]
pub fn mutable_string(
a_str: Option<&CFMutableAttributedString>,
) -> Option<CFRetained<CFMutableString>> {
extern "C-unwind" {
fn CFAttributedStringGetMutableString(
a_str: Option<&CFMutableAttributedString>,
) -> Option<NonNull<CFMutableString>>;
}
let ret = unsafe { CFAttributedStringGetMutableString(a_str) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Sets the value of multiple attributes over the specified range, which should be valid. If clearOtherAttributes is false, existing attributes (which aren't being replaced) are left alone; otherwise they are cleared. The dictionary should be setup for "usual" CF type usage --- CFString keys, and arbitrary CFType values. Note that after this call, further mutations to the replacement dictionary argument by the caller will not affect the contents of the attributed string.
#[doc(alias = "CFAttributedStringSetAttributes")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn set_attributes(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFDictionary>,
clear_other_attributes: bool,
) {
extern "C-unwind" {
fn CFAttributedStringSetAttributes(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFDictionary>,
clear_other_attributes: Boolean,
);
}
unsafe {
CFAttributedStringSetAttributes(a_str, range, replacement, clear_other_attributes as _)
}
}
/// Sets the value of a single attribute over the specified range, which should be valid. value should not be NULL.
#[doc(alias = "CFAttributedStringSetAttribute")]
#[inline]
pub unsafe fn set_attribute(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
attr_name: Option<&CFString>,
value: Option<&CFType>,
) {
extern "C-unwind" {
fn CFAttributedStringSetAttribute(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
attr_name: Option<&CFString>,
value: Option<&CFType>,
);
}
unsafe { CFAttributedStringSetAttribute(a_str, range, attr_name, value) }
}
/// Removes the value of a single attribute over the specified range, which should be valid. It's OK for the attribute not the exist over the specified range.
#[doc(alias = "CFAttributedStringRemoveAttribute")]
#[inline]
pub unsafe fn remove_attribute(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
attr_name: Option<&CFString>,
) {
extern "C-unwind" {
fn CFAttributedStringRemoveAttribute(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
attr_name: Option<&CFString>,
);
}
unsafe { CFAttributedStringRemoveAttribute(a_str, range, attr_name) }
}
/// Replaces the attributed substring over the specified range with the attributed string specified in replacement. range should be valid. To delete a range of the attributed string, call CFAttributedStringReplaceString() with empty string and specified range.
#[doc(alias = "CFAttributedStringReplaceAttributedString")]
#[inline]
pub unsafe fn replace_attributed_string(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFAttributedString>,
) {
extern "C-unwind" {
fn CFAttributedStringReplaceAttributedString(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFAttributedString>,
);
}
unsafe { CFAttributedStringReplaceAttributedString(a_str, range, replacement) }
}
/// In cases where attributed string might do a bunch of work to assure self-consistency, CFAttributedStringBeginEditing/CFAttributedStringEndEditing allow disabling that to allow deferring and coalescing any work. It's a good idea to call these around a set of related mutation calls which don't require the string to be in consistent state in between. These calls can be nested.
#[doc(alias = "CFAttributedStringBeginEditing")]
#[inline]
pub fn begin_editing(a_str: Option<&CFMutableAttributedString>) {
extern "C-unwind" {
fn CFAttributedStringBeginEditing(a_str: Option<&CFMutableAttributedString>);
}
unsafe { CFAttributedStringBeginEditing(a_str) }
}
/// In cases where attributed string might do a bunch of work to assure self-consistency, CFAttributedStringBeginEditing/CFAttributedStringEndEditing allow disabling that to allow deferring and coalescing any work. It's a good idea to call these around a set of related mutation calls which don't require the string to be in consistent state in between. These calls can be nested.
#[doc(alias = "CFAttributedStringEndEditing")]
#[inline]
pub fn end_editing(a_str: Option<&CFMutableAttributedString>) {
extern "C-unwind" {
fn CFAttributedStringEndEditing(a_str: Option<&CFMutableAttributedString>);
}
unsafe { CFAttributedStringEndEditing(a_str) }
}
}
impl CFAttributedString {
/// Fills bidiLevels by applying the Unicode Bidi Algorithm (P, X, W, N, and I) to the characters in range. Returns true if the result is not uni-level LTR (in other words, needing further Bidi processing). baseDirection is NSWritingDirection (NSWritingDirectionNatural, NSWritingDirectionLeftToRight, and NSWritingDirectionRightToLeft). Understands NSWritingDirectionAttributeName values.
#[doc(alias = "CFAttributedStringGetBidiLevelsAndResolvedDirections")]
#[inline]
pub unsafe fn bidi_levels_and_resolved_directions(
self: &CFAttributedString,
range: CFRange,
base_direction: i8,
bidi_levels: *mut u8,
base_directions: *mut u8,
) -> bool {
extern "C-unwind" {
fn CFAttributedStringGetBidiLevelsAndResolvedDirections(
attributed_string: &CFAttributedString,
range: CFRange,
base_direction: i8,
bidi_levels: *mut u8,
base_directions: *mut u8,
) -> bool;
}
unsafe {
CFAttributedStringGetBidiLevelsAndResolvedDirections(
self,
range,
base_direction,
bidi_levels,
base_directions,
)
}
}
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFAttributedString::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAttributedStringCreate(
alloc: Option<&CFAllocator>,
str: Option<&CFString>,
attributes: Option<&CFDictionary>,
) -> Option<CFRetained<CFAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreate(
alloc: Option<&CFAllocator>,
str: Option<&CFString>,
attributes: Option<&CFDictionary>,
) -> Option<NonNull<CFAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreate(alloc, str, attributes) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFAttributedString::with_substring`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAttributedStringCreateWithSubstring(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
range: CFRange,
) -> Option<CFRetained<CFAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateWithSubstring(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
range: CFRange,
) -> Option<NonNull<CFAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateWithSubstring(alloc, a_str, range) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFAttributedString::new_copy`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringCreateCopy(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
) -> Option<CFRetained<CFAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateCopy(
alloc: Option<&CFAllocator>,
a_str: Option<&CFAttributedString>,
) -> Option<NonNull<CFAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateCopy(alloc, a_str) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFAttributedString::string`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringGetString(
a_str: &CFAttributedString,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFAttributedStringGetString(a_str: &CFAttributedString) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFAttributedStringGetString(a_str) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFAttributedString::length`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringGetLength(a_str: &CFAttributedString) -> CFIndex {
extern "C-unwind" {
fn CFAttributedStringGetLength(a_str: &CFAttributedString) -> CFIndex;
}
unsafe { CFAttributedStringGetLength(a_str) }
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFAttributedString::attributes`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAttributedStringGetAttributes(
a_str: &CFAttributedString,
loc: CFIndex,
effective_range: *mut CFRange,
) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFAttributedStringGetAttributes(
a_str: &CFAttributedString,
loc: CFIndex,
effective_range: *mut CFRange,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFAttributedStringGetAttributes(a_str, loc, effective_range) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFAttributedString::attribute`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAttributedStringGetAttribute(
a_str: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
effective_range: *mut CFRange,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFAttributedStringGetAttribute(
a_str: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
effective_range: *mut CFRange,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFAttributedStringGetAttribute(a_str, loc, attr_name, effective_range) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFAttributedString::attributes_and_longest_effective_range`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAttributedStringGetAttributesAndLongestEffectiveRange(
a_str: &CFAttributedString,
loc: CFIndex,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFAttributedStringGetAttributesAndLongestEffectiveRange(
a_str: &CFAttributedString,
loc: CFIndex,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe {
CFAttributedStringGetAttributesAndLongestEffectiveRange(
a_str,
loc,
in_range,
longest_effective_range,
)
};
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFAttributedString::attribute_and_longest_effective_range`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAttributedStringGetAttributeAndLongestEffectiveRange(
a_str: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFAttributedStringGetAttributeAndLongestEffectiveRange(
a_str: &CFAttributedString,
loc: CFIndex,
attr_name: Option<&CFString>,
in_range: CFRange,
longest_effective_range: *mut CFRange,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe {
CFAttributedStringGetAttributeAndLongestEffectiveRange(
a_str,
loc,
attr_name,
in_range,
longest_effective_range,
)
};
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFMutableAttributedString::new_copy`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringCreateMutableCopy(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
a_str: Option<&CFAttributedString>,
) -> Option<CFRetained<CFMutableAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateMutableCopy(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
a_str: Option<&CFAttributedString>,
) -> Option<NonNull<CFMutableAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateMutableCopy(alloc, max_length, a_str) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableAttributedString::new`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringCreateMutable(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
) -> Option<CFRetained<CFMutableAttributedString>> {
extern "C-unwind" {
fn CFAttributedStringCreateMutable(
alloc: Option<&CFAllocator>,
max_length: CFIndex,
) -> Option<NonNull<CFMutableAttributedString>>;
}
let ret = unsafe { CFAttributedStringCreateMutable(alloc, max_length) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableAttributedString::replace_string`"]
pub fn CFAttributedStringReplaceString(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFString>,
);
}
#[deprecated = "renamed to `CFMutableAttributedString::mutable_string`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringGetMutableString(
a_str: Option<&CFMutableAttributedString>,
) -> Option<CFRetained<CFMutableString>> {
extern "C-unwind" {
fn CFAttributedStringGetMutableString(
a_str: Option<&CFMutableAttributedString>,
) -> Option<NonNull<CFMutableString>>;
}
let ret = unsafe { CFAttributedStringGetMutableString(a_str) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFMutableAttributedString::set_attributes`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAttributedStringSetAttributes(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFDictionary>,
clear_other_attributes: bool,
) {
extern "C-unwind" {
fn CFAttributedStringSetAttributes(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFDictionary>,
clear_other_attributes: Boolean,
);
}
unsafe {
CFAttributedStringSetAttributes(a_str, range, replacement, clear_other_attributes as _)
}
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableAttributedString::set_attribute`"]
pub fn CFAttributedStringSetAttribute(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
attr_name: Option<&CFString>,
value: Option<&CFType>,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableAttributedString::remove_attribute`"]
pub fn CFAttributedStringRemoveAttribute(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
attr_name: Option<&CFString>,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableAttributedString::replace_attributed_string`"]
pub fn CFAttributedStringReplaceAttributedString(
a_str: Option<&CFMutableAttributedString>,
range: CFRange,
replacement: Option<&CFAttributedString>,
);
}
#[deprecated = "renamed to `CFMutableAttributedString::begin_editing`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringBeginEditing(a_str: Option<&CFMutableAttributedString>) {
extern "C-unwind" {
fn CFAttributedStringBeginEditing(a_str: Option<&CFMutableAttributedString>);
}
unsafe { CFAttributedStringBeginEditing(a_str) }
}
#[deprecated = "renamed to `CFMutableAttributedString::end_editing`"]
#[inline]
pub extern "C-unwind" fn CFAttributedStringEndEditing(a_str: Option<&CFMutableAttributedString>) {
extern "C-unwind" {
fn CFAttributedStringEndEditing(a_str: Option<&CFMutableAttributedString>);
}
unsafe { CFAttributedStringEndEditing(a_str) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFAttributedString::bidi_levels_and_resolved_directions`"]
pub fn CFAttributedStringGetBidiLevelsAndResolvedDirections(
attributed_string: &CFAttributedString,
range: CFRange,
base_direction: i8,
bidi_levels: *mut u8,
base_directions: *mut u8,
) -> bool;
}

View File

@@ -0,0 +1,2 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT

View File

@@ -0,0 +1,473 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagretaincallback?language=objc)
pub type CFBagRetainCallBack =
Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagreleasecallback?language=objc)
pub type CFBagReleaseCallBack =
Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagcopydescriptioncallback?language=objc)
pub type CFBagCopyDescriptionCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagequalcallback?language=objc)
pub type CFBagEqualCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void, *const c_void) -> Boolean>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbaghashcallback?language=objc)
pub type CFBagHashCallBack = Option<unsafe extern "C-unwind" fn(*const c_void) -> CFHashCode>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagcallbacks?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFBagCallBacks {
pub version: CFIndex,
pub retain: CFBagRetainCallBack,
pub release: CFBagReleaseCallBack,
pub copyDescription: CFBagCopyDescriptionCallBack,
pub equal: CFBagEqualCallBack,
pub hash: CFBagHashCallBack,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFBagCallBacks {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<CFBagRetainCallBack>::ENCODING,
<CFBagReleaseCallBack>::ENCODING,
<CFBagCopyDescriptionCallBack>::ENCODING,
<CFBagEqualCallBack>::ENCODING,
<CFBagHashCallBack>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFBagCallBacks {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcftypebagcallbacks?language=objc)
pub static kCFTypeBagCallBacks: CFBagCallBacks;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcopystringbagcallbacks?language=objc)
pub static kCFCopyStringBagCallBacks: CFBagCallBacks;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagapplierfunction?language=objc)
pub type CFBagApplierFunction = Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbag?language=objc)
#[repr(C)]
pub struct CFBag<T: ?Sized = Opaque> {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
_generics: PhantomData<(*mut T,)>,
}
cf_type!(
unsafe impl<T: ?Sized> CFBag<T> {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl<T: ?Sized> RefEncode<"__CFBag"> for CFBag<T> {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutablebag?language=objc)
#[repr(C)]
pub struct CFMutableBag<T: ?Sized = Opaque> {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
_generics: PhantomData<(*mut T,)>,
}
cf_type!(
unsafe impl<T: ?Sized> CFMutableBag<T>: CFBag<T> {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl<T: ?Sized> RefEncode<"__CFBag"> for CFMutableBag<T> {}
);
unsafe impl ConcreteType for CFBag {
#[doc(alias = "CFBagGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFBagGetTypeID() -> CFTypeID;
}
unsafe { CFBagGetTypeID() }
}
}
impl CFBag {
#[doc(alias = "CFBagCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<CFRetained<CFBag>> {
extern "C-unwind" {
fn CFBagCreate(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<NonNull<CFBag>>;
}
let ret = unsafe { CFBagCreate(allocator, values, num_values, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFBagCreateCopy")]
#[inline]
pub unsafe fn new_copy(
allocator: Option<&CFAllocator>,
the_bag: Option<&CFBag>,
) -> Option<CFRetained<CFBag>> {
extern "C-unwind" {
fn CFBagCreateCopy(
allocator: Option<&CFAllocator>,
the_bag: Option<&CFBag>,
) -> Option<NonNull<CFBag>>;
}
let ret = unsafe { CFBagCreateCopy(allocator, the_bag) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFMutableBag {
#[doc(alias = "CFBagCreateMutable")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<CFRetained<CFMutableBag>> {
extern "C-unwind" {
fn CFBagCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<NonNull<CFMutableBag>>;
}
let ret = unsafe { CFBagCreateMutable(allocator, capacity, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFBagCreateMutableCopy")]
#[inline]
pub unsafe fn new_copy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_bag: Option<&CFBag>,
) -> Option<CFRetained<CFMutableBag>> {
extern "C-unwind" {
fn CFBagCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_bag: Option<&CFBag>,
) -> Option<NonNull<CFMutableBag>>;
}
let ret = unsafe { CFBagCreateMutableCopy(allocator, capacity, the_bag) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFBag {
#[doc(alias = "CFBagGetCount")]
#[inline]
pub unsafe fn count(self: &CFBag) -> CFIndex {
extern "C-unwind" {
fn CFBagGetCount(the_bag: &CFBag) -> CFIndex;
}
unsafe { CFBagGetCount(self) }
}
#[doc(alias = "CFBagGetCountOfValue")]
#[inline]
pub unsafe fn count_of_value(self: &CFBag, value: *const c_void) -> CFIndex {
extern "C-unwind" {
fn CFBagGetCountOfValue(the_bag: &CFBag, value: *const c_void) -> CFIndex;
}
unsafe { CFBagGetCountOfValue(self, value) }
}
#[doc(alias = "CFBagContainsValue")]
#[inline]
pub unsafe fn contains_value(self: &CFBag, value: *const c_void) -> bool {
extern "C-unwind" {
fn CFBagContainsValue(the_bag: &CFBag, value: *const c_void) -> Boolean;
}
let ret = unsafe { CFBagContainsValue(self, value) };
ret != 0
}
#[doc(alias = "CFBagGetValue")]
#[inline]
pub unsafe fn value(self: &CFBag, value: *const c_void) -> *const c_void {
extern "C-unwind" {
fn CFBagGetValue(the_bag: &CFBag, value: *const c_void) -> *const c_void;
}
unsafe { CFBagGetValue(self, value) }
}
#[doc(alias = "CFBagGetValueIfPresent")]
#[inline]
pub unsafe fn value_if_present(
self: &CFBag,
candidate: *const c_void,
value: *mut *const c_void,
) -> bool {
extern "C-unwind" {
fn CFBagGetValueIfPresent(
the_bag: &CFBag,
candidate: *const c_void,
value: *mut *const c_void,
) -> Boolean;
}
let ret = unsafe { CFBagGetValueIfPresent(self, candidate, value) };
ret != 0
}
#[doc(alias = "CFBagGetValues")]
#[inline]
pub unsafe fn values(self: &CFBag, values: *mut *const c_void) {
extern "C-unwind" {
fn CFBagGetValues(the_bag: &CFBag, values: *mut *const c_void);
}
unsafe { CFBagGetValues(self, values) }
}
#[doc(alias = "CFBagApplyFunction")]
#[inline]
pub unsafe fn apply_function(
self: &CFBag,
applier: CFBagApplierFunction,
context: *mut c_void,
) {
extern "C-unwind" {
fn CFBagApplyFunction(
the_bag: &CFBag,
applier: CFBagApplierFunction,
context: *mut c_void,
);
}
unsafe { CFBagApplyFunction(self, applier, context) }
}
}
impl CFMutableBag {
#[doc(alias = "CFBagAddValue")]
#[inline]
pub unsafe fn add_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
extern "C-unwind" {
fn CFBagAddValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
unsafe { CFBagAddValue(the_bag, value) }
}
#[doc(alias = "CFBagReplaceValue")]
#[inline]
pub unsafe fn replace_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
extern "C-unwind" {
fn CFBagReplaceValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
unsafe { CFBagReplaceValue(the_bag, value) }
}
#[doc(alias = "CFBagSetValue")]
#[inline]
pub unsafe fn set_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
extern "C-unwind" {
fn CFBagSetValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
unsafe { CFBagSetValue(the_bag, value) }
}
#[doc(alias = "CFBagRemoveValue")]
#[inline]
pub unsafe fn remove_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
extern "C-unwind" {
fn CFBagRemoveValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
unsafe { CFBagRemoveValue(the_bag, value) }
}
#[doc(alias = "CFBagRemoveAllValues")]
#[inline]
pub unsafe fn remove_all_values(the_bag: Option<&CFMutableBag>) {
extern "C-unwind" {
fn CFBagRemoveAllValues(the_bag: Option<&CFMutableBag>);
}
unsafe { CFBagRemoveAllValues(the_bag) }
}
}
#[deprecated = "renamed to `CFBag::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBagCreate(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<CFRetained<CFBag>> {
extern "C-unwind" {
fn CFBagCreate(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<NonNull<CFBag>>;
}
let ret = unsafe { CFBagCreate(allocator, values, num_values, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFBag::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBagCreateCopy(
allocator: Option<&CFAllocator>,
the_bag: Option<&CFBag>,
) -> Option<CFRetained<CFBag>> {
extern "C-unwind" {
fn CFBagCreateCopy(
allocator: Option<&CFAllocator>,
the_bag: Option<&CFBag>,
) -> Option<NonNull<CFBag>>;
}
let ret = unsafe { CFBagCreateCopy(allocator, the_bag) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableBag::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBagCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<CFRetained<CFMutableBag>> {
extern "C-unwind" {
fn CFBagCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBagCallBacks,
) -> Option<NonNull<CFMutableBag>>;
}
let ret = unsafe { CFBagCreateMutable(allocator, capacity, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableBag::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBagCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_bag: Option<&CFBag>,
) -> Option<CFRetained<CFMutableBag>> {
extern "C-unwind" {
fn CFBagCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_bag: Option<&CFBag>,
) -> Option<NonNull<CFMutableBag>>;
}
let ret = unsafe { CFBagCreateMutableCopy(allocator, capacity, the_bag) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBag::count`"]
pub fn CFBagGetCount(the_bag: &CFBag) -> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBag::count_of_value`"]
pub fn CFBagGetCountOfValue(the_bag: &CFBag, value: *const c_void) -> CFIndex;
}
#[deprecated = "renamed to `CFBag::contains_value`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBagContainsValue(the_bag: &CFBag, value: *const c_void) -> bool {
extern "C-unwind" {
fn CFBagContainsValue(the_bag: &CFBag, value: *const c_void) -> Boolean;
}
let ret = unsafe { CFBagContainsValue(the_bag, value) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBag::value`"]
pub fn CFBagGetValue(the_bag: &CFBag, value: *const c_void) -> *const c_void;
}
#[deprecated = "renamed to `CFBag::value_if_present`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBagGetValueIfPresent(
the_bag: &CFBag,
candidate: *const c_void,
value: *mut *const c_void,
) -> bool {
extern "C-unwind" {
fn CFBagGetValueIfPresent(
the_bag: &CFBag,
candidate: *const c_void,
value: *mut *const c_void,
) -> Boolean;
}
let ret = unsafe { CFBagGetValueIfPresent(the_bag, candidate, value) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBag::values`"]
pub fn CFBagGetValues(the_bag: &CFBag, values: *mut *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBag::apply_function`"]
pub fn CFBagApplyFunction(the_bag: &CFBag, applier: CFBagApplierFunction, context: *mut c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBag::add_value`"]
pub fn CFBagAddValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBag::replace_value`"]
pub fn CFBagReplaceValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBag::set_value`"]
pub fn CFBagSetValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBag::remove_value`"]
pub fn CFBagRemoveValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBag::remove_all_values`"]
pub fn CFBagRemoveAllValues(the_bag: Option<&CFMutableBag>);
}

View File

@@ -0,0 +1,812 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_0?language=objc)
pub const kCFCoreFoundationVersionNumber10_0: c_float = 196.40;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_0_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_0_3: c_float = 196.50;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_1: c_float = 226.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_1_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_1_1: c_float = 226.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_1_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_1_2: c_float = 227.20;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_1_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_1_3: c_float = 227.20;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_1_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_1_4: c_float = 227.30;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_2: c_float = 263.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_1: c_float = 263.10;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_2: c_float = 263.10;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_3: c_float = 263.30;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_4: c_float = 263.30;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_5?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_5: c_float = 263.50;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_6?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_6: c_float = 263.50;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_7?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_7: c_float = 263.50;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_2_8?language=objc)
pub const kCFCoreFoundationVersionNumber10_2_8: c_float = 263.50;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_3: c_float = 299.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_1: c_float = 299.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_2: c_float = 299.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_3: c_float = 299.30;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_4: c_float = 299.31;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_5?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_5: c_float = 299.31;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_6?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_6: c_float = 299.32;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_7?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_7: c_float = 299.33;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_8?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_8: c_float = 299.33;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_3_9?language=objc)
pub const kCFCoreFoundationVersionNumber10_3_9: c_float = 299.35;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_4: c_float = 368.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_1: c_float = 368.10;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_2: c_float = 368.11;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_3: c_float = 368.18;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_4_intel?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_4_Intel: c_float = 368.26;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_4_powerpc?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_4_PowerPC: c_float = 368.25;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_5_intel?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_5_Intel: c_float = 368.26;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_5_powerpc?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_5_PowerPC: c_float = 368.25;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_6_intel?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_6_Intel: c_float = 368.26;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_6_powerpc?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_6_PowerPC: c_float = 368.25;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_7?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_7: c_float = 368.27;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_8?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_8: c_float = 368.27;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_9?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_9: c_float = 368.28;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_10?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_10: c_float = 368.28;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_4_11?language=objc)
pub const kCFCoreFoundationVersionNumber10_4_11: c_float = 368.31;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5?language=objc)
pub const kCFCoreFoundationVersionNumber10_5: c_float = 476.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_1: c_float = 476.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_2: c_float = 476.10;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_3: c_float = 476.13;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_4: c_float = 476.14;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_5?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_5: c_float = 476.15;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_6?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_6: c_float = 476.17;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_7?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_7: c_float = 476.18;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_5_8?language=objc)
pub const kCFCoreFoundationVersionNumber10_5_8: c_float = 476.19;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6?language=objc)
pub const kCFCoreFoundationVersionNumber10_6: c_float = 550.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_1: c_float = 550.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_2: c_float = 550.13;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_3: c_float = 550.19;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_4: c_float = 550.29;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_5?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_5: c_float = 550.42;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_6?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_6: c_float = 550.42;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_7?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_7: c_float = 550.42;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_6_8?language=objc)
pub const kCFCoreFoundationVersionNumber10_6_8: c_float = 550.43;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_7?language=objc)
pub const kCFCoreFoundationVersionNumber10_7: c_float = 635.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_7_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_7_1: c_float = 635.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_7_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_7_2: c_float = 635.15;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_7_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_7_3: c_float = 635.19;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_7_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_7_4: c_float = 635.21;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_7_5?language=objc)
pub const kCFCoreFoundationVersionNumber10_7_5: c_float = 635.21;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_8?language=objc)
pub const kCFCoreFoundationVersionNumber10_8: c_float = 744.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_8_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_8_1: c_float = 744.00;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_8_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_8_2: c_float = 744.12;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_8_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_8_3: c_float = 744.18;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_8_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_8_4: c_float = 744.19;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_9?language=objc)
pub const kCFCoreFoundationVersionNumber10_9: c_float = 855.11;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_9_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_9_1: c_float = 855.11;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_9_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_9_2: c_float = 855.14;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_10?language=objc)
pub const kCFCoreFoundationVersionNumber10_10: c_float = 1151.16;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_10_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_10_1: c_float = 1151.16;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_10_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_10_2: c_uint = 1152;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_10_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_10_3: c_float = 1153.18;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_10_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_10_4: c_float = 1153.18;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_10_5?language=objc)
pub const kCFCoreFoundationVersionNumber10_10_5: c_float = 1153.18;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_10_max?language=objc)
pub const kCFCoreFoundationVersionNumber10_10_Max: c_uint = 1199;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_11?language=objc)
pub const kCFCoreFoundationVersionNumber10_11: c_uint = 1253;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_11_1?language=objc)
pub const kCFCoreFoundationVersionNumber10_11_1: c_float = 1255.1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_11_2?language=objc)
pub const kCFCoreFoundationVersionNumber10_11_2: c_float = 1256.14;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_11_3?language=objc)
pub const kCFCoreFoundationVersionNumber10_11_3: c_float = 1256.14;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_11_4?language=objc)
pub const kCFCoreFoundationVersionNumber10_11_4: c_float = 1258.1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber10_11_max?language=objc)
pub const kCFCoreFoundationVersionNumber10_11_Max: c_uint = 1299;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatortypeid?language=objc)
pub type CFAllocatorTypeID = c_ulonglong;
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber?language=objc)
pub static kCFCoreFoundationVersionNumber: c_double;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfstring?language=objc)
#[repr(C)]
pub struct CFString {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFString {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFString"> for CFString {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutablestring?language=objc)
#[repr(C)]
pub struct CFMutableString {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFMutableString: CFString {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFString"> for CFMutableString {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfpropertylist?language=objc)
pub type CFPropertyList = CFType;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcomparisonresult?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFComparisonResult(pub CFIndex);
impl CFComparisonResult {
#[doc(alias = "kCFCompareLessThan")]
pub const CompareLessThan: Self = Self(-1);
#[doc(alias = "kCFCompareEqualTo")]
pub const CompareEqualTo: Self = Self(0);
#[doc(alias = "kCFCompareGreaterThan")]
pub const CompareGreaterThan: Self = Self(1);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFComparisonResult {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFComparisonResult {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcomparatorfunction?language=objc)
pub type CFComparatorFunction = Option<
unsafe extern "C-unwind" fn(*const c_void, *const c_void, *mut c_void) -> CFComparisonResult,
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnotfound?language=objc)
pub static kCFNotFound: CFIndex = -1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfrange?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFRange {
pub location: CFIndex,
pub length: CFIndex,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFRange {
const ENCODING: Encoding = Encoding::Struct("?", &[<CFIndex>::ENCODING, <CFIndex>::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFRange {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnull?language=objc)
#[repr(C)]
pub struct CFNull {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFNull {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFNull"> for CFNull {}
);
unsafe impl ConcreteType for CFNull {
#[doc(alias = "CFNullGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFNullGetTypeID() -> CFTypeID;
}
unsafe { CFNullGetTypeID() }
}
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnull?language=objc)
pub static kCFNull: Option<&'static CFNull>;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocator?language=objc)
#[repr(C)]
pub struct CFAllocator {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFAllocator {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFAllocator"> for CFAllocator {}
);
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatordefault?language=objc)
pub static kCFAllocatorDefault: Option<&'static CFAllocator>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatorsystemdefault?language=objc)
pub static kCFAllocatorSystemDefault: Option<&'static CFAllocator>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatormalloc?language=objc)
pub static kCFAllocatorMalloc: Option<&'static CFAllocator>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatormalloczone?language=objc)
pub static kCFAllocatorMallocZone: Option<&'static CFAllocator>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatornull?language=objc)
pub static kCFAllocatorNull: Option<&'static CFAllocator>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatorusecontext?language=objc)
pub static kCFAllocatorUseContext: Option<&'static CFAllocator>;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorretaincallback?language=objc)
pub type CFAllocatorRetainCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorreleasecallback?language=objc)
pub type CFAllocatorReleaseCallBack = Option<unsafe extern "C-unwind" fn(*const c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorcopydescriptioncallback?language=objc)
pub type CFAllocatorCopyDescriptionCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorallocatecallback?language=objc)
pub type CFAllocatorAllocateCallBack =
Option<unsafe extern "C-unwind" fn(CFIndex, CFOptionFlags, *mut c_void) -> *mut c_void>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorreallocatecallback?language=objc)
pub type CFAllocatorReallocateCallBack = Option<
unsafe extern "C-unwind" fn(*mut c_void, CFIndex, CFOptionFlags, *mut c_void) -> *mut c_void,
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatordeallocatecallback?language=objc)
pub type CFAllocatorDeallocateCallBack =
Option<unsafe extern "C-unwind" fn(*mut c_void, *mut c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorpreferredsizecallback?language=objc)
pub type CFAllocatorPreferredSizeCallBack =
Option<unsafe extern "C-unwind" fn(CFIndex, CFOptionFlags, *mut c_void) -> CFIndex>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorcontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFAllocatorContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: CFAllocatorRetainCallBack,
pub release: CFAllocatorReleaseCallBack,
pub copyDescription: CFAllocatorCopyDescriptionCallBack,
pub allocate: CFAllocatorAllocateCallBack,
pub reallocate: CFAllocatorReallocateCallBack,
pub deallocate: CFAllocatorDeallocateCallBack,
pub preferredSize: CFAllocatorPreferredSizeCallBack,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFAllocatorContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<CFAllocatorRetainCallBack>::ENCODING,
<CFAllocatorReleaseCallBack>::ENCODING,
<CFAllocatorCopyDescriptionCallBack>::ENCODING,
<CFAllocatorAllocateCallBack>::ENCODING,
<CFAllocatorReallocateCallBack>::ENCODING,
<CFAllocatorDeallocateCallBack>::ENCODING,
<CFAllocatorPreferredSizeCallBack>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFAllocatorContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFAllocator {
#[doc(alias = "CFAllocatorGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFAllocatorGetTypeID() -> CFTypeID;
}
unsafe { CFAllocatorGetTypeID() }
}
}
impl CFAllocator {
#[doc(alias = "CFAllocatorSetDefault")]
#[inline]
pub fn set_default(allocator: Option<&CFAllocator>) {
extern "C-unwind" {
fn CFAllocatorSetDefault(allocator: Option<&CFAllocator>);
}
unsafe { CFAllocatorSetDefault(allocator) }
}
#[doc(alias = "CFAllocatorGetDefault")]
#[inline]
pub fn default() -> Option<CFRetained<CFAllocator>> {
extern "C-unwind" {
fn CFAllocatorGetDefault() -> Option<NonNull<CFAllocator>>;
}
let ret = unsafe { CFAllocatorGetDefault() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFAllocatorCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
context: *mut CFAllocatorContext,
) -> Option<CFRetained<CFAllocator>> {
extern "C-unwind" {
fn CFAllocatorCreate(
allocator: Option<&CFAllocator>,
context: *mut CFAllocatorContext,
) -> Option<NonNull<CFAllocator>>;
}
let ret = unsafe { CFAllocatorCreate(allocator, context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFAllocatorAllocateTyped")]
#[inline]
pub unsafe fn allocate_typed(
allocator: Option<&CFAllocator>,
size: CFIndex,
descriptor: CFAllocatorTypeID,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorAllocateTyped(
allocator: Option<&CFAllocator>,
size: CFIndex,
descriptor: CFAllocatorTypeID,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorAllocateTyped(allocator, size, descriptor, hint) }
}
#[doc(alias = "CFAllocatorReallocateTyped")]
#[inline]
pub unsafe fn reallocate_typed(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
descriptor: CFAllocatorTypeID,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorReallocateTyped(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
descriptor: CFAllocatorTypeID,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorReallocateTyped(allocator, ptr, newsize, descriptor, hint) }
}
#[doc(alias = "CFAllocatorAllocateBytes")]
#[inline]
pub fn allocate_bytes(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorAllocateBytes(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorAllocateBytes(allocator, size, hint) }
}
#[doc(alias = "CFAllocatorReallocateBytes")]
#[inline]
pub unsafe fn reallocate_bytes(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorReallocateBytes(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorReallocateBytes(allocator, ptr, newsize, hint) }
}
#[doc(alias = "CFAllocatorAllocate")]
#[inline]
pub fn allocate(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorAllocate(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorAllocate(allocator, size, hint) }
}
#[doc(alias = "CFAllocatorReallocate")]
#[inline]
pub unsafe fn reallocate(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorReallocate(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorReallocate(allocator, ptr, newsize, hint) }
}
#[doc(alias = "CFAllocatorDeallocate")]
#[inline]
pub unsafe fn deallocate(allocator: Option<&CFAllocator>, ptr: *mut c_void) {
extern "C-unwind" {
fn CFAllocatorDeallocate(allocator: Option<&CFAllocator>, ptr: *mut c_void);
}
unsafe { CFAllocatorDeallocate(allocator, ptr) }
}
#[doc(alias = "CFAllocatorGetPreferredSizeForSize")]
#[inline]
pub fn preferred_size_for_size(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> CFIndex {
extern "C-unwind" {
fn CFAllocatorGetPreferredSizeForSize(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> CFIndex;
}
unsafe { CFAllocatorGetPreferredSizeForSize(allocator, size, hint) }
}
#[doc(alias = "CFAllocatorGetContext")]
#[inline]
pub unsafe fn context(allocator: Option<&CFAllocator>, context: *mut CFAllocatorContext) {
extern "C-unwind" {
fn CFAllocatorGetContext(
allocator: Option<&CFAllocator>,
context: *mut CFAllocatorContext,
);
}
unsafe { CFAllocatorGetContext(allocator, context) }
}
}
#[inline]
pub extern "C-unwind" fn CFGetTypeID(cf: Option<&CFType>) -> CFTypeID {
extern "C-unwind" {
fn CFGetTypeID(cf: Option<&CFType>) -> CFTypeID;
}
unsafe { CFGetTypeID(cf) }
}
#[inline]
pub extern "C-unwind" fn CFCopyTypeIDDescription(
type_id: CFTypeID,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFCopyTypeIDDescription(type_id: CFTypeID) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFCopyTypeIDDescription(type_id) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[inline]
pub extern "C-unwind" fn CFGetRetainCount(cf: Option<&CFType>) -> CFIndex {
extern "C-unwind" {
fn CFGetRetainCount(cf: Option<&CFType>) -> CFIndex;
}
unsafe { CFGetRetainCount(cf) }
}
#[inline]
pub extern "C-unwind" fn CFEqual(cf1: Option<&CFType>, cf2: Option<&CFType>) -> bool {
extern "C-unwind" {
fn CFEqual(cf1: Option<&CFType>, cf2: Option<&CFType>) -> Boolean;
}
let ret = unsafe { CFEqual(cf1, cf2) };
ret != 0
}
#[inline]
pub extern "C-unwind" fn CFHash(cf: Option<&CFType>) -> CFHashCode {
extern "C-unwind" {
fn CFHash(cf: Option<&CFType>) -> CFHashCode;
}
unsafe { CFHash(cf) }
}
#[inline]
pub extern "C-unwind" fn CFCopyDescription(cf: Option<&CFType>) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFCopyDescription(cf: Option<&CFType>) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFCopyDescription(cf) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[inline]
pub extern "C-unwind" fn CFGetAllocator(cf: Option<&CFType>) -> Option<CFRetained<CFAllocator>> {
extern "C-unwind" {
fn CFGetAllocator(cf: Option<&CFType>) -> Option<NonNull<CFAllocator>>;
}
let ret = unsafe { CFGetAllocator(cf) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFAllocator::set_default`"]
#[inline]
pub extern "C-unwind" fn CFAllocatorSetDefault(allocator: Option<&CFAllocator>) {
extern "C-unwind" {
fn CFAllocatorSetDefault(allocator: Option<&CFAllocator>);
}
unsafe { CFAllocatorSetDefault(allocator) }
}
#[deprecated = "renamed to `CFAllocator::default`"]
#[inline]
pub extern "C-unwind" fn CFAllocatorGetDefault() -> Option<CFRetained<CFAllocator>> {
extern "C-unwind" {
fn CFAllocatorGetDefault() -> Option<NonNull<CFAllocator>>;
}
let ret = unsafe { CFAllocatorGetDefault() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFAllocator::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFAllocatorCreate(
allocator: Option<&CFAllocator>,
context: *mut CFAllocatorContext,
) -> Option<CFRetained<CFAllocator>> {
extern "C-unwind" {
fn CFAllocatorCreate(
allocator: Option<&CFAllocator>,
context: *mut CFAllocatorContext,
) -> Option<NonNull<CFAllocator>>;
}
let ret = unsafe { CFAllocatorCreate(allocator, context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFAllocator::allocate_typed`"]
pub fn CFAllocatorAllocateTyped(
allocator: Option<&CFAllocator>,
size: CFIndex,
descriptor: CFAllocatorTypeID,
hint: CFOptionFlags,
) -> *mut c_void;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFAllocator::reallocate_typed`"]
pub fn CFAllocatorReallocateTyped(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
descriptor: CFAllocatorTypeID,
hint: CFOptionFlags,
) -> *mut c_void;
}
#[deprecated = "renamed to `CFAllocator::allocate_bytes`"]
#[inline]
pub extern "C-unwind" fn CFAllocatorAllocateBytes(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorAllocateBytes(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorAllocateBytes(allocator, size, hint) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFAllocator::reallocate_bytes`"]
pub fn CFAllocatorReallocateBytes(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
#[deprecated = "renamed to `CFAllocator::allocate`"]
#[inline]
pub extern "C-unwind" fn CFAllocatorAllocate(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void {
extern "C-unwind" {
fn CFAllocatorAllocate(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
unsafe { CFAllocatorAllocate(allocator, size, hint) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFAllocator::reallocate`"]
pub fn CFAllocatorReallocate(
allocator: Option<&CFAllocator>,
ptr: *mut c_void,
newsize: CFIndex,
hint: CFOptionFlags,
) -> *mut c_void;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFAllocator::deallocate`"]
pub fn CFAllocatorDeallocate(allocator: Option<&CFAllocator>, ptr: *mut c_void);
}
#[deprecated = "renamed to `CFAllocator::preferred_size_for_size`"]
#[inline]
pub extern "C-unwind" fn CFAllocatorGetPreferredSizeForSize(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> CFIndex {
extern "C-unwind" {
fn CFAllocatorGetPreferredSizeForSize(
allocator: Option<&CFAllocator>,
size: CFIndex,
hint: CFOptionFlags,
) -> CFIndex;
}
unsafe { CFAllocatorGetPreferredSizeForSize(allocator, size, hint) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFAllocator::context`"]
pub fn CFAllocatorGetContext(allocator: Option<&CFAllocator>, context: *mut CFAllocatorContext);
}

View File

@@ -0,0 +1,580 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheapcomparecontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFBinaryHeapCompareContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFBinaryHeapCompareContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFBinaryHeapCompareContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Structure containing the callbacks for values of a CFBinaryHeap.
/// Field: version The version number of the structure type being passed
/// in as a parameter to the CFBinaryHeap creation functions.
/// This structure is version 0.
/// Field: retain The callback used to add a retain for the binary heap
/// on values as they are put into the binary heap.
/// This callback returns the value to use as the value in the
/// binary heap, which is usually the value parameter passed to
/// this callback, but may be a different value if a different
/// value should be added to the binary heap. The binary heap's
/// allocator is passed as the first argument.
/// Field: release The callback used to remove a retain previously added
/// for the binary heap from values as they are removed from
/// the binary heap. The binary heap's allocator is passed as the
/// first argument.
/// Field: copyDescription The callback used to create a descriptive
/// string representation of each value in the binary heap. This
/// is used by the CFCopyDescription() function.
/// Field: compare The callback used to compare values in the binary heap for
/// equality in some operations.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheapcallbacks?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFBinaryHeapCallBacks {
pub version: CFIndex,
pub retain:
Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void>,
pub release: Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>,
pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
pub compare: Option<
unsafe extern "C-unwind" fn(
*const c_void,
*const c_void,
*mut c_void,
) -> CFComparisonResult,
>,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFBinaryHeapCallBacks {
const ENCODING: Encoding =
Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<Option<
unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void,
>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
<Option<
unsafe extern "C-unwind" fn(
*const c_void,
*const c_void,
*mut c_void,
) -> CFComparisonResult,
>>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFBinaryHeapCallBacks {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern "C" {
/// Predefined CFBinaryHeapCallBacks structure containing a set
/// of callbacks appropriate for use when the values in a CFBinaryHeap
/// are all CFString types.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringbinaryheapcallbacks?language=objc)
pub static kCFStringBinaryHeapCallBacks: CFBinaryHeapCallBacks;
}
/// Type of the callback function used by the apply functions of
/// CFBinaryHeap.
///
/// Parameter `val`: The current value from the binary heap.
///
/// Parameter `context`: The user-defined context parameter given to the apply
/// function.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheapapplierfunction?language=objc)
pub type CFBinaryHeapApplierFunction =
Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
/// This is the type of a reference to CFBinaryHeaps.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheap?language=objc)
#[repr(C)]
pub struct CFBinaryHeap<T: ?Sized = Opaque> {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
_generics: PhantomData<(*mut T,)>,
}
cf_type!(
unsafe impl<T: ?Sized> CFBinaryHeap<T> {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl<T: ?Sized> RefEncode<"__CFBinaryHeap"> for CFBinaryHeap<T> {}
);
unsafe impl ConcreteType for CFBinaryHeap {
/// Returns the type identifier of all CFBinaryHeap instances.
#[doc(alias = "CFBinaryHeapGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFBinaryHeapGetTypeID() -> CFTypeID;
}
unsafe { CFBinaryHeapGetTypeID() }
}
}
impl CFBinaryHeap {
/// Creates a new mutable binary heap with the given values.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate
/// memory for the binary heap and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `capacity`: A hint about the number of values that will be held
/// by the CFBinaryHeap. Pass 0 for no hint. The implementation may
/// ignore this hint, or may use it to optimize various
/// operations. A heap's actual capacity is only limited by
/// address space and available memory constraints). If this
/// parameter is negative, the behavior is undefined.
///
/// Parameter `callBacks`: A pointer to a CFBinaryHeapCallBacks structure
/// initialized with the callbacks for the binary heap to use on
/// each value in the binary heap. A copy of the contents of the
/// callbacks structure is made, so that a pointer to a structure
/// on the stack can be passed in, or can be reused for multiple
/// binary heap creations. If the version field of this callbacks
/// structure is not one of the defined ones for CFBinaryHeap, the
/// behavior is undefined. The retain field may be NULL, in which
/// case the CFBinaryHeap will do nothing to add a retain to values
/// as they are put into the binary heap. The release field may be
/// NULL, in which case the CFBinaryHeap will do nothing to remove
/// the binary heap's retain (if any) on the values when the
/// heap is destroyed or a key-value pair is removed. If the
/// copyDescription field is NULL, the binary heap will create a
/// simple description for a value. If the equal field is NULL, the
/// binary heap will use pointer equality to test for equality of
/// values. This callbacks parameter itself may be NULL, which is
/// treated as if a valid structure of version 0 with all fields
/// NULL had been passed in. Otherwise,
/// if any of the fields are not valid pointers to functions
/// of the correct type, or this parameter is not a valid
/// pointer to a CFBinaryHeapCallBacks callbacks structure,
/// the behavior is undefined. If any of the values put into the
/// binary heap is not one understood by one of the callback functions
/// the behavior when that callback function is used is undefined.
///
/// Parameter `compareContext`: A pointer to a CFBinaryHeapCompareContext structure.
///
/// Returns: A reference to the new CFBinaryHeap.
#[doc(alias = "CFBinaryHeapCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBinaryHeapCallBacks,
compare_context: *const CFBinaryHeapCompareContext,
) -> Option<CFRetained<CFBinaryHeap>> {
extern "C-unwind" {
fn CFBinaryHeapCreate(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBinaryHeapCallBacks,
compare_context: *const CFBinaryHeapCompareContext,
) -> Option<NonNull<CFBinaryHeap>>;
}
let ret = unsafe { CFBinaryHeapCreate(allocator, capacity, call_backs, compare_context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a new mutable binary heap with the values from the given binary heap.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate
/// memory for the binary heap and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `capacity`: A hint about the number of values that will be held
/// by the CFBinaryHeap. Pass 0 for no hint. The implementation may
/// ignore this hint, or may use it to optimize various
/// operations. A heap's actual capacity is only limited by
/// address space and available memory constraints).
/// This parameter must be greater than or equal
/// to the count of the heap which is to be copied, or the
/// behavior is undefined. If this parameter is negative, the
/// behavior is undefined.
///
/// Parameter `heap`: The binary heap which is to be copied. The values from the
/// binary heap are copied as pointers into the new binary heap (that is,
/// the values themselves are copied, not that which the values
/// point to, if anything). However, the values are also
/// retained by the new binary heap. The count of the new binary will
/// be the same as the given binary heap. The new binary heap uses the same
/// callbacks as the binary heap to be copied. If this parameter is
/// not a valid CFBinaryHeap, the behavior is undefined.
///
/// Returns: A reference to the new mutable binary heap.
#[doc(alias = "CFBinaryHeapCreateCopy")]
#[inline]
pub unsafe fn new_copy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
heap: Option<&CFBinaryHeap>,
) -> Option<CFRetained<CFBinaryHeap>> {
extern "C-unwind" {
fn CFBinaryHeapCreateCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
heap: Option<&CFBinaryHeap>,
) -> Option<NonNull<CFBinaryHeap>>;
}
let ret = unsafe { CFBinaryHeapCreateCopy(allocator, capacity, heap) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns the number of values currently in the binary heap.
///
/// Parameter `heap`: The binary heap to be queried. If this parameter is not a valid
/// CFBinaryHeap, the behavior is undefined.
///
/// Returns: The number of values in the binary heap.
#[doc(alias = "CFBinaryHeapGetCount")]
#[inline]
pub unsafe fn count(self: &CFBinaryHeap) -> CFIndex {
extern "C-unwind" {
fn CFBinaryHeapGetCount(heap: &CFBinaryHeap) -> CFIndex;
}
unsafe { CFBinaryHeapGetCount(self) }
}
/// Counts the number of times the given value occurs in the binary heap.
///
/// Parameter `heap`: The binary heap to be searched. If this parameter is not a
/// valid CFBinaryHeap, the behavior is undefined.
///
/// Parameter `value`: The value for which to find matches in the binary heap. The
/// compare() callback provided when the binary heap was created is
/// used to compare. If the compare() callback was NULL, pointer
/// equality (in C, ==) is used. If value, or any of the values
/// in the binary heap, are not understood by the compare() callback,
/// the behavior is undefined.
///
/// Returns: The number of times the given value occurs in the binary heap.
#[doc(alias = "CFBinaryHeapGetCountOfValue")]
#[inline]
pub unsafe fn count_of_value(self: &CFBinaryHeap, value: *const c_void) -> CFIndex {
extern "C-unwind" {
fn CFBinaryHeapGetCountOfValue(heap: &CFBinaryHeap, value: *const c_void) -> CFIndex;
}
unsafe { CFBinaryHeapGetCountOfValue(self, value) }
}
/// Reports whether or not the value is in the binary heap.
///
/// Parameter `heap`: The binary heap to be searched. If this parameter is not a
/// valid CFBinaryHeap, the behavior is undefined.
///
/// Parameter `value`: The value for which to find matches in the binary heap. The
/// compare() callback provided when the binary heap was created is
/// used to compare. If the compare() callback was NULL, pointer
/// equality (in C, ==) is used. If value, or any of the values
/// in the binary heap, are not understood by the compare() callback,
/// the behavior is undefined.
///
/// Returns: true, if the value is in the specified binary heap, otherwise false.
#[doc(alias = "CFBinaryHeapContainsValue")]
#[inline]
pub unsafe fn contains_value(self: &CFBinaryHeap, value: *const c_void) -> bool {
extern "C-unwind" {
fn CFBinaryHeapContainsValue(heap: &CFBinaryHeap, value: *const c_void) -> Boolean;
}
let ret = unsafe { CFBinaryHeapContainsValue(self, value) };
ret != 0
}
/// Returns the minimum value is in the binary heap. If the heap contains several equal
/// minimum values, any one may be returned.
///
/// Parameter `heap`: The binary heap to be searched. If this parameter is not a
/// valid CFBinaryHeap, the behavior is undefined.
///
/// Returns: A reference to the minimum value in the binary heap, or NULL if the
/// binary heap contains no values.
#[doc(alias = "CFBinaryHeapGetMinimum")]
#[inline]
pub unsafe fn minimum(self: &CFBinaryHeap) -> *const c_void {
extern "C-unwind" {
fn CFBinaryHeapGetMinimum(heap: &CFBinaryHeap) -> *const c_void;
}
unsafe { CFBinaryHeapGetMinimum(self) }
}
/// Returns the minimum value is in the binary heap, if present. If the heap contains several equal
/// minimum values, any one may be returned.
///
/// Parameter `heap`: The binary heap to be searched. If this parameter is not a
/// valid CFBinaryHeap, the behavior is undefined.
///
/// Parameter `value`: A C pointer to pointer-sized storage to be filled with the minimum value in
/// the binary heap. If this value is not a valid C pointer to a pointer-sized block
/// of storage, the result is undefined. If the result of the function is false, the value
/// stored at this address is undefined.
///
/// Returns: true, if a minimum value was found in the specified binary heap, otherwise false.
#[doc(alias = "CFBinaryHeapGetMinimumIfPresent")]
#[inline]
pub unsafe fn minimum_if_present(self: &CFBinaryHeap, value: *mut *const c_void) -> bool {
extern "C-unwind" {
fn CFBinaryHeapGetMinimumIfPresent(
heap: &CFBinaryHeap,
value: *mut *const c_void,
) -> Boolean;
}
let ret = unsafe { CFBinaryHeapGetMinimumIfPresent(self, value) };
ret != 0
}
/// Fills the buffer with values from the binary heap.
///
/// Parameter `heap`: The binary heap to be queried. If this parameter is not a
/// valid CFBinaryHeap, the behavior is undefined.
///
/// Parameter `values`: A C array of pointer-sized values to be filled with
/// values from the binary heap. The values in the C array are ordered
/// from least to greatest. If this parameter is not a valid pointer to a
/// C array of at least CFBinaryHeapGetCount() pointers, the behavior is undefined.
#[doc(alias = "CFBinaryHeapGetValues")]
#[inline]
pub unsafe fn values(self: &CFBinaryHeap, values: *mut *const c_void) {
extern "C-unwind" {
fn CFBinaryHeapGetValues(heap: &CFBinaryHeap, values: *mut *const c_void);
}
unsafe { CFBinaryHeapGetValues(self, values) }
}
/// Calls a function once for each value in the binary heap.
///
/// Parameter `heap`: The binary heap to be operated upon. If this parameter is not a
/// valid CFBinaryHeap, the behavior is undefined.
///
/// Parameter `applier`: The callback function to call once for each value in
/// the given binary heap. If this parameter is not a
/// pointer to a function of the correct prototype, the behavior
/// is undefined. If there are values in the binary heap which the
/// applier function does not expect or cannot properly apply
/// to, the behavior is undefined.
///
/// Parameter `context`: A pointer-sized user-defined value, which is passed
/// as the second parameter to the applier function, but is
/// otherwise unused by this function. If the context is not
/// what is expected by the applier function, the behavior is
/// undefined.
#[doc(alias = "CFBinaryHeapApplyFunction")]
#[inline]
pub unsafe fn apply_function(
self: &CFBinaryHeap,
applier: CFBinaryHeapApplierFunction,
context: *mut c_void,
) {
extern "C-unwind" {
fn CFBinaryHeapApplyFunction(
heap: &CFBinaryHeap,
applier: CFBinaryHeapApplierFunction,
context: *mut c_void,
);
}
unsafe { CFBinaryHeapApplyFunction(self, applier, context) }
}
/// Adds the value to the binary heap.
///
/// Parameter `heap`: The binary heap to which the value is to be added. If this parameter is not a
/// valid mutable CFBinaryHeap, the behavior is undefined.
///
/// Parameter `value`: The value to add to the binary heap. The value is retained by
/// the binary heap using the retain callback provided when the binary heap
/// was created. If the value is not of the sort expected by the
/// retain callback, the behavior is undefined.
#[doc(alias = "CFBinaryHeapAddValue")]
#[inline]
pub unsafe fn add_value(self: &CFBinaryHeap, value: *const c_void) {
extern "C-unwind" {
fn CFBinaryHeapAddValue(heap: &CFBinaryHeap, value: *const c_void);
}
unsafe { CFBinaryHeapAddValue(self, value) }
}
/// Removes the minimum value from the binary heap.
///
/// Parameter `heap`: The binary heap from which the minimum value is to be removed. If this
/// parameter is not a valid mutable CFBinaryHeap, the behavior is undefined.
#[doc(alias = "CFBinaryHeapRemoveMinimumValue")]
#[inline]
pub unsafe fn remove_minimum_value(self: &CFBinaryHeap) {
extern "C-unwind" {
fn CFBinaryHeapRemoveMinimumValue(heap: &CFBinaryHeap);
}
unsafe { CFBinaryHeapRemoveMinimumValue(self) }
}
/// Removes all the values from the binary heap, making it empty.
///
/// Parameter `heap`: The binary heap from which all of the values are to be
/// removed. If this parameter is not a valid mutable CFBinaryHeap,
/// the behavior is undefined.
#[doc(alias = "CFBinaryHeapRemoveAllValues")]
#[inline]
pub unsafe fn remove_all_values(self: &CFBinaryHeap) {
extern "C-unwind" {
fn CFBinaryHeapRemoveAllValues(heap: &CFBinaryHeap);
}
unsafe { CFBinaryHeapRemoveAllValues(self) }
}
}
#[deprecated = "renamed to `CFBinaryHeap::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBinaryHeapCreate(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBinaryHeapCallBacks,
compare_context: *const CFBinaryHeapCompareContext,
) -> Option<CFRetained<CFBinaryHeap>> {
extern "C-unwind" {
fn CFBinaryHeapCreate(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFBinaryHeapCallBacks,
compare_context: *const CFBinaryHeapCompareContext,
) -> Option<NonNull<CFBinaryHeap>>;
}
let ret = unsafe { CFBinaryHeapCreate(allocator, capacity, call_backs, compare_context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFBinaryHeap::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBinaryHeapCreateCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
heap: Option<&CFBinaryHeap>,
) -> Option<CFRetained<CFBinaryHeap>> {
extern "C-unwind" {
fn CFBinaryHeapCreateCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
heap: Option<&CFBinaryHeap>,
) -> Option<NonNull<CFBinaryHeap>>;
}
let ret = unsafe { CFBinaryHeapCreateCopy(allocator, capacity, heap) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::count`"]
pub fn CFBinaryHeapGetCount(heap: &CFBinaryHeap) -> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::count_of_value`"]
pub fn CFBinaryHeapGetCountOfValue(heap: &CFBinaryHeap, value: *const c_void) -> CFIndex;
}
#[deprecated = "renamed to `CFBinaryHeap::contains_value`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBinaryHeapContainsValue(
heap: &CFBinaryHeap,
value: *const c_void,
) -> bool {
extern "C-unwind" {
fn CFBinaryHeapContainsValue(heap: &CFBinaryHeap, value: *const c_void) -> Boolean;
}
let ret = unsafe { CFBinaryHeapContainsValue(heap, value) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::minimum`"]
pub fn CFBinaryHeapGetMinimum(heap: &CFBinaryHeap) -> *const c_void;
}
#[deprecated = "renamed to `CFBinaryHeap::minimum_if_present`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBinaryHeapGetMinimumIfPresent(
heap: &CFBinaryHeap,
value: *mut *const c_void,
) -> bool {
extern "C-unwind" {
fn CFBinaryHeapGetMinimumIfPresent(
heap: &CFBinaryHeap,
value: *mut *const c_void,
) -> Boolean;
}
let ret = unsafe { CFBinaryHeapGetMinimumIfPresent(heap, value) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::values`"]
pub fn CFBinaryHeapGetValues(heap: &CFBinaryHeap, values: *mut *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::apply_function`"]
pub fn CFBinaryHeapApplyFunction(
heap: &CFBinaryHeap,
applier: CFBinaryHeapApplierFunction,
context: *mut c_void,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::add_value`"]
pub fn CFBinaryHeapAddValue(heap: &CFBinaryHeap, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::remove_minimum_value`"]
pub fn CFBinaryHeapRemoveMinimumValue(heap: &CFBinaryHeap);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBinaryHeap::remove_all_values`"]
pub fn CFBinaryHeapRemoveAllValues(heap: &CFBinaryHeap);
}

View File

@@ -0,0 +1,403 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbit?language=objc)
pub type CFBit = u32;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbitvector?language=objc)
#[repr(C)]
pub struct CFBitVector {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFBitVector {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFBitVector"> for CFBitVector {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutablebitvector?language=objc)
#[repr(C)]
pub struct CFMutableBitVector {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFMutableBitVector: CFBitVector {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFBitVector"> for CFMutableBitVector {}
);
unsafe impl ConcreteType for CFBitVector {
#[doc(alias = "CFBitVectorGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFBitVectorGetTypeID() -> CFTypeID;
}
unsafe { CFBitVectorGetTypeID() }
}
}
impl CFBitVector {
#[doc(alias = "CFBitVectorCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
bytes: *const u8,
num_bits: CFIndex,
) -> Option<CFRetained<CFBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreate(
allocator: Option<&CFAllocator>,
bytes: *const u8,
num_bits: CFIndex,
) -> Option<NonNull<CFBitVector>>;
}
let ret = unsafe { CFBitVectorCreate(allocator, bytes, num_bits) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFBitVectorCreateCopy")]
#[inline]
pub unsafe fn new_copy(
allocator: Option<&CFAllocator>,
bv: Option<&CFBitVector>,
) -> Option<CFRetained<CFBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreateCopy(
allocator: Option<&CFAllocator>,
bv: Option<&CFBitVector>,
) -> Option<NonNull<CFBitVector>>;
}
let ret = unsafe { CFBitVectorCreateCopy(allocator, bv) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFMutableBitVector {
#[doc(alias = "CFBitVectorCreateMutable")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<CFRetained<CFMutableBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<NonNull<CFMutableBitVector>>;
}
let ret = unsafe { CFBitVectorCreateMutable(allocator, capacity) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFBitVectorCreateMutableCopy")]
#[inline]
pub unsafe fn new_copy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
bv: Option<&CFBitVector>,
) -> Option<CFRetained<CFMutableBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
bv: Option<&CFBitVector>,
) -> Option<NonNull<CFMutableBitVector>>;
}
let ret = unsafe { CFBitVectorCreateMutableCopy(allocator, capacity, bv) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFBitVector {
#[doc(alias = "CFBitVectorGetCount")]
#[inline]
pub unsafe fn count(self: &CFBitVector) -> CFIndex {
extern "C-unwind" {
fn CFBitVectorGetCount(bv: &CFBitVector) -> CFIndex;
}
unsafe { CFBitVectorGetCount(self) }
}
#[doc(alias = "CFBitVectorGetCountOfBit")]
#[inline]
pub unsafe fn count_of_bit(self: &CFBitVector, range: CFRange, value: CFBit) -> CFIndex {
extern "C-unwind" {
fn CFBitVectorGetCountOfBit(bv: &CFBitVector, range: CFRange, value: CFBit) -> CFIndex;
}
unsafe { CFBitVectorGetCountOfBit(self, range, value) }
}
#[doc(alias = "CFBitVectorContainsBit")]
#[inline]
pub unsafe fn contains_bit(self: &CFBitVector, range: CFRange, value: CFBit) -> bool {
extern "C-unwind" {
fn CFBitVectorContainsBit(bv: &CFBitVector, range: CFRange, value: CFBit) -> Boolean;
}
let ret = unsafe { CFBitVectorContainsBit(self, range, value) };
ret != 0
}
#[doc(alias = "CFBitVectorGetBitAtIndex")]
#[inline]
pub unsafe fn bit_at_index(self: &CFBitVector, idx: CFIndex) -> CFBit {
extern "C-unwind" {
fn CFBitVectorGetBitAtIndex(bv: &CFBitVector, idx: CFIndex) -> CFBit;
}
unsafe { CFBitVectorGetBitAtIndex(self, idx) }
}
#[doc(alias = "CFBitVectorGetBits")]
#[inline]
pub unsafe fn bits(self: &CFBitVector, range: CFRange, bytes: *mut u8) {
extern "C-unwind" {
fn CFBitVectorGetBits(bv: &CFBitVector, range: CFRange, bytes: *mut u8);
}
unsafe { CFBitVectorGetBits(self, range, bytes) }
}
#[doc(alias = "CFBitVectorGetFirstIndexOfBit")]
#[inline]
pub unsafe fn first_index_of_bit(self: &CFBitVector, range: CFRange, value: CFBit) -> CFIndex {
extern "C-unwind" {
fn CFBitVectorGetFirstIndexOfBit(
bv: &CFBitVector,
range: CFRange,
value: CFBit,
) -> CFIndex;
}
unsafe { CFBitVectorGetFirstIndexOfBit(self, range, value) }
}
#[doc(alias = "CFBitVectorGetLastIndexOfBit")]
#[inline]
pub unsafe fn last_index_of_bit(self: &CFBitVector, range: CFRange, value: CFBit) -> CFIndex {
extern "C-unwind" {
fn CFBitVectorGetLastIndexOfBit(
bv: &CFBitVector,
range: CFRange,
value: CFBit,
) -> CFIndex;
}
unsafe { CFBitVectorGetLastIndexOfBit(self, range, value) }
}
}
impl CFMutableBitVector {
#[doc(alias = "CFBitVectorSetCount")]
#[inline]
pub unsafe fn set_count(bv: Option<&CFMutableBitVector>, count: CFIndex) {
extern "C-unwind" {
fn CFBitVectorSetCount(bv: Option<&CFMutableBitVector>, count: CFIndex);
}
unsafe { CFBitVectorSetCount(bv, count) }
}
#[doc(alias = "CFBitVectorFlipBitAtIndex")]
#[inline]
pub unsafe fn flip_bit_at_index(bv: Option<&CFMutableBitVector>, idx: CFIndex) {
extern "C-unwind" {
fn CFBitVectorFlipBitAtIndex(bv: Option<&CFMutableBitVector>, idx: CFIndex);
}
unsafe { CFBitVectorFlipBitAtIndex(bv, idx) }
}
#[doc(alias = "CFBitVectorFlipBits")]
#[inline]
pub unsafe fn flip_bits(bv: Option<&CFMutableBitVector>, range: CFRange) {
extern "C-unwind" {
fn CFBitVectorFlipBits(bv: Option<&CFMutableBitVector>, range: CFRange);
}
unsafe { CFBitVectorFlipBits(bv, range) }
}
#[doc(alias = "CFBitVectorSetBitAtIndex")]
#[inline]
pub unsafe fn set_bit_at_index(bv: Option<&CFMutableBitVector>, idx: CFIndex, value: CFBit) {
extern "C-unwind" {
fn CFBitVectorSetBitAtIndex(
bv: Option<&CFMutableBitVector>,
idx: CFIndex,
value: CFBit,
);
}
unsafe { CFBitVectorSetBitAtIndex(bv, idx, value) }
}
#[doc(alias = "CFBitVectorSetBits")]
#[inline]
pub unsafe fn set_bits(bv: Option<&CFMutableBitVector>, range: CFRange, value: CFBit) {
extern "C-unwind" {
fn CFBitVectorSetBits(bv: Option<&CFMutableBitVector>, range: CFRange, value: CFBit);
}
unsafe { CFBitVectorSetBits(bv, range, value) }
}
#[doc(alias = "CFBitVectorSetAllBits")]
#[inline]
pub unsafe fn set_all_bits(bv: Option<&CFMutableBitVector>, value: CFBit) {
extern "C-unwind" {
fn CFBitVectorSetAllBits(bv: Option<&CFMutableBitVector>, value: CFBit);
}
unsafe { CFBitVectorSetAllBits(bv, value) }
}
}
#[deprecated = "renamed to `CFBitVector::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBitVectorCreate(
allocator: Option<&CFAllocator>,
bytes: *const u8,
num_bits: CFIndex,
) -> Option<CFRetained<CFBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreate(
allocator: Option<&CFAllocator>,
bytes: *const u8,
num_bits: CFIndex,
) -> Option<NonNull<CFBitVector>>;
}
let ret = unsafe { CFBitVectorCreate(allocator, bytes, num_bits) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFBitVector::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBitVectorCreateCopy(
allocator: Option<&CFAllocator>,
bv: Option<&CFBitVector>,
) -> Option<CFRetained<CFBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreateCopy(
allocator: Option<&CFAllocator>,
bv: Option<&CFBitVector>,
) -> Option<NonNull<CFBitVector>>;
}
let ret = unsafe { CFBitVectorCreateCopy(allocator, bv) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableBitVector::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBitVectorCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<CFRetained<CFMutableBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<NonNull<CFMutableBitVector>>;
}
let ret = unsafe { CFBitVectorCreateMutable(allocator, capacity) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableBitVector::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBitVectorCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
bv: Option<&CFBitVector>,
) -> Option<CFRetained<CFMutableBitVector>> {
extern "C-unwind" {
fn CFBitVectorCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
bv: Option<&CFBitVector>,
) -> Option<NonNull<CFMutableBitVector>>;
}
let ret = unsafe { CFBitVectorCreateMutableCopy(allocator, capacity, bv) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBitVector::count`"]
pub fn CFBitVectorGetCount(bv: &CFBitVector) -> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBitVector::count_of_bit`"]
pub fn CFBitVectorGetCountOfBit(bv: &CFBitVector, range: CFRange, value: CFBit) -> CFIndex;
}
#[deprecated = "renamed to `CFBitVector::contains_bit`"]
#[inline]
pub unsafe extern "C-unwind" fn CFBitVectorContainsBit(
bv: &CFBitVector,
range: CFRange,
value: CFBit,
) -> bool {
extern "C-unwind" {
fn CFBitVectorContainsBit(bv: &CFBitVector, range: CFRange, value: CFBit) -> Boolean;
}
let ret = unsafe { CFBitVectorContainsBit(bv, range, value) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBitVector::bit_at_index`"]
pub fn CFBitVectorGetBitAtIndex(bv: &CFBitVector, idx: CFIndex) -> CFBit;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBitVector::bits`"]
pub fn CFBitVectorGetBits(bv: &CFBitVector, range: CFRange, bytes: *mut u8);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBitVector::first_index_of_bit`"]
pub fn CFBitVectorGetFirstIndexOfBit(bv: &CFBitVector, range: CFRange, value: CFBit)
-> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFBitVector::last_index_of_bit`"]
pub fn CFBitVectorGetLastIndexOfBit(bv: &CFBitVector, range: CFRange, value: CFBit) -> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBitVector::set_count`"]
pub fn CFBitVectorSetCount(bv: Option<&CFMutableBitVector>, count: CFIndex);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBitVector::flip_bit_at_index`"]
pub fn CFBitVectorFlipBitAtIndex(bv: Option<&CFMutableBitVector>, idx: CFIndex);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBitVector::flip_bits`"]
pub fn CFBitVectorFlipBits(bv: Option<&CFMutableBitVector>, range: CFRange);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBitVector::set_bit_at_index`"]
pub fn CFBitVectorSetBitAtIndex(bv: Option<&CFMutableBitVector>, idx: CFIndex, value: CFBit);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBitVector::set_bits`"]
pub fn CFBitVectorSetBits(bv: Option<&CFMutableBitVector>, range: CFRange, value: CFBit);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableBitVector::set_all_bits`"]
pub fn CFBitVectorSetAllBits(bv: Option<&CFMutableBitVector>, value: CFBit);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbyteorder?language=objc)
pub type CFByteOrder = CFIndex;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfswappedfloat32?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFSwappedFloat32 {
pub v: u32,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFSwappedFloat32 {
const ENCODING: Encoding = Encoding::Struct("?", &[<u32>::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFSwappedFloat32 {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfswappedfloat64?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFSwappedFloat64 {
pub v: u64,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFSwappedFloat64 {
const ENCODING: Encoding = Encoding::Struct("?", &[<u64>::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFSwappedFloat64 {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

View File

@@ -0,0 +1,110 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgvector?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CGVector {
pub dx: CGFloat,
pub dy: CGFloat,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CGVector {
const ENCODING: Encoding =
Encoding::Struct("CGVector", &[<CGFloat>::ENCODING, <CGFloat>::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGVector {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgrectedge?language=objc)
// NS_CLOSED_ENUM
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum CGRectEdge {
#[doc(alias = "CGRectMinXEdge")]
MinXEdge = 0,
#[doc(alias = "CGRectMinYEdge")]
MinYEdge = 1,
#[doc(alias = "CGRectMaxXEdge")]
MaxXEdge = 2,
#[doc(alias = "CGRectMaxYEdge")]
MaxYEdge = 3,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CGRectEdge {
const ENCODING: Encoding = u32::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGRectEdge {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgaffinetransform?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CGAffineTransform {
pub a: CGFloat,
pub b: CGFloat,
pub c: CGFloat,
pub d: CGFloat,
pub tx: CGFloat,
pub ty: CGFloat,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CGAffineTransform {
const ENCODING: Encoding = Encoding::Struct(
"CGAffineTransform",
&[
<CGFloat>::ENCODING,
<CGFloat>::ENCODING,
<CGFloat>::ENCODING,
<CGFloat>::ENCODING,
<CGFloat>::ENCODING,
<CGFloat>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGAffineTransform {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgaffinetransformcomponents?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CGAffineTransformComponents {
pub scale: CGSize,
pub horizontalShear: CGFloat,
pub rotation: CGFloat,
pub translation: CGVector,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CGAffineTransformComponents {
const ENCODING: Encoding = Encoding::Struct(
"CGAffineTransformComponents",
&[
<CGSize>::ENCODING,
<CGFloat>::ENCODING,
<CGFloat>::ENCODING,
<CGVector>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGAffineTransformComponents {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

View File

@@ -0,0 +1,506 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcalendar?language=objc)
#[repr(C)]
pub struct CFCalendar {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFCalendar {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFCalendar"> for CFCalendar {}
);
unsafe impl ConcreteType for CFCalendar {
#[doc(alias = "CFCalendarGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFCalendarGetTypeID() -> CFTypeID;
}
unsafe { CFCalendarGetTypeID() }
}
}
impl CFCalendar {
#[doc(alias = "CFCalendarCopyCurrent")]
#[inline]
pub fn current() -> Option<CFRetained<CFCalendar>> {
extern "C-unwind" {
fn CFCalendarCopyCurrent() -> Option<NonNull<CFCalendar>>;
}
let ret = unsafe { CFCalendarCopyCurrent() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a calendar. The identifiers are the `kCF*Calendar` constants in CFLocale.h.
#[doc(alias = "CFCalendarCreateWithIdentifier")]
#[cfg(feature = "CFLocale")]
#[inline]
pub fn with_identifier(
allocator: Option<&CFAllocator>,
identifier: Option<&CFCalendarIdentifier>,
) -> Option<CFRetained<CFCalendar>> {
extern "C-unwind" {
fn CFCalendarCreateWithIdentifier(
allocator: Option<&CFAllocator>,
identifier: Option<&CFCalendarIdentifier>,
) -> Option<NonNull<CFCalendar>>;
}
let ret = unsafe { CFCalendarCreateWithIdentifier(allocator, identifier) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns the calendar's identifier.
#[doc(alias = "CFCalendarGetIdentifier")]
#[cfg(feature = "CFLocale")]
#[inline]
pub fn identifier(self: &CFCalendar) -> Option<CFRetained<CFCalendarIdentifier>> {
extern "C-unwind" {
fn CFCalendarGetIdentifier(
calendar: &CFCalendar,
) -> Option<NonNull<CFCalendarIdentifier>>;
}
let ret = unsafe { CFCalendarGetIdentifier(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFCalendarCopyLocale")]
#[cfg(feature = "CFLocale")]
#[inline]
pub fn locale(self: &CFCalendar) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFCalendarCopyLocale(calendar: &CFCalendar) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFCalendarCopyLocale(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFCalendarSetLocale")]
#[cfg(feature = "CFLocale")]
#[inline]
pub unsafe fn set_locale(self: &CFCalendar, locale: Option<&CFLocale>) {
extern "C-unwind" {
fn CFCalendarSetLocale(calendar: &CFCalendar, locale: Option<&CFLocale>);
}
unsafe { CFCalendarSetLocale(self, locale) }
}
#[doc(alias = "CFCalendarCopyTimeZone")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn time_zone(self: &CFCalendar) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFCalendarCopyTimeZone(calendar: &CFCalendar) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFCalendarCopyTimeZone(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFCalendarSetTimeZone")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn set_time_zone(self: &CFCalendar, tz: Option<&CFTimeZone>) {
extern "C-unwind" {
fn CFCalendarSetTimeZone(calendar: &CFCalendar, tz: Option<&CFTimeZone>);
}
unsafe { CFCalendarSetTimeZone(self, tz) }
}
#[doc(alias = "CFCalendarGetFirstWeekday")]
#[inline]
pub fn first_weekday(self: &CFCalendar) -> CFIndex {
extern "C-unwind" {
fn CFCalendarGetFirstWeekday(calendar: &CFCalendar) -> CFIndex;
}
unsafe { CFCalendarGetFirstWeekday(self) }
}
#[doc(alias = "CFCalendarSetFirstWeekday")]
#[inline]
pub fn set_first_weekday(self: &CFCalendar, wkdy: CFIndex) {
extern "C-unwind" {
fn CFCalendarSetFirstWeekday(calendar: &CFCalendar, wkdy: CFIndex);
}
unsafe { CFCalendarSetFirstWeekday(self, wkdy) }
}
#[doc(alias = "CFCalendarGetMinimumDaysInFirstWeek")]
#[inline]
pub fn minimum_days_in_first_week(self: &CFCalendar) -> CFIndex {
extern "C-unwind" {
fn CFCalendarGetMinimumDaysInFirstWeek(calendar: &CFCalendar) -> CFIndex;
}
unsafe { CFCalendarGetMinimumDaysInFirstWeek(self) }
}
#[doc(alias = "CFCalendarSetMinimumDaysInFirstWeek")]
#[inline]
pub fn set_minimum_days_in_first_week(self: &CFCalendar, mwd: CFIndex) {
extern "C-unwind" {
fn CFCalendarSetMinimumDaysInFirstWeek(calendar: &CFCalendar, mwd: CFIndex);
}
unsafe { CFCalendarSetMinimumDaysInFirstWeek(self, mwd) }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcalendarunit?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFCalendarUnit(pub CFOptionFlags);
bitflags::bitflags! {
impl CFCalendarUnit: CFOptionFlags {
#[doc(alias = "kCFCalendarUnitEra")]
const Era = 1<<1;
#[doc(alias = "kCFCalendarUnitYear")]
const Year = 1<<2;
#[doc(alias = "kCFCalendarUnitMonth")]
const Month = 1<<3;
#[doc(alias = "kCFCalendarUnitDay")]
const Day = 1<<4;
#[doc(alias = "kCFCalendarUnitHour")]
const Hour = 1<<5;
#[doc(alias = "kCFCalendarUnitMinute")]
const Minute = 1<<6;
#[doc(alias = "kCFCalendarUnitSecond")]
const Second = 1<<7;
#[doc(alias = "kCFCalendarUnitWeek")]
#[deprecated = "Use kCFCalendarUnitWeekOfYear or kCFCalendarUnitWeekOfMonth instead"]
const Week = 1<<8;
#[doc(alias = "kCFCalendarUnitWeekday")]
const Weekday = 1<<9;
#[doc(alias = "kCFCalendarUnitWeekdayOrdinal")]
const WeekdayOrdinal = 1<<10;
#[doc(alias = "kCFCalendarUnitQuarter")]
const Quarter = 1<<11;
#[doc(alias = "kCFCalendarUnitWeekOfMonth")]
const WeekOfMonth = 1<<12;
#[doc(alias = "kCFCalendarUnitWeekOfYear")]
const WeekOfYear = 1<<13;
#[doc(alias = "kCFCalendarUnitYearForWeekOfYear")]
const YearForWeekOfYear = 1<<14;
#[doc(alias = "kCFCalendarUnitDayOfYear")]
const DayOfYear = 1<<16;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFCalendarUnit {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFCalendarUnit {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFCalendar {
#[doc(alias = "CFCalendarGetMinimumRangeOfUnit")]
#[inline]
pub fn minimum_range_of_unit(self: &CFCalendar, unit: CFCalendarUnit) -> CFRange {
extern "C-unwind" {
fn CFCalendarGetMinimumRangeOfUnit(
calendar: &CFCalendar,
unit: CFCalendarUnit,
) -> CFRange;
}
unsafe { CFCalendarGetMinimumRangeOfUnit(self, unit) }
}
#[doc(alias = "CFCalendarGetMaximumRangeOfUnit")]
#[inline]
pub fn maximum_range_of_unit(self: &CFCalendar, unit: CFCalendarUnit) -> CFRange {
extern "C-unwind" {
fn CFCalendarGetMaximumRangeOfUnit(
calendar: &CFCalendar,
unit: CFCalendarUnit,
) -> CFRange;
}
unsafe { CFCalendarGetMaximumRangeOfUnit(self, unit) }
}
#[doc(alias = "CFCalendarGetRangeOfUnit")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn range_of_unit(
self: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFRange {
extern "C-unwind" {
fn CFCalendarGetRangeOfUnit(
calendar: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFRange;
}
unsafe { CFCalendarGetRangeOfUnit(self, smaller_unit, bigger_unit, at) }
}
#[doc(alias = "CFCalendarGetOrdinalityOfUnit")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn ordinality_of_unit(
self: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFIndex {
extern "C-unwind" {
fn CFCalendarGetOrdinalityOfUnit(
calendar: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFIndex;
}
unsafe { CFCalendarGetOrdinalityOfUnit(self, smaller_unit, bigger_unit, at) }
}
#[doc(alias = "CFCalendarGetTimeRangeOfUnit")]
#[cfg(feature = "CFDate")]
#[inline]
pub unsafe fn time_range_of_unit(
self: &CFCalendar,
unit: CFCalendarUnit,
at: CFAbsoluteTime,
startp: *mut CFAbsoluteTime,
tip: *mut CFTimeInterval,
) -> bool {
extern "C-unwind" {
fn CFCalendarGetTimeRangeOfUnit(
calendar: &CFCalendar,
unit: CFCalendarUnit,
at: CFAbsoluteTime,
startp: *mut CFAbsoluteTime,
tip: *mut CFTimeInterval,
) -> Boolean;
}
let ret = unsafe { CFCalendarGetTimeRangeOfUnit(self, unit, at, startp, tip) };
ret != 0
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcalendarcomponentswrap?language=objc)
pub const kCFCalendarComponentsWrap: CFOptionFlags = 1 << 0;
#[deprecated = "renamed to `CFCalendar::current`"]
#[inline]
pub extern "C-unwind" fn CFCalendarCopyCurrent() -> Option<CFRetained<CFCalendar>> {
extern "C-unwind" {
fn CFCalendarCopyCurrent() -> Option<NonNull<CFCalendar>>;
}
let ret = unsafe { CFCalendarCopyCurrent() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFCalendar::with_identifier`"]
#[inline]
pub extern "C-unwind" fn CFCalendarCreateWithIdentifier(
allocator: Option<&CFAllocator>,
identifier: Option<&CFCalendarIdentifier>,
) -> Option<CFRetained<CFCalendar>> {
extern "C-unwind" {
fn CFCalendarCreateWithIdentifier(
allocator: Option<&CFAllocator>,
identifier: Option<&CFCalendarIdentifier>,
) -> Option<NonNull<CFCalendar>>;
}
let ret = unsafe { CFCalendarCreateWithIdentifier(allocator, identifier) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFCalendar::identifier`"]
#[inline]
pub extern "C-unwind" fn CFCalendarGetIdentifier(
calendar: &CFCalendar,
) -> Option<CFRetained<CFCalendarIdentifier>> {
extern "C-unwind" {
fn CFCalendarGetIdentifier(calendar: &CFCalendar) -> Option<NonNull<CFCalendarIdentifier>>;
}
let ret = unsafe { CFCalendarGetIdentifier(calendar) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFCalendar::locale`"]
#[inline]
pub extern "C-unwind" fn CFCalendarCopyLocale(
calendar: &CFCalendar,
) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFCalendarCopyLocale(calendar: &CFCalendar) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFCalendarCopyLocale(calendar) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFCalendar::set_locale`"]
pub fn CFCalendarSetLocale(calendar: &CFCalendar, locale: Option<&CFLocale>);
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFCalendar::time_zone`"]
#[inline]
pub extern "C-unwind" fn CFCalendarCopyTimeZone(
calendar: &CFCalendar,
) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFCalendarCopyTimeZone(calendar: &CFCalendar) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFCalendarCopyTimeZone(calendar) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFCalendar::set_time_zone`"]
#[inline]
pub extern "C-unwind" fn CFCalendarSetTimeZone(calendar: &CFCalendar, tz: Option<&CFTimeZone>) {
extern "C-unwind" {
fn CFCalendarSetTimeZone(calendar: &CFCalendar, tz: Option<&CFTimeZone>);
}
unsafe { CFCalendarSetTimeZone(calendar, tz) }
}
#[deprecated = "renamed to `CFCalendar::first_weekday`"]
#[inline]
pub extern "C-unwind" fn CFCalendarGetFirstWeekday(calendar: &CFCalendar) -> CFIndex {
extern "C-unwind" {
fn CFCalendarGetFirstWeekday(calendar: &CFCalendar) -> CFIndex;
}
unsafe { CFCalendarGetFirstWeekday(calendar) }
}
#[deprecated = "renamed to `CFCalendar::set_first_weekday`"]
#[inline]
pub extern "C-unwind" fn CFCalendarSetFirstWeekday(calendar: &CFCalendar, wkdy: CFIndex) {
extern "C-unwind" {
fn CFCalendarSetFirstWeekday(calendar: &CFCalendar, wkdy: CFIndex);
}
unsafe { CFCalendarSetFirstWeekday(calendar, wkdy) }
}
#[deprecated = "renamed to `CFCalendar::minimum_days_in_first_week`"]
#[inline]
pub extern "C-unwind" fn CFCalendarGetMinimumDaysInFirstWeek(calendar: &CFCalendar) -> CFIndex {
extern "C-unwind" {
fn CFCalendarGetMinimumDaysInFirstWeek(calendar: &CFCalendar) -> CFIndex;
}
unsafe { CFCalendarGetMinimumDaysInFirstWeek(calendar) }
}
#[deprecated = "renamed to `CFCalendar::set_minimum_days_in_first_week`"]
#[inline]
pub extern "C-unwind" fn CFCalendarSetMinimumDaysInFirstWeek(calendar: &CFCalendar, mwd: CFIndex) {
extern "C-unwind" {
fn CFCalendarSetMinimumDaysInFirstWeek(calendar: &CFCalendar, mwd: CFIndex);
}
unsafe { CFCalendarSetMinimumDaysInFirstWeek(calendar, mwd) }
}
#[deprecated = "renamed to `CFCalendar::minimum_range_of_unit`"]
#[inline]
pub extern "C-unwind" fn CFCalendarGetMinimumRangeOfUnit(
calendar: &CFCalendar,
unit: CFCalendarUnit,
) -> CFRange {
extern "C-unwind" {
fn CFCalendarGetMinimumRangeOfUnit(calendar: &CFCalendar, unit: CFCalendarUnit) -> CFRange;
}
unsafe { CFCalendarGetMinimumRangeOfUnit(calendar, unit) }
}
#[deprecated = "renamed to `CFCalendar::maximum_range_of_unit`"]
#[inline]
pub extern "C-unwind" fn CFCalendarGetMaximumRangeOfUnit(
calendar: &CFCalendar,
unit: CFCalendarUnit,
) -> CFRange {
extern "C-unwind" {
fn CFCalendarGetMaximumRangeOfUnit(calendar: &CFCalendar, unit: CFCalendarUnit) -> CFRange;
}
unsafe { CFCalendarGetMaximumRangeOfUnit(calendar, unit) }
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFCalendar::range_of_unit`"]
#[inline]
pub extern "C-unwind" fn CFCalendarGetRangeOfUnit(
calendar: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFRange {
extern "C-unwind" {
fn CFCalendarGetRangeOfUnit(
calendar: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFRange;
}
unsafe { CFCalendarGetRangeOfUnit(calendar, smaller_unit, bigger_unit, at) }
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFCalendar::ordinality_of_unit`"]
#[inline]
pub extern "C-unwind" fn CFCalendarGetOrdinalityOfUnit(
calendar: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFIndex {
extern "C-unwind" {
fn CFCalendarGetOrdinalityOfUnit(
calendar: &CFCalendar,
smaller_unit: CFCalendarUnit,
bigger_unit: CFCalendarUnit,
at: CFAbsoluteTime,
) -> CFIndex;
}
unsafe { CFCalendarGetOrdinalityOfUnit(calendar, smaller_unit, bigger_unit, at) }
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFCalendar::time_range_of_unit`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCalendarGetTimeRangeOfUnit(
calendar: &CFCalendar,
unit: CFCalendarUnit,
at: CFAbsoluteTime,
startp: *mut CFAbsoluteTime,
tip: *mut CFTimeInterval,
) -> bool {
extern "C-unwind" {
fn CFCalendarGetTimeRangeOfUnit(
calendar: &CFCalendar,
unit: CFCalendarUnit,
at: CFAbsoluteTime,
startp: *mut CFAbsoluteTime,
tip: *mut CFTimeInterval,
) -> Boolean;
}
let ret = unsafe { CFCalendarGetTimeRangeOfUnit(calendar, unit, at, startp, tip) };
ret != 0
}

View File

@@ -0,0 +1,893 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// This is the type of a reference to immutable CFCharacterSets.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcharacterset?language=objc)
#[repr(C)]
pub struct CFCharacterSet {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFCharacterSet {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFCharacterSet"> for CFCharacterSet {}
);
/// This is the type of a reference to mutable CFMutableCharacterSets.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutablecharacterset?language=objc)
#[repr(C)]
pub struct CFMutableCharacterSet {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFMutableCharacterSet: CFCharacterSet {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFCharacterSet"> for CFMutableCharacterSet {}
);
/// Type of the predefined CFCharacterSet selector values.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcharactersetpredefinedset?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFCharacterSetPredefinedSet(pub CFIndex);
impl CFCharacterSetPredefinedSet {
#[doc(alias = "kCFCharacterSetControl")]
pub const Control: Self = Self(1);
#[doc(alias = "kCFCharacterSetWhitespace")]
pub const Whitespace: Self = Self(2);
#[doc(alias = "kCFCharacterSetWhitespaceAndNewline")]
pub const WhitespaceAndNewline: Self = Self(3);
#[doc(alias = "kCFCharacterSetDecimalDigit")]
pub const DecimalDigit: Self = Self(4);
#[doc(alias = "kCFCharacterSetLetter")]
pub const Letter: Self = Self(5);
#[doc(alias = "kCFCharacterSetLowercaseLetter")]
pub const LowercaseLetter: Self = Self(6);
#[doc(alias = "kCFCharacterSetUppercaseLetter")]
pub const UppercaseLetter: Self = Self(7);
#[doc(alias = "kCFCharacterSetNonBase")]
pub const NonBase: Self = Self(8);
#[doc(alias = "kCFCharacterSetDecomposable")]
pub const Decomposable: Self = Self(9);
#[doc(alias = "kCFCharacterSetAlphaNumeric")]
pub const AlphaNumeric: Self = Self(10);
#[doc(alias = "kCFCharacterSetPunctuation")]
pub const Punctuation: Self = Self(11);
#[doc(alias = "kCFCharacterSetCapitalizedLetter")]
pub const CapitalizedLetter: Self = Self(13);
#[doc(alias = "kCFCharacterSetSymbol")]
pub const Symbol: Self = Self(14);
#[doc(alias = "kCFCharacterSetNewline")]
pub const Newline: Self = Self(15);
#[doc(alias = "kCFCharacterSetIllegal")]
pub const Illegal: Self = Self(12);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFCharacterSetPredefinedSet {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFCharacterSetPredefinedSet {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFCharacterSet {
/// Returns the type identifier of all CFCharacterSet instances.
#[doc(alias = "CFCharacterSetGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFCharacterSetGetTypeID() -> CFTypeID;
}
unsafe { CFCharacterSetGetTypeID() }
}
}
impl CFCharacterSet {
/// Returns a predefined CFCharacterSet instance.
///
/// Parameter `theSetIdentifier`: The CFCharacterSetPredefinedSet selector
/// which specifies the predefined character set. If the
/// value is not in CFCharacterSetPredefinedSet, the behavior
/// is undefined.
///
/// Returns: A reference to the predefined immutable CFCharacterSet.
/// This instance is owned by CF.
#[doc(alias = "CFCharacterSetGetPredefined")]
#[inline]
pub unsafe fn predefined(
the_set_identifier: CFCharacterSetPredefinedSet,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetGetPredefined(
the_set_identifier: CFCharacterSetPredefinedSet,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetGetPredefined(the_set_identifier) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Creates a new immutable character set with the values from the given range.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theRange`: The CFRange which should be used to specify the
/// Unicode range the character set is filled with. It
/// accepts the range in 32-bit in the UTF-32 format. The
/// valid character point range is from 0x00000 to 0x10FFFF.
/// If the range is outside of the valid Unicode character
/// point, the behavior is undefined.
///
/// Returns: A reference to the new immutable CFCharacterSet.
#[doc(alias = "CFCharacterSetCreateWithCharactersInRange")]
#[inline]
pub unsafe fn with_characters_in_range(
alloc: Option<&CFAllocator>,
the_range: CFRange,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateWithCharactersInRange(
alloc: Option<&CFAllocator>,
the_range: CFRange,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateWithCharactersInRange(alloc, the_range) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a new immutable character set with the values in the given string.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theString`: The CFString which should be used to specify
/// the Unicode characters the character set is filled with.
/// If this parameter is not a valid CFString, the behavior
/// is undefined.
///
/// Returns: A reference to the new immutable CFCharacterSet.
#[doc(alias = "CFCharacterSetCreateWithCharactersInString")]
#[inline]
pub unsafe fn with_characters_in_string(
alloc: Option<&CFAllocator>,
the_string: Option<&CFString>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateWithCharactersInString(
alloc: Option<&CFAllocator>,
the_string: Option<&CFString>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateWithCharactersInString(alloc, the_string) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a new immutable character set with the bitmap representtion in the given data.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theData`: The CFData which should be used to specify the
/// bitmap representation of the Unicode character points
/// the character set is filled with. The bitmap
/// representation could contain all the Unicode character
/// range starting from BMP to Plane 16. The first 8192 bytes
/// of the data represent the BMP range. The BMP range 8192
/// bytes can be followed by zero to sixteen 8192 byte
/// bitmaps, each one with the plane index byte prepended.
/// For example, the bitmap representing the BMP and Plane 2
/// has the size of 16385 bytes (8192 bytes for BMP, 1 byte
/// index + 8192 bytes bitmap for Plane 2). The plane index
/// byte, in this case, contains the integer value two. If
/// this parameter is not a valid CFData or it contains a
/// Plane index byte outside of the valid Plane range
/// (1 to 16), the behavior is undefined.
///
/// Returns: A reference to the new immutable CFCharacterSet.
#[doc(alias = "CFCharacterSetCreateWithBitmapRepresentation")]
#[cfg(feature = "CFData")]
#[inline]
pub unsafe fn with_bitmap_representation(
alloc: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateWithBitmapRepresentation(
alloc: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateWithBitmapRepresentation(alloc, the_data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a new immutable character set that is the invert of the specified character set.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theSet`: The CFCharacterSet which is to be inverted. If this
/// parameter is not a valid CFCharacterSet, the behavior is
/// undefined.
///
/// Returns: A reference to the new immutable CFCharacterSet.
#[doc(alias = "CFCharacterSetCreateInvertedSet")]
#[inline]
pub unsafe fn new_inverted_set(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateInvertedSet(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateInvertedSet(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Reports whether or not the character set is a superset of the character set specified as the second parameter.
///
/// Parameter `theSet`: The character set to be checked for the membership of theOtherSet.
/// If this parameter is not a valid CFCharacterSet, the behavior is undefined.
///
/// Parameter `theOtherset`: The character set to be checked whether or not it is a subset of theSet.
/// If this parameter is not a valid CFCharacterSet, the behavior is undefined.
#[doc(alias = "CFCharacterSetIsSupersetOfSet")]
#[inline]
pub unsafe fn is_superset_of_set(
self: &CFCharacterSet,
the_otherset: Option<&CFCharacterSet>,
) -> bool {
extern "C-unwind" {
fn CFCharacterSetIsSupersetOfSet(
the_set: &CFCharacterSet,
the_otherset: Option<&CFCharacterSet>,
) -> Boolean;
}
let ret = unsafe { CFCharacterSetIsSupersetOfSet(self, the_otherset) };
ret != 0
}
/// Reports whether or not the character set contains at least one member character in the specified plane.
///
/// Parameter `theSet`: The character set to be checked for the membership. If this
/// parameter is not a valid CFCharacterSet, the behavior is undefined.
///
/// Parameter `thePlane`: The plane number to be checked for the membership.
/// The valid value range is from 0 to 16. If the value is outside of the valid
/// plane number range, the behavior is undefined.
#[doc(alias = "CFCharacterSetHasMemberInPlane")]
#[inline]
pub unsafe fn has_member_in_plane(self: &CFCharacterSet, the_plane: CFIndex) -> bool {
extern "C-unwind" {
fn CFCharacterSetHasMemberInPlane(
the_set: &CFCharacterSet,
the_plane: CFIndex,
) -> Boolean;
}
let ret = unsafe { CFCharacterSetHasMemberInPlane(self, the_plane) };
ret != 0
}
}
impl CFMutableCharacterSet {
/// Creates a new empty mutable character set.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Returns: A reference to the new mutable CFCharacterSet.
#[doc(alias = "CFCharacterSetCreateMutable")]
#[inline]
pub unsafe fn new(alloc: Option<&CFAllocator>) -> Option<CFRetained<CFMutableCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateMutable(
alloc: Option<&CFAllocator>,
) -> Option<NonNull<CFMutableCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateMutable(alloc) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFCharacterSet {
/// Creates a new character set with the values from the given character set. This function tries to compact the backing store where applicable.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theSet`: The CFCharacterSet which is to be copied. If this
/// parameter is not a valid CFCharacterSet, the behavior is
/// undefined.
///
/// Returns: A reference to the new CFCharacterSet.
#[doc(alias = "CFCharacterSetCreateCopy")]
#[inline]
pub unsafe fn new_copy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateCopy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateCopy(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFMutableCharacterSet {
/// Creates a new mutable character set with the values from the given character set.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theSet`: The CFCharacterSet which is to be copied. If this
/// parameter is not a valid CFCharacterSet, the behavior is
/// undefined.
///
/// Returns: A reference to the new mutable CFCharacterSet.
#[doc(alias = "CFCharacterSetCreateMutableCopy")]
#[inline]
pub unsafe fn new_copy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFMutableCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateMutableCopy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFMutableCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateMutableCopy(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFCharacterSet {
/// Reports whether or not the Unicode character is in the character set.
///
/// Parameter `theSet`: The character set to be searched. If this parameter
/// is not a valid CFCharacterSet, the behavior is undefined.
///
/// Parameter `theChar`: The Unicode character for which to test against the
/// character set. Note that this function takes 16-bit Unicode
/// character value; hence, it does not support access to the
/// non-BMP planes.
///
/// Returns: true, if the value is in the character set, otherwise false.
#[doc(alias = "CFCharacterSetIsCharacterMember")]
#[inline]
pub unsafe fn is_character_member(self: &CFCharacterSet, the_char: UniChar) -> bool {
extern "C-unwind" {
fn CFCharacterSetIsCharacterMember(
the_set: &CFCharacterSet,
the_char: UniChar,
) -> Boolean;
}
let ret = unsafe { CFCharacterSetIsCharacterMember(self, the_char) };
ret != 0
}
/// Reports whether or not the UTF-32 character is in the character set.
///
/// Parameter `theSet`: The character set to be searched. If this parameter
/// is not a valid CFCharacterSet, the behavior is undefined.
///
/// Parameter `theChar`: The UTF-32 character for which to test against the
/// character set.
///
/// Returns: true, if the value is in the character set, otherwise false.
#[doc(alias = "CFCharacterSetIsLongCharacterMember")]
#[inline]
pub unsafe fn is_long_character_member(self: &CFCharacterSet, the_char: UTF32Char) -> bool {
extern "C-unwind" {
fn CFCharacterSetIsLongCharacterMember(
the_set: &CFCharacterSet,
the_char: UTF32Char,
) -> Boolean;
}
let ret = unsafe { CFCharacterSetIsLongCharacterMember(self, the_char) };
ret != 0
}
/// Creates a new immutable data with the bitmap representation from the given character set.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate
/// memory for the array and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theSet`: The CFCharacterSet which is to be used create the
/// bitmap representation from. Refer to the comments for
/// CFCharacterSetCreateWithBitmapRepresentation for the
/// detailed discussion of the bitmap representation format.
/// If this parameter is not a valid CFCharacterSet, the
/// behavior is undefined.
///
/// Returns: A reference to the new immutable CFData.
#[doc(alias = "CFCharacterSetCreateBitmapRepresentation")]
#[cfg(feature = "CFData")]
#[inline]
pub unsafe fn new_bitmap_representation(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFCharacterSetCreateBitmapRepresentation(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFCharacterSetCreateBitmapRepresentation(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFMutableCharacterSet {
/// Adds the given range to the charaacter set.
///
/// Parameter `theSet`: The character set to which the range is to be added.
/// If this parameter is not a valid mutable CFCharacterSet,
/// the behavior is undefined.
///
/// Parameter `theRange`: The range to add to the character set. It accepts
/// the range in 32-bit in the UTF-32 format. The valid
/// character point range is from 0x00000 to 0x10FFFF. If the
/// range is outside of the valid Unicode character point,
/// the behavior is undefined.
#[doc(alias = "CFCharacterSetAddCharactersInRange")]
#[inline]
pub unsafe fn add_characters_in_range(
the_set: Option<&CFMutableCharacterSet>,
the_range: CFRange,
) {
extern "C-unwind" {
fn CFCharacterSetAddCharactersInRange(
the_set: Option<&CFMutableCharacterSet>,
the_range: CFRange,
);
}
unsafe { CFCharacterSetAddCharactersInRange(the_set, the_range) }
}
/// Removes the given range from the charaacter set.
///
/// Parameter `theSet`: The character set from which the range is to be
/// removed. If this parameter is not a valid mutable
/// CFCharacterSet, the behavior is undefined.
///
/// Parameter `theRange`: The range to remove from the character set.
/// It accepts the range in 32-bit in the UTF-32 format.
/// The valid character point range is from 0x00000 to 0x10FFFF.
/// If the range is outside of the valid Unicode character point,
/// the behavior is undefined.
#[doc(alias = "CFCharacterSetRemoveCharactersInRange")]
#[inline]
pub unsafe fn remove_characters_in_range(
the_set: Option<&CFMutableCharacterSet>,
the_range: CFRange,
) {
extern "C-unwind" {
fn CFCharacterSetRemoveCharactersInRange(
the_set: Option<&CFMutableCharacterSet>,
the_range: CFRange,
);
}
unsafe { CFCharacterSetRemoveCharactersInRange(the_set, the_range) }
}
/// Adds the characters in the given string to the charaacter set.
///
/// Parameter `theSet`: The character set to which the characters in the
/// string are to be added. If this parameter is not a
/// valid mutable CFCharacterSet, the behavior is undefined.
///
/// Parameter `theString`: The string to add to the character set.
/// If this parameter is not a valid CFString, the behavior
/// is undefined.
#[doc(alias = "CFCharacterSetAddCharactersInString")]
#[inline]
pub unsafe fn add_characters_in_string(
the_set: Option<&CFMutableCharacterSet>,
the_string: Option<&CFString>,
) {
extern "C-unwind" {
fn CFCharacterSetAddCharactersInString(
the_set: Option<&CFMutableCharacterSet>,
the_string: Option<&CFString>,
);
}
unsafe { CFCharacterSetAddCharactersInString(the_set, the_string) }
}
/// Removes the characters in the given string from the charaacter set.
///
/// Parameter `theSet`: The character set from which the characters in the
/// string are to be remove. If this parameter is not a
/// valid mutable CFCharacterSet, the behavior is undefined.
///
/// Parameter `theString`: The string to remove from the character set.
/// If this parameter is not a valid CFString, the behavior
/// is undefined.
#[doc(alias = "CFCharacterSetRemoveCharactersInString")]
#[inline]
pub unsafe fn remove_characters_in_string(
the_set: Option<&CFMutableCharacterSet>,
the_string: Option<&CFString>,
) {
extern "C-unwind" {
fn CFCharacterSetRemoveCharactersInString(
the_set: Option<&CFMutableCharacterSet>,
the_string: Option<&CFString>,
);
}
unsafe { CFCharacterSetRemoveCharactersInString(the_set, the_string) }
}
/// Forms the union with the given character set.
///
/// Parameter `theSet`: The destination character set into which the
/// union of the two character sets is stored. If this
/// parameter is not a valid mutable CFCharacterSet, the
/// behavior is undefined.
///
/// Parameter `theOtherSet`: The character set with which the union is
/// formed. If this parameter is not a valid CFCharacterSet,
/// the behavior is undefined.
#[doc(alias = "CFCharacterSetUnion")]
#[inline]
pub unsafe fn union(
the_set: Option<&CFMutableCharacterSet>,
the_other_set: Option<&CFCharacterSet>,
) {
extern "C-unwind" {
fn CFCharacterSetUnion(
the_set: Option<&CFMutableCharacterSet>,
the_other_set: Option<&CFCharacterSet>,
);
}
unsafe { CFCharacterSetUnion(the_set, the_other_set) }
}
/// Forms the intersection with the given character set.
///
/// Parameter `theSet`: The destination character set into which the
/// intersection of the two character sets is stored.
/// If this parameter is not a valid mutable CFCharacterSet,
/// the behavior is undefined.
///
/// Parameter `theOtherSet`: The character set with which the intersection
/// is formed. If this parameter is not a valid CFCharacterSet,
/// the behavior is undefined.
#[doc(alias = "CFCharacterSetIntersect")]
#[inline]
pub unsafe fn intersect(
the_set: Option<&CFMutableCharacterSet>,
the_other_set: Option<&CFCharacterSet>,
) {
extern "C-unwind" {
fn CFCharacterSetIntersect(
the_set: Option<&CFMutableCharacterSet>,
the_other_set: Option<&CFCharacterSet>,
);
}
unsafe { CFCharacterSetIntersect(the_set, the_other_set) }
}
/// Inverts the content of the given character set.
///
/// Parameter `theSet`: The character set to be inverted.
/// If this parameter is not a valid mutable CFCharacterSet,
/// the behavior is undefined.
#[doc(alias = "CFCharacterSetInvert")]
#[inline]
pub unsafe fn invert(the_set: Option<&CFMutableCharacterSet>) {
extern "C-unwind" {
fn CFCharacterSetInvert(the_set: Option<&CFMutableCharacterSet>);
}
unsafe { CFCharacterSetInvert(the_set) }
}
}
#[deprecated = "renamed to `CFCharacterSet::predefined`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetGetPredefined(
the_set_identifier: CFCharacterSetPredefinedSet,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetGetPredefined(
the_set_identifier: CFCharacterSetPredefinedSet,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetGetPredefined(the_set_identifier) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFCharacterSet::with_characters_in_range`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateWithCharactersInRange(
alloc: Option<&CFAllocator>,
the_range: CFRange,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateWithCharactersInRange(
alloc: Option<&CFAllocator>,
the_range: CFRange,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateWithCharactersInRange(alloc, the_range) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFCharacterSet::with_characters_in_string`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateWithCharactersInString(
alloc: Option<&CFAllocator>,
the_string: Option<&CFString>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateWithCharactersInString(
alloc: Option<&CFAllocator>,
the_string: Option<&CFString>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateWithCharactersInString(alloc, the_string) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFCharacterSet::with_bitmap_representation`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateWithBitmapRepresentation(
alloc: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateWithBitmapRepresentation(
alloc: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateWithBitmapRepresentation(alloc, the_data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFCharacterSet::new_inverted_set`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateInvertedSet(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateInvertedSet(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateInvertedSet(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFCharacterSet::is_superset_of_set`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetIsSupersetOfSet(
the_set: &CFCharacterSet,
the_otherset: Option<&CFCharacterSet>,
) -> bool {
extern "C-unwind" {
fn CFCharacterSetIsSupersetOfSet(
the_set: &CFCharacterSet,
the_otherset: Option<&CFCharacterSet>,
) -> Boolean;
}
let ret = unsafe { CFCharacterSetIsSupersetOfSet(the_set, the_otherset) };
ret != 0
}
#[deprecated = "renamed to `CFCharacterSet::has_member_in_plane`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetHasMemberInPlane(
the_set: &CFCharacterSet,
the_plane: CFIndex,
) -> bool {
extern "C-unwind" {
fn CFCharacterSetHasMemberInPlane(the_set: &CFCharacterSet, the_plane: CFIndex) -> Boolean;
}
let ret = unsafe { CFCharacterSetHasMemberInPlane(the_set, the_plane) };
ret != 0
}
#[deprecated = "renamed to `CFMutableCharacterSet::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateMutable(
alloc: Option<&CFAllocator>,
) -> Option<CFRetained<CFMutableCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateMutable(
alloc: Option<&CFAllocator>,
) -> Option<NonNull<CFMutableCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateMutable(alloc) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFCharacterSet::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateCopy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateCopy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateCopy(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableCharacterSet::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateMutableCopy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFMutableCharacterSet>> {
extern "C-unwind" {
fn CFCharacterSetCreateMutableCopy(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFMutableCharacterSet>>;
}
let ret = unsafe { CFCharacterSetCreateMutableCopy(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFCharacterSet::is_character_member`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetIsCharacterMember(
the_set: &CFCharacterSet,
the_char: UniChar,
) -> bool {
extern "C-unwind" {
fn CFCharacterSetIsCharacterMember(the_set: &CFCharacterSet, the_char: UniChar) -> Boolean;
}
let ret = unsafe { CFCharacterSetIsCharacterMember(the_set, the_char) };
ret != 0
}
#[deprecated = "renamed to `CFCharacterSet::is_long_character_member`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetIsLongCharacterMember(
the_set: &CFCharacterSet,
the_char: UTF32Char,
) -> bool {
extern "C-unwind" {
fn CFCharacterSetIsLongCharacterMember(
the_set: &CFCharacterSet,
the_char: UTF32Char,
) -> Boolean;
}
let ret = unsafe { CFCharacterSetIsLongCharacterMember(the_set, the_char) };
ret != 0
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFCharacterSet::new_bitmap_representation`"]
#[inline]
pub unsafe extern "C-unwind" fn CFCharacterSetCreateBitmapRepresentation(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFCharacterSetCreateBitmapRepresentation(
alloc: Option<&CFAllocator>,
the_set: Option<&CFCharacterSet>,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFCharacterSetCreateBitmapRepresentation(alloc, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableCharacterSet::add_characters_in_range`"]
pub fn CFCharacterSetAddCharactersInRange(
the_set: Option<&CFMutableCharacterSet>,
the_range: CFRange,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableCharacterSet::remove_characters_in_range`"]
pub fn CFCharacterSetRemoveCharactersInRange(
the_set: Option<&CFMutableCharacterSet>,
the_range: CFRange,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableCharacterSet::add_characters_in_string`"]
pub fn CFCharacterSetAddCharactersInString(
the_set: Option<&CFMutableCharacterSet>,
the_string: Option<&CFString>,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableCharacterSet::remove_characters_in_string`"]
pub fn CFCharacterSetRemoveCharactersInString(
the_set: Option<&CFMutableCharacterSet>,
the_string: Option<&CFString>,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableCharacterSet::union`"]
pub fn CFCharacterSetUnion(
the_set: Option<&CFMutableCharacterSet>,
the_other_set: Option<&CFCharacterSet>,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableCharacterSet::intersect`"]
pub fn CFCharacterSetIntersect(
the_set: Option<&CFMutableCharacterSet>,
the_other_set: Option<&CFCharacterSet>,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableCharacterSet::invert`"]
pub fn CFCharacterSetInvert(the_set: Option<&CFMutableCharacterSet>);
}

View File

@@ -0,0 +1,471 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdata?language=objc)
#[repr(C)]
pub struct CFData {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFData {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFData"> for CFData {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutabledata?language=objc)
#[repr(C)]
pub struct CFMutableData {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFMutableData: CFData {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFData"> for CFMutableData {}
);
unsafe impl ConcreteType for CFData {
#[doc(alias = "CFDataGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFDataGetTypeID() -> CFTypeID;
}
unsafe { CFDataGetTypeID() }
}
}
impl CFData {
#[doc(alias = "CFDataCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFDataCreate(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFDataCreate(allocator, bytes, length) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDataCreateWithBytesNoCopy")]
#[inline]
pub unsafe fn with_bytes_no_copy(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
bytes_deallocator: Option<&CFAllocator>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFDataCreateWithBytesNoCopy(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
bytes_deallocator: Option<&CFAllocator>,
) -> Option<NonNull<CFData>>;
}
let ret =
unsafe { CFDataCreateWithBytesNoCopy(allocator, bytes, length, bytes_deallocator) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDataCreateCopy")]
#[inline]
pub fn new_copy(
allocator: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFDataCreateCopy(
allocator: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFDataCreateCopy(allocator, the_data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFMutableData {
#[doc(alias = "CFDataCreateMutable")]
#[inline]
pub fn new(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<CFRetained<CFMutableData>> {
extern "C-unwind" {
fn CFDataCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<NonNull<CFMutableData>>;
}
let ret = unsafe { CFDataCreateMutable(allocator, capacity) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDataCreateMutableCopy")]
#[inline]
pub unsafe fn new_copy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_data: Option<&CFData>,
) -> Option<CFRetained<CFMutableData>> {
extern "C-unwind" {
fn CFDataCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_data: Option<&CFData>,
) -> Option<NonNull<CFMutableData>>;
}
let ret = unsafe { CFDataCreateMutableCopy(allocator, capacity, the_data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFData {
#[doc(alias = "CFDataGetLength")]
#[inline]
pub fn length(self: &CFData) -> CFIndex {
extern "C-unwind" {
fn CFDataGetLength(the_data: &CFData) -> CFIndex;
}
unsafe { CFDataGetLength(self) }
}
#[doc(alias = "CFDataGetBytePtr")]
#[inline]
pub fn byte_ptr(self: &CFData) -> *const u8 {
extern "C-unwind" {
fn CFDataGetBytePtr(the_data: &CFData) -> *const u8;
}
unsafe { CFDataGetBytePtr(self) }
}
}
impl CFMutableData {
#[doc(alias = "CFDataGetMutableBytePtr")]
#[inline]
pub fn mutable_byte_ptr(the_data: Option<&CFMutableData>) -> *mut u8 {
extern "C-unwind" {
fn CFDataGetMutableBytePtr(the_data: Option<&CFMutableData>) -> *mut u8;
}
unsafe { CFDataGetMutableBytePtr(the_data) }
}
}
impl CFData {
#[doc(alias = "CFDataGetBytes")]
#[inline]
pub unsafe fn bytes(self: &CFData, range: CFRange, buffer: *mut u8) {
extern "C-unwind" {
fn CFDataGetBytes(the_data: &CFData, range: CFRange, buffer: *mut u8);
}
unsafe { CFDataGetBytes(self, range, buffer) }
}
}
impl CFMutableData {
#[doc(alias = "CFDataSetLength")]
#[inline]
pub fn set_length(the_data: Option<&CFMutableData>, length: CFIndex) {
extern "C-unwind" {
fn CFDataSetLength(the_data: Option<&CFMutableData>, length: CFIndex);
}
unsafe { CFDataSetLength(the_data, length) }
}
#[doc(alias = "CFDataIncreaseLength")]
#[inline]
pub fn increase_length(the_data: Option<&CFMutableData>, extra_length: CFIndex) {
extern "C-unwind" {
fn CFDataIncreaseLength(the_data: Option<&CFMutableData>, extra_length: CFIndex);
}
unsafe { CFDataIncreaseLength(the_data, extra_length) }
}
#[doc(alias = "CFDataAppendBytes")]
#[inline]
pub unsafe fn append_bytes(
the_data: Option<&CFMutableData>,
bytes: *const u8,
length: CFIndex,
) {
extern "C-unwind" {
fn CFDataAppendBytes(
the_data: Option<&CFMutableData>,
bytes: *const u8,
length: CFIndex,
);
}
unsafe { CFDataAppendBytes(the_data, bytes, length) }
}
#[doc(alias = "CFDataReplaceBytes")]
#[inline]
pub unsafe fn replace_bytes(
the_data: Option<&CFMutableData>,
range: CFRange,
new_bytes: *const u8,
new_length: CFIndex,
) {
extern "C-unwind" {
fn CFDataReplaceBytes(
the_data: Option<&CFMutableData>,
range: CFRange,
new_bytes: *const u8,
new_length: CFIndex,
);
}
unsafe { CFDataReplaceBytes(the_data, range, new_bytes, new_length) }
}
#[doc(alias = "CFDataDeleteBytes")]
#[inline]
pub fn delete_bytes(the_data: Option<&CFMutableData>, range: CFRange) {
extern "C-unwind" {
fn CFDataDeleteBytes(the_data: Option<&CFMutableData>, range: CFRange);
}
unsafe { CFDataDeleteBytes(the_data, range) }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdatasearchflags?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFDataSearchFlags(pub CFOptionFlags);
bitflags::bitflags! {
impl CFDataSearchFlags: CFOptionFlags {
#[doc(alias = "kCFDataSearchBackwards")]
const Backwards = 1<<0;
#[doc(alias = "kCFDataSearchAnchored")]
const Anchored = 1<<1;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFDataSearchFlags {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFDataSearchFlags {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFData {
#[doc(alias = "CFDataFind")]
#[inline]
pub unsafe fn find(
self: &CFData,
data_to_find: Option<&CFData>,
search_range: CFRange,
compare_options: CFDataSearchFlags,
) -> CFRange {
extern "C-unwind" {
fn CFDataFind(
the_data: &CFData,
data_to_find: Option<&CFData>,
search_range: CFRange,
compare_options: CFDataSearchFlags,
) -> CFRange;
}
unsafe { CFDataFind(self, data_to_find, search_range, compare_options) }
}
}
#[deprecated = "renamed to `CFData::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDataCreate(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFDataCreate(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFDataCreate(allocator, bytes, length) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFData::with_bytes_no_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDataCreateWithBytesNoCopy(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
bytes_deallocator: Option<&CFAllocator>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFDataCreateWithBytesNoCopy(
allocator: Option<&CFAllocator>,
bytes: *const u8,
length: CFIndex,
bytes_deallocator: Option<&CFAllocator>,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFDataCreateWithBytesNoCopy(allocator, bytes, length, bytes_deallocator) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFData::new_copy`"]
#[inline]
pub extern "C-unwind" fn CFDataCreateCopy(
allocator: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFDataCreateCopy(
allocator: Option<&CFAllocator>,
the_data: Option<&CFData>,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFDataCreateCopy(allocator, the_data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableData::new`"]
#[inline]
pub extern "C-unwind" fn CFDataCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<CFRetained<CFMutableData>> {
extern "C-unwind" {
fn CFDataCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
) -> Option<NonNull<CFMutableData>>;
}
let ret = unsafe { CFDataCreateMutable(allocator, capacity) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableData::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDataCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_data: Option<&CFData>,
) -> Option<CFRetained<CFMutableData>> {
extern "C-unwind" {
fn CFDataCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_data: Option<&CFData>,
) -> Option<NonNull<CFMutableData>>;
}
let ret = unsafe { CFDataCreateMutableCopy(allocator, capacity, the_data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFData::length`"]
#[inline]
pub extern "C-unwind" fn CFDataGetLength(the_data: &CFData) -> CFIndex {
extern "C-unwind" {
fn CFDataGetLength(the_data: &CFData) -> CFIndex;
}
unsafe { CFDataGetLength(the_data) }
}
#[deprecated = "renamed to `CFData::byte_ptr`"]
#[inline]
pub extern "C-unwind" fn CFDataGetBytePtr(the_data: &CFData) -> *const u8 {
extern "C-unwind" {
fn CFDataGetBytePtr(the_data: &CFData) -> *const u8;
}
unsafe { CFDataGetBytePtr(the_data) }
}
#[deprecated = "renamed to `CFMutableData::mutable_byte_ptr`"]
#[inline]
pub extern "C-unwind" fn CFDataGetMutableBytePtr(the_data: Option<&CFMutableData>) -> *mut u8 {
extern "C-unwind" {
fn CFDataGetMutableBytePtr(the_data: Option<&CFMutableData>) -> *mut u8;
}
unsafe { CFDataGetMutableBytePtr(the_data) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFData::bytes`"]
pub fn CFDataGetBytes(the_data: &CFData, range: CFRange, buffer: *mut u8);
}
#[deprecated = "renamed to `CFMutableData::set_length`"]
#[inline]
pub extern "C-unwind" fn CFDataSetLength(the_data: Option<&CFMutableData>, length: CFIndex) {
extern "C-unwind" {
fn CFDataSetLength(the_data: Option<&CFMutableData>, length: CFIndex);
}
unsafe { CFDataSetLength(the_data, length) }
}
#[deprecated = "renamed to `CFMutableData::increase_length`"]
#[inline]
pub extern "C-unwind" fn CFDataIncreaseLength(
the_data: Option<&CFMutableData>,
extra_length: CFIndex,
) {
extern "C-unwind" {
fn CFDataIncreaseLength(the_data: Option<&CFMutableData>, extra_length: CFIndex);
}
unsafe { CFDataIncreaseLength(the_data, extra_length) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableData::append_bytes`"]
pub fn CFDataAppendBytes(the_data: Option<&CFMutableData>, bytes: *const u8, length: CFIndex);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableData::replace_bytes`"]
pub fn CFDataReplaceBytes(
the_data: Option<&CFMutableData>,
range: CFRange,
new_bytes: *const u8,
new_length: CFIndex,
);
}
#[deprecated = "renamed to `CFMutableData::delete_bytes`"]
#[inline]
pub extern "C-unwind" fn CFDataDeleteBytes(the_data: Option<&CFMutableData>, range: CFRange) {
extern "C-unwind" {
fn CFDataDeleteBytes(the_data: Option<&CFMutableData>, range: CFRange);
}
unsafe { CFDataDeleteBytes(the_data, range) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFData::find`"]
pub fn CFDataFind(
the_data: &CFData,
data_to_find: Option<&CFData>,
search_range: CFRange,
compare_options: CFDataSearchFlags,
) -> CFRange;
}

View File

@@ -0,0 +1,372 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftimeinterval?language=objc)
pub type CFTimeInterval = c_double;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfabsolutetime?language=objc)
pub type CFAbsoluteTime = CFTimeInterval;
#[inline]
pub extern "C-unwind" fn CFAbsoluteTimeGetCurrent() -> CFAbsoluteTime {
extern "C-unwind" {
fn CFAbsoluteTimeGetCurrent() -> CFAbsoluteTime;
}
unsafe { CFAbsoluteTimeGetCurrent() }
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfabsolutetimeintervalsince1970?language=objc)
pub static kCFAbsoluteTimeIntervalSince1970: CFTimeInterval;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfabsolutetimeintervalsince1904?language=objc)
pub static kCFAbsoluteTimeIntervalSince1904: CFTimeInterval;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdate?language=objc)
#[repr(C)]
pub struct CFDate {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFDate {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFDate"> for CFDate {}
);
unsafe impl ConcreteType for CFDate {
#[doc(alias = "CFDateGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFDateGetTypeID() -> CFTypeID;
}
unsafe { CFDateGetTypeID() }
}
}
impl CFDate {
#[doc(alias = "CFDateCreate")]
#[inline]
pub fn new(allocator: Option<&CFAllocator>, at: CFAbsoluteTime) -> Option<CFRetained<CFDate>> {
extern "C-unwind" {
fn CFDateCreate(
allocator: Option<&CFAllocator>,
at: CFAbsoluteTime,
) -> Option<NonNull<CFDate>>;
}
let ret = unsafe { CFDateCreate(allocator, at) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDateGetAbsoluteTime")]
#[inline]
pub fn absolute_time(self: &CFDate) -> CFAbsoluteTime {
extern "C-unwind" {
fn CFDateGetAbsoluteTime(the_date: &CFDate) -> CFAbsoluteTime;
}
unsafe { CFDateGetAbsoluteTime(self) }
}
#[doc(alias = "CFDateGetTimeIntervalSinceDate")]
#[inline]
pub fn time_interval_since_date(self: &CFDate, other_date: Option<&CFDate>) -> CFTimeInterval {
extern "C-unwind" {
fn CFDateGetTimeIntervalSinceDate(
the_date: &CFDate,
other_date: Option<&CFDate>,
) -> CFTimeInterval;
}
unsafe { CFDateGetTimeIntervalSinceDate(self, other_date) }
}
#[doc(alias = "CFDateCompare")]
#[inline]
pub unsafe fn compare(
self: &CFDate,
other_date: Option<&CFDate>,
context: *mut c_void,
) -> CFComparisonResult {
extern "C-unwind" {
fn CFDateCompare(
the_date: &CFDate,
other_date: Option<&CFDate>,
context: *mut c_void,
) -> CFComparisonResult;
}
unsafe { CFDateCompare(self, other_date, context) }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftimezone?language=objc)
#[repr(C)]
pub struct CFTimeZone {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFTimeZone {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFTimeZone"> for CFTimeZone {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfgregoriandate?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFGregorianDate {
pub year: i32,
pub month: i8,
pub day: i8,
pub hour: i8,
pub minute: i8,
pub second: c_double,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFGregorianDate {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<i32>::ENCODING,
<i8>::ENCODING,
<i8>::ENCODING,
<i8>::ENCODING,
<i8>::ENCODING,
<c_double>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFGregorianDate {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfgregorianunits?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFGregorianUnits {
pub years: i32,
pub months: i32,
pub days: i32,
pub hours: i32,
pub minutes: i32,
pub seconds: c_double,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFGregorianUnits {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<i32>::ENCODING,
<i32>::ENCODING,
<i32>::ENCODING,
<i32>::ENCODING,
<i32>::ENCODING,
<c_double>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFGregorianUnits {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfgregorianunitflags?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFGregorianUnitFlags(pub CFOptionFlags);
bitflags::bitflags! {
impl CFGregorianUnitFlags: CFOptionFlags {
#[doc(alias = "kCFGregorianUnitsYears")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
const UnitsYears = 1<<0;
#[doc(alias = "kCFGregorianUnitsMonths")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
const UnitsMonths = 1<<1;
#[doc(alias = "kCFGregorianUnitsDays")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
const UnitsDays = 1<<2;
#[doc(alias = "kCFGregorianUnitsHours")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
const UnitsHours = 1<<3;
#[doc(alias = "kCFGregorianUnitsMinutes")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
const UnitsMinutes = 1<<4;
#[doc(alias = "kCFGregorianUnitsSeconds")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
const UnitsSeconds = 1<<5;
#[doc(alias = "kCFGregorianAllUnits")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
const AllUnits = 0x00FFFFFF;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFGregorianUnitFlags {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFGregorianUnitFlags {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFGregorianDate {
#[doc(alias = "CFGregorianDateIsValid")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
#[inline]
pub unsafe fn is_valid(self: CFGregorianDate, unit_flags: CFOptionFlags) -> bool {
extern "C-unwind" {
fn CFGregorianDateIsValid(gdate: CFGregorianDate, unit_flags: CFOptionFlags)
-> Boolean;
}
let ret = unsafe { CFGregorianDateIsValid(self, unit_flags) };
ret != 0
}
#[doc(alias = "CFGregorianDateGetAbsoluteTime")]
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
#[inline]
pub unsafe fn absolute_time(self: CFGregorianDate, tz: Option<&CFTimeZone>) -> CFAbsoluteTime {
extern "C-unwind" {
fn CFGregorianDateGetAbsoluteTime(
gdate: CFGregorianDate,
tz: Option<&CFTimeZone>,
) -> CFAbsoluteTime;
}
unsafe { CFGregorianDateGetAbsoluteTime(self, tz) }
}
}
extern "C-unwind" {
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
pub fn CFAbsoluteTimeGetGregorianDate(
at: CFAbsoluteTime,
tz: Option<&CFTimeZone>,
) -> CFGregorianDate;
}
extern "C-unwind" {
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
pub fn CFAbsoluteTimeAddGregorianUnits(
at: CFAbsoluteTime,
tz: Option<&CFTimeZone>,
units: CFGregorianUnits,
) -> CFAbsoluteTime;
}
extern "C-unwind" {
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
pub fn CFAbsoluteTimeGetDifferenceAsGregorianUnits(
at1: CFAbsoluteTime,
at2: CFAbsoluteTime,
tz: Option<&CFTimeZone>,
unit_flags: CFOptionFlags,
) -> CFGregorianUnits;
}
extern "C-unwind" {
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
pub fn CFAbsoluteTimeGetDayOfWeek(at: CFAbsoluteTime, tz: Option<&CFTimeZone>) -> i32;
}
extern "C-unwind" {
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
pub fn CFAbsoluteTimeGetDayOfYear(at: CFAbsoluteTime, tz: Option<&CFTimeZone>) -> i32;
}
extern "C-unwind" {
#[deprecated = "Use CFCalendar or NSCalendar API instead"]
pub fn CFAbsoluteTimeGetWeekOfYear(at: CFAbsoluteTime, tz: Option<&CFTimeZone>) -> i32;
}
#[deprecated = "renamed to `CFDate::new`"]
#[inline]
pub extern "C-unwind" fn CFDateCreate(
allocator: Option<&CFAllocator>,
at: CFAbsoluteTime,
) -> Option<CFRetained<CFDate>> {
extern "C-unwind" {
fn CFDateCreate(
allocator: Option<&CFAllocator>,
at: CFAbsoluteTime,
) -> Option<NonNull<CFDate>>;
}
let ret = unsafe { CFDateCreate(allocator, at) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFDate::absolute_time`"]
#[inline]
pub extern "C-unwind" fn CFDateGetAbsoluteTime(the_date: &CFDate) -> CFAbsoluteTime {
extern "C-unwind" {
fn CFDateGetAbsoluteTime(the_date: &CFDate) -> CFAbsoluteTime;
}
unsafe { CFDateGetAbsoluteTime(the_date) }
}
#[deprecated = "renamed to `CFDate::time_interval_since_date`"]
#[inline]
pub extern "C-unwind" fn CFDateGetTimeIntervalSinceDate(
the_date: &CFDate,
other_date: Option<&CFDate>,
) -> CFTimeInterval {
extern "C-unwind" {
fn CFDateGetTimeIntervalSinceDate(
the_date: &CFDate,
other_date: Option<&CFDate>,
) -> CFTimeInterval;
}
unsafe { CFDateGetTimeIntervalSinceDate(the_date, other_date) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFDate::compare`"]
pub fn CFDateCompare(
the_date: &CFDate,
other_date: Option<&CFDate>,
context: *mut c_void,
) -> CFComparisonResult;
}
#[deprecated = "renamed to `CFGregorianDate::is_valid`"]
#[inline]
pub unsafe extern "C-unwind" fn CFGregorianDateIsValid(
gdate: CFGregorianDate,
unit_flags: CFOptionFlags,
) -> bool {
extern "C-unwind" {
fn CFGregorianDateIsValid(gdate: CFGregorianDate, unit_flags: CFOptionFlags) -> Boolean;
}
let ret = unsafe { CFGregorianDateIsValid(gdate, unit_flags) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFGregorianDate::absolute_time`"]
pub fn CFGregorianDateGetAbsoluteTime(
gdate: CFGregorianDate,
tz: Option<&CFTimeZone>,
) -> CFAbsoluteTime;
}

View File

@@ -0,0 +1,695 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdateformatterkey?language=objc)
// NS_TYPED_ENUM
pub type CFDateFormatterKey = CFString;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdateformatter?language=objc)
#[repr(C)]
pub struct CFDateFormatter {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFDateFormatter {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFDateFormatter"> for CFDateFormatter {}
);
impl CFDateFormatter {
#[doc(alias = "CFDateFormatterCreateDateFormatFromTemplate")]
#[cfg(feature = "CFLocale")]
#[inline]
pub unsafe fn new_date_format_from_template(
allocator: Option<&CFAllocator>,
tmplate: Option<&CFString>,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterCreateDateFormatFromTemplate(
allocator: Option<&CFAllocator>,
tmplate: Option<&CFString>,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe {
CFDateFormatterCreateDateFormatFromTemplate(allocator, tmplate, options, locale)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
unsafe impl ConcreteType for CFDateFormatter {
#[doc(alias = "CFDateFormatterGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFDateFormatterGetTypeID() -> CFTypeID;
}
unsafe { CFDateFormatterGetTypeID() }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdateformatterstyle?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFDateFormatterStyle(pub CFIndex);
impl CFDateFormatterStyle {
#[doc(alias = "kCFDateFormatterNoStyle")]
pub const NoStyle: Self = Self(0);
#[doc(alias = "kCFDateFormatterShortStyle")]
pub const ShortStyle: Self = Self(1);
#[doc(alias = "kCFDateFormatterMediumStyle")]
pub const MediumStyle: Self = Self(2);
#[doc(alias = "kCFDateFormatterLongStyle")]
pub const LongStyle: Self = Self(3);
#[doc(alias = "kCFDateFormatterFullStyle")]
pub const FullStyle: Self = Self(4);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFDateFormatterStyle {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFDateFormatterStyle {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfiso8601dateformatoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFISO8601DateFormatOptions(pub CFOptionFlags);
bitflags::bitflags! {
impl CFISO8601DateFormatOptions: CFOptionFlags {
#[doc(alias = "kCFISO8601DateFormatWithYear")]
const WithYear = 1<<0;
#[doc(alias = "kCFISO8601DateFormatWithMonth")]
const WithMonth = 1<<1;
#[doc(alias = "kCFISO8601DateFormatWithWeekOfYear")]
const WithWeekOfYear = 1<<2;
#[doc(alias = "kCFISO8601DateFormatWithDay")]
const WithDay = 1<<4;
#[doc(alias = "kCFISO8601DateFormatWithTime")]
const WithTime = 1<<5;
#[doc(alias = "kCFISO8601DateFormatWithTimeZone")]
const WithTimeZone = 1<<6;
#[doc(alias = "kCFISO8601DateFormatWithSpaceBetweenDateAndTime")]
const WithSpaceBetweenDateAndTime = 1<<7;
#[doc(alias = "kCFISO8601DateFormatWithDashSeparatorInDate")]
const WithDashSeparatorInDate = 1<<8;
#[doc(alias = "kCFISO8601DateFormatWithColonSeparatorInTime")]
const WithColonSeparatorInTime = 1<<9;
#[doc(alias = "kCFISO8601DateFormatWithColonSeparatorInTimeZone")]
const WithColonSeparatorInTimeZone = 1<<10;
#[doc(alias = "kCFISO8601DateFormatWithFractionalSeconds")]
const WithFractionalSeconds = 1<<11;
#[doc(alias = "kCFISO8601DateFormatWithFullDate")]
const WithFullDate = CFISO8601DateFormatOptions::WithYear.0|CFISO8601DateFormatOptions::WithMonth.0|CFISO8601DateFormatOptions::WithDay.0|CFISO8601DateFormatOptions::WithDashSeparatorInDate.0;
#[doc(alias = "kCFISO8601DateFormatWithFullTime")]
const WithFullTime = CFISO8601DateFormatOptions::WithTime.0|CFISO8601DateFormatOptions::WithColonSeparatorInTime.0|CFISO8601DateFormatOptions::WithTimeZone.0|CFISO8601DateFormatOptions::WithColonSeparatorInTimeZone.0;
#[doc(alias = "kCFISO8601DateFormatWithInternetDateTime")]
const WithInternetDateTime = CFISO8601DateFormatOptions::WithFullDate.0|CFISO8601DateFormatOptions::WithFullTime.0;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFISO8601DateFormatOptions {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFISO8601DateFormatOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFDateFormatter {
#[doc(alias = "CFDateFormatterCreateISO8601Formatter")]
#[inline]
pub unsafe fn new_iso_8601_formatter(
allocator: Option<&CFAllocator>,
format_options: CFISO8601DateFormatOptions,
) -> Option<CFRetained<CFDateFormatter>> {
extern "C-unwind" {
fn CFDateFormatterCreateISO8601Formatter(
allocator: Option<&CFAllocator>,
format_options: CFISO8601DateFormatOptions,
) -> Option<NonNull<CFDateFormatter>>;
}
let ret = unsafe { CFDateFormatterCreateISO8601Formatter(allocator, format_options) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDateFormatterCreate")]
#[cfg(feature = "CFLocale")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
date_style: CFDateFormatterStyle,
time_style: CFDateFormatterStyle,
) -> Option<CFRetained<CFDateFormatter>> {
extern "C-unwind" {
fn CFDateFormatterCreate(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
date_style: CFDateFormatterStyle,
time_style: CFDateFormatterStyle,
) -> Option<NonNull<CFDateFormatter>>;
}
let ret = unsafe { CFDateFormatterCreate(allocator, locale, date_style, time_style) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDateFormatterGetLocale")]
#[cfg(feature = "CFLocale")]
#[inline]
pub unsafe fn locale(self: &CFDateFormatter) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFDateFormatterGetLocale(formatter: &CFDateFormatter) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFDateFormatterGetLocale(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFDateFormatterGetDateStyle")]
#[inline]
pub unsafe fn date_style(self: &CFDateFormatter) -> CFDateFormatterStyle {
extern "C-unwind" {
fn CFDateFormatterGetDateStyle(formatter: &CFDateFormatter) -> CFDateFormatterStyle;
}
unsafe { CFDateFormatterGetDateStyle(self) }
}
#[doc(alias = "CFDateFormatterGetTimeStyle")]
#[inline]
pub unsafe fn time_style(self: &CFDateFormatter) -> CFDateFormatterStyle {
extern "C-unwind" {
fn CFDateFormatterGetTimeStyle(formatter: &CFDateFormatter) -> CFDateFormatterStyle;
}
unsafe { CFDateFormatterGetTimeStyle(self) }
}
#[doc(alias = "CFDateFormatterGetFormat")]
#[inline]
pub unsafe fn format(self: &CFDateFormatter) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterGetFormat(formatter: &CFDateFormatter) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFDateFormatterGetFormat(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFDateFormatterSetFormat")]
#[inline]
pub unsafe fn set_format(self: &CFDateFormatter, format_string: Option<&CFString>) {
extern "C-unwind" {
fn CFDateFormatterSetFormat(
formatter: &CFDateFormatter,
format_string: Option<&CFString>,
);
}
unsafe { CFDateFormatterSetFormat(self, format_string) }
}
#[doc(alias = "CFDateFormatterCreateStringWithDate")]
#[cfg(feature = "CFDate")]
#[inline]
pub unsafe fn new_string_with_date(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
date: Option<&CFDate>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterCreateStringWithDate(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
date: Option<&CFDate>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFDateFormatterCreateStringWithDate(allocator, formatter, date) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDateFormatterCreateStringWithAbsoluteTime")]
#[cfg(feature = "CFDate")]
#[inline]
pub unsafe fn new_string_with_absolute_time(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
at: CFAbsoluteTime,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterCreateStringWithAbsoluteTime(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
at: CFAbsoluteTime,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFDateFormatterCreateStringWithAbsoluteTime(allocator, formatter, at) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDateFormatterCreateDateFromString")]
#[cfg(feature = "CFDate")]
#[inline]
pub unsafe fn new_date_from_string(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
) -> Option<CFRetained<CFDate>> {
extern "C-unwind" {
fn CFDateFormatterCreateDateFromString(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
) -> Option<NonNull<CFDate>>;
}
let ret =
unsafe { CFDateFormatterCreateDateFromString(allocator, formatter, string, rangep) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFDateFormatterGetAbsoluteTimeFromString")]
#[cfg(feature = "CFDate")]
#[inline]
pub unsafe fn absolute_time_from_string(
self: &CFDateFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
atp: *mut CFAbsoluteTime,
) -> bool {
extern "C-unwind" {
fn CFDateFormatterGetAbsoluteTimeFromString(
formatter: &CFDateFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
atp: *mut CFAbsoluteTime,
) -> Boolean;
}
let ret = unsafe { CFDateFormatterGetAbsoluteTimeFromString(self, string, rangep, atp) };
ret != 0
}
#[doc(alias = "CFDateFormatterSetProperty")]
#[inline]
pub unsafe fn set_property(
self: &CFDateFormatter,
key: Option<&CFString>,
value: Option<&CFType>,
) {
extern "C-unwind" {
fn CFDateFormatterSetProperty(
formatter: &CFDateFormatter,
key: Option<&CFString>,
value: Option<&CFType>,
);
}
unsafe { CFDateFormatterSetProperty(self, key, value) }
}
#[doc(alias = "CFDateFormatterCopyProperty")]
#[inline]
pub unsafe fn property(
self: &CFDateFormatter,
key: Option<&CFDateFormatterKey>,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFDateFormatterCopyProperty(
formatter: &CFDateFormatter,
key: Option<&CFDateFormatterKey>,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFDateFormatterCopyProperty(self, key) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterislenient?language=objc)
pub static kCFDateFormatterIsLenient: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattertimezone?language=objc)
pub static kCFDateFormatterTimeZone: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattercalendarname?language=objc)
pub static kCFDateFormatterCalendarName: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterdefaultformat?language=objc)
pub static kCFDateFormatterDefaultFormat: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattertwodigitstartdate?language=objc)
pub static kCFDateFormatterTwoDigitStartDate: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterdefaultdate?language=objc)
pub static kCFDateFormatterDefaultDate: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattercalendar?language=objc)
pub static kCFDateFormatterCalendar: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattererasymbols?language=objc)
pub static kCFDateFormatterEraSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattermonthsymbols?language=objc)
pub static kCFDateFormatterMonthSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattershortmonthsymbols?language=objc)
pub static kCFDateFormatterShortMonthSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterweekdaysymbols?language=objc)
pub static kCFDateFormatterWeekdaySymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattershortweekdaysymbols?language=objc)
pub static kCFDateFormatterShortWeekdaySymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatteramsymbol?language=objc)
pub static kCFDateFormatterAMSymbol: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterpmsymbol?language=objc)
pub static kCFDateFormatterPMSymbol: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterlongerasymbols?language=objc)
pub static kCFDateFormatterLongEraSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterveryshortmonthsymbols?language=objc)
pub static kCFDateFormatterVeryShortMonthSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterstandalonemonthsymbols?language=objc)
pub static kCFDateFormatterStandaloneMonthSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattershortstandalonemonthsymbols?language=objc)
pub static kCFDateFormatterShortStandaloneMonthSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterveryshortstandalonemonthsymbols?language=objc)
pub static kCFDateFormatterVeryShortStandaloneMonthSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterveryshortweekdaysymbols?language=objc)
pub static kCFDateFormatterVeryShortWeekdaySymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterstandaloneweekdaysymbols?language=objc)
pub static kCFDateFormatterStandaloneWeekdaySymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattershortstandaloneweekdaysymbols?language=objc)
pub static kCFDateFormatterShortStandaloneWeekdaySymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterveryshortstandaloneweekdaysymbols?language=objc)
pub static kCFDateFormatterVeryShortStandaloneWeekdaySymbols:
Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterquartersymbols?language=objc)
pub static kCFDateFormatterQuarterSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattershortquartersymbols?language=objc)
pub static kCFDateFormatterShortQuarterSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterstandalonequartersymbols?language=objc)
pub static kCFDateFormatterStandaloneQuarterSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattershortstandalonequartersymbols?language=objc)
pub static kCFDateFormatterShortStandaloneQuarterSymbols: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformattergregorianstartdate?language=objc)
pub static kCFDateFormatterGregorianStartDate: Option<&'static CFDateFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfdateformatterdoesrelativedateformattingkey?language=objc)
pub static kCFDateFormatterDoesRelativeDateFormattingKey: Option<&'static CFDateFormatterKey>;
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFDateFormatter::new_date_format_from_template`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterCreateDateFormatFromTemplate(
allocator: Option<&CFAllocator>,
tmplate: Option<&CFString>,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterCreateDateFormatFromTemplate(
allocator: Option<&CFAllocator>,
tmplate: Option<&CFString>,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFString>>;
}
let ret =
unsafe { CFDateFormatterCreateDateFormatFromTemplate(allocator, tmplate, options, locale) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFDateFormatter::new_iso_8601_formatter`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterCreateISO8601Formatter(
allocator: Option<&CFAllocator>,
format_options: CFISO8601DateFormatOptions,
) -> Option<CFRetained<CFDateFormatter>> {
extern "C-unwind" {
fn CFDateFormatterCreateISO8601Formatter(
allocator: Option<&CFAllocator>,
format_options: CFISO8601DateFormatOptions,
) -> Option<NonNull<CFDateFormatter>>;
}
let ret = unsafe { CFDateFormatterCreateISO8601Formatter(allocator, format_options) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFDateFormatter::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterCreate(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
date_style: CFDateFormatterStyle,
time_style: CFDateFormatterStyle,
) -> Option<CFRetained<CFDateFormatter>> {
extern "C-unwind" {
fn CFDateFormatterCreate(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
date_style: CFDateFormatterStyle,
time_style: CFDateFormatterStyle,
) -> Option<NonNull<CFDateFormatter>>;
}
let ret = unsafe { CFDateFormatterCreate(allocator, locale, date_style, time_style) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFDateFormatter::locale`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterGetLocale(
formatter: &CFDateFormatter,
) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFDateFormatterGetLocale(formatter: &CFDateFormatter) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFDateFormatterGetLocale(formatter) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFDateFormatter::date_style`"]
pub fn CFDateFormatterGetDateStyle(formatter: &CFDateFormatter) -> CFDateFormatterStyle;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFDateFormatter::time_style`"]
pub fn CFDateFormatterGetTimeStyle(formatter: &CFDateFormatter) -> CFDateFormatterStyle;
}
#[deprecated = "renamed to `CFDateFormatter::format`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterGetFormat(
formatter: &CFDateFormatter,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterGetFormat(formatter: &CFDateFormatter) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFDateFormatterGetFormat(formatter) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFDateFormatter::set_format`"]
pub fn CFDateFormatterSetFormat(formatter: &CFDateFormatter, format_string: Option<&CFString>);
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFDateFormatter::new_string_with_date`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterCreateStringWithDate(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
date: Option<&CFDate>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterCreateStringWithDate(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
date: Option<&CFDate>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFDateFormatterCreateStringWithDate(allocator, formatter, date) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFDateFormatter::new_string_with_absolute_time`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterCreateStringWithAbsoluteTime(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
at: CFAbsoluteTime,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFDateFormatterCreateStringWithAbsoluteTime(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
at: CFAbsoluteTime,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFDateFormatterCreateStringWithAbsoluteTime(allocator, formatter, at) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFDateFormatter::new_date_from_string`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterCreateDateFromString(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
) -> Option<CFRetained<CFDate>> {
extern "C-unwind" {
fn CFDateFormatterCreateDateFromString(
allocator: Option<&CFAllocator>,
formatter: Option<&CFDateFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
) -> Option<NonNull<CFDate>>;
}
let ret = unsafe { CFDateFormatterCreateDateFromString(allocator, formatter, string, rangep) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFDateFormatter::absolute_time_from_string`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterGetAbsoluteTimeFromString(
formatter: &CFDateFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
atp: *mut CFAbsoluteTime,
) -> bool {
extern "C-unwind" {
fn CFDateFormatterGetAbsoluteTimeFromString(
formatter: &CFDateFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
atp: *mut CFAbsoluteTime,
) -> Boolean;
}
let ret = unsafe { CFDateFormatterGetAbsoluteTimeFromString(formatter, string, rangep, atp) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFDateFormatter::set_property`"]
pub fn CFDateFormatterSetProperty(
formatter: &CFDateFormatter,
key: Option<&CFString>,
value: Option<&CFType>,
);
}
#[deprecated = "renamed to `CFDateFormatter::property`"]
#[inline]
pub unsafe extern "C-unwind" fn CFDateFormatterCopyProperty(
formatter: &CFDateFormatter,
key: Option<&CFDateFormatterKey>,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFDateFormatterCopyProperty(
formatter: &CFDateFormatter,
key: Option<&CFDateFormatterKey>,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFDateFormatterCopyProperty(formatter, key) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,411 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cferrordomain?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type CFErrorDomain = CFString;
/// This is the type of a reference to CFErrors. CFErrorRef is toll-free bridged with NSError.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cferror?language=objc)
#[repr(C)]
pub struct CFError {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFError {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFError"> for CFError {}
);
unsafe impl ConcreteType for CFError {
/// Returns the type identifier of all CFError instances.
#[doc(alias = "CFErrorGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFErrorGetTypeID() -> CFTypeID;
}
unsafe { CFErrorGetTypeID() }
}
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomainposix?language=objc)
pub static kCFErrorDomainPOSIX: Option<&'static CFErrorDomain>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomainosstatus?language=objc)
pub static kCFErrorDomainOSStatus: Option<&'static CFErrorDomain>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomainmach?language=objc)
pub static kCFErrorDomainMach: Option<&'static CFErrorDomain>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomaincocoa?language=objc)
pub static kCFErrorDomainCocoa: Option<&'static CFErrorDomain>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizeddescriptionkey?language=objc)
pub static kCFErrorLocalizedDescriptionKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizedfailurekey?language=objc)
pub static kCFErrorLocalizedFailureKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizedfailurereasonkey?language=objc)
pub static kCFErrorLocalizedFailureReasonKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizedrecoverysuggestionkey?language=objc)
pub static kCFErrorLocalizedRecoverySuggestionKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordescriptionkey?language=objc)
pub static kCFErrorDescriptionKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorunderlyingerrorkey?language=objc)
pub static kCFErrorUnderlyingErrorKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorurlkey?language=objc)
pub static kCFErrorURLKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorfilepathkey?language=objc)
pub static kCFErrorFilePathKey: Option<&'static CFString>;
}
impl CFError {
/// Creates a new CFError.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate memory for the error. This parameter may be NULL in which case the
/// current default CFAllocator is used. If this reference is not a valid CFAllocator, the behavior is undefined.
///
/// Parameter `domain`: A CFString identifying the error domain. If this reference is NULL or is otherwise not a valid CFString, the behavior is undefined.
///
/// Parameter `code`: A CFIndex identifying the error code. The code is interpreted within the context of the error domain.
///
/// Parameter `userInfo`: A CFDictionary created with kCFCopyStringDictionaryKeyCallBacks and kCFTypeDictionaryValueCallBacks. It will be copied with CFDictionaryCreateCopy().
/// If no userInfo dictionary is desired, NULL may be passed in as a convenience, in which case an empty userInfo dictionary will be assigned.
///
/// Returns: A reference to the new CFError.
#[doc(alias = "CFErrorCreate")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info: Option<&CFDictionary>,
) -> Option<CFRetained<CFError>> {
extern "C-unwind" {
fn CFErrorCreate(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info: Option<&CFDictionary>,
) -> Option<NonNull<CFError>>;
}
let ret = unsafe { CFErrorCreate(allocator, domain, code, user_info) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a new CFError without having to create an intermediate userInfo dictionary.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate memory for the error. This parameter may be NULL in which case the
/// current default CFAllocator is used. If this reference is not a valid CFAllocator, the behavior is undefined.
///
/// Parameter `domain`: A CFString identifying the error domain. If this reference is NULL or is otherwise not a valid CFString, the behavior is undefined.
///
/// Parameter `code`: A CFIndex identifying the error code. The code is interpreted within the context of the error domain.
///
/// Parameter `userInfoKeys`: An array of numUserInfoValues CFStrings used as keys in creating the userInfo dictionary. NULL is valid only if numUserInfoValues is 0.
///
/// Parameter `userInfoValues`: An array of numUserInfoValues CF types used as values in creating the userInfo dictionary. NULL is valid only if numUserInfoValues is 0.
///
/// Parameter `numUserInfoValues`: CFIndex representing the number of keys and values in the userInfoKeys and userInfoValues arrays.
///
/// Returns: A reference to the new CFError. numUserInfoValues CF types are gathered from each of userInfoKeys and userInfoValues to create the userInfo dictionary.
#[doc(alias = "CFErrorCreateWithUserInfoKeysAndValues")]
#[inline]
pub unsafe fn with_user_info_keys_and_values(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info_keys: *const *const c_void,
user_info_values: *const *const c_void,
num_user_info_values: CFIndex,
) -> Option<CFRetained<CFError>> {
extern "C-unwind" {
fn CFErrorCreateWithUserInfoKeysAndValues(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info_keys: *const *const c_void,
user_info_values: *const *const c_void,
num_user_info_values: CFIndex,
) -> Option<NonNull<CFError>>;
}
let ret = unsafe {
CFErrorCreateWithUserInfoKeysAndValues(
allocator,
domain,
code,
user_info_keys,
user_info_values,
num_user_info_values,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns the error domain the CFError was created with.
///
/// Parameter `err`: The CFError whose error domain is to be returned. If this reference is not a valid CFError, the behavior is undefined.
///
/// Returns: The error domain of the CFError. Since this is a "Get" function, the caller shouldn't CFRelease the return value.
#[doc(alias = "CFErrorGetDomain")]
#[inline]
pub fn domain(self: &CFError) -> Option<CFRetained<CFErrorDomain>> {
extern "C-unwind" {
fn CFErrorGetDomain(err: &CFError) -> Option<NonNull<CFErrorDomain>>;
}
let ret = unsafe { CFErrorGetDomain(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the error code the CFError was created with.
///
/// Parameter `err`: The CFError whose error code is to be returned. If this reference is not a valid CFError, the behavior is undefined.
///
/// Returns: The error code of the CFError (not an error return for the current call).
#[doc(alias = "CFErrorGetCode")]
#[inline]
pub fn code(self: &CFError) -> CFIndex {
extern "C-unwind" {
fn CFErrorGetCode(err: &CFError) -> CFIndex;
}
unsafe { CFErrorGetCode(self) }
}
/// Returns CFError userInfo dictionary.
///
/// Returns a dictionary containing the same keys and values as in the userInfo dictionary the CFError was created with. Returns an empty dictionary if NULL was supplied to CFErrorCreate().
///
/// Parameter `err`: The CFError whose error user info is to be returned. If this reference is not a valid CFError, the behavior is undefined.
///
/// Returns: The user info of the CFError.
#[doc(alias = "CFErrorCopyUserInfo")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub fn user_info(self: &CFError) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFErrorCopyUserInfo(err: &CFError) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFErrorCopyUserInfo(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns a human-presentable description for the error. CFError creators should strive to make sure the return value is human-presentable and localized by providing a value for kCFErrorLocalizedDescriptionKey at the time of CFError creation.
///
/// This is a complete sentence or two which says what failed and why it failed. Please refer to header comments for -[NSError localizedDescription] for details on the steps used to compute this; but roughly:
/// - Use value of kCFErrorLocalizedDescriptionKey as-is if provided.
/// - Use value of kCFErrorLocalizedFailureKey if provided, optionally followed by kCFErrorLocalizedFailureReasonKey if available.
/// - Use value of kCFErrorLocalizedFailureReasonKey, combining with a generic failure message such as: "Operation code not be completed. " + kCFErrorLocalizedFailureReasonKey.
/// - If all of the above fail, generate a semi-user presentable string from kCFErrorDescriptionKey, the domain, and code. Something like: "Operation could not be completed. Error domain/code occurred. " or "Operation could not be completed. " + kCFErrorDescriptionKey + " (Error domain/code)"
/// Toll-free bridged NSError instances might provide additional behaviors for manufacturing a description string. Do not count on the exact contents or format of the returned string, it might change.
///
/// Parameter `err`: The CFError whose description is to be returned. If this reference is not a valid CFError, the behavior is undefined.
///
/// Returns: A CFString with human-presentable description of the CFError. Never NULL.
#[doc(alias = "CFErrorCopyDescription")]
#[inline]
pub fn description(self: &CFError) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFErrorCopyDescription(err: &CFError) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFErrorCopyDescription(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns a human-presentable failure reason for the error. May return NULL. CFError creators should strive to make sure the return value is human-presentable and localized by providing a value for kCFErrorLocalizedFailureReasonKey at the time of CFError creation.
///
/// This is a complete sentence which describes why the operation failed. In many cases this will be just the "because" part of the description (but as a complete sentence, which makes localization easier). By default this looks for kCFErrorLocalizedFailureReasonKey in the user info. Toll-free bridged NSError instances might provide additional behaviors for manufacturing this value. If no user-presentable string is available, returns NULL.
/// Example Description: "Could not save file 'Letter' in folder 'Documents' because the volume 'MyDisk' doesn't have enough space."
/// Corresponding FailureReason: "The volume 'MyDisk' doesn't have enough space."
///
/// Parameter `err`: The CFError whose failure reason is to be returned. If this reference is not a valid CFError, the behavior is undefined.
///
/// Returns: A CFString with the localized, end-user presentable failure reason of the CFError, or NULL.
#[doc(alias = "CFErrorCopyFailureReason")]
#[inline]
pub fn failure_reason(self: &CFError) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFErrorCopyFailureReason(err: &CFError) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFErrorCopyFailureReason(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns a human presentable recovery suggestion for the error. May return NULL. CFError creators should strive to make sure the return value is human-presentable and localized by providing a value for kCFErrorLocalizedRecoverySuggestionKey at the time of CFError creation.
///
/// This is the string that can be displayed as the "informative" (aka "secondary") message on an alert panel. By default this looks for kCFErrorLocalizedRecoverySuggestionKey in the user info. Toll-free bridged NSError instances might provide additional behaviors for manufacturing this value. If no user-presentable string is available, returns NULL.
/// Example Description: "Could not save file 'Letter' in folder 'Documents' because the volume 'MyDisk' doesn't have enough space."
/// Corresponding RecoverySuggestion: "Remove some files from the volume and try again."
///
/// Parameter `err`: The CFError whose recovery suggestion is to be returned. If this reference is not a valid CFError, the behavior is undefined.
///
/// Returns: A CFString with the localized, end-user presentable recovery suggestion of the CFError, or NULL.
#[doc(alias = "CFErrorCopyRecoverySuggestion")]
#[inline]
pub fn recovery_suggestion(self: &CFError) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFErrorCopyRecoverySuggestion(err: &CFError) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFErrorCopyRecoverySuggestion(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFError::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFErrorCreate(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info: Option<&CFDictionary>,
) -> Option<CFRetained<CFError>> {
extern "C-unwind" {
fn CFErrorCreate(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info: Option<&CFDictionary>,
) -> Option<NonNull<CFError>>;
}
let ret = unsafe { CFErrorCreate(allocator, domain, code, user_info) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFError::with_user_info_keys_and_values`"]
#[inline]
pub unsafe extern "C-unwind" fn CFErrorCreateWithUserInfoKeysAndValues(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info_keys: *const *const c_void,
user_info_values: *const *const c_void,
num_user_info_values: CFIndex,
) -> Option<CFRetained<CFError>> {
extern "C-unwind" {
fn CFErrorCreateWithUserInfoKeysAndValues(
allocator: Option<&CFAllocator>,
domain: Option<&CFErrorDomain>,
code: CFIndex,
user_info_keys: *const *const c_void,
user_info_values: *const *const c_void,
num_user_info_values: CFIndex,
) -> Option<NonNull<CFError>>;
}
let ret = unsafe {
CFErrorCreateWithUserInfoKeysAndValues(
allocator,
domain,
code,
user_info_keys,
user_info_values,
num_user_info_values,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFError::domain`"]
#[inline]
pub extern "C-unwind" fn CFErrorGetDomain(err: &CFError) -> Option<CFRetained<CFErrorDomain>> {
extern "C-unwind" {
fn CFErrorGetDomain(err: &CFError) -> Option<NonNull<CFErrorDomain>>;
}
let ret = unsafe { CFErrorGetDomain(err) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFError::code`"]
#[inline]
pub extern "C-unwind" fn CFErrorGetCode(err: &CFError) -> CFIndex {
extern "C-unwind" {
fn CFErrorGetCode(err: &CFError) -> CFIndex;
}
unsafe { CFErrorGetCode(err) }
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFError::user_info`"]
#[inline]
pub extern "C-unwind" fn CFErrorCopyUserInfo(err: &CFError) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFErrorCopyUserInfo(err: &CFError) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFErrorCopyUserInfo(err) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFError::description`"]
#[inline]
pub extern "C-unwind" fn CFErrorCopyDescription(err: &CFError) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFErrorCopyDescription(err: &CFError) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFErrorCopyDescription(err) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFError::failure_reason`"]
#[inline]
pub extern "C-unwind" fn CFErrorCopyFailureReason(err: &CFError) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFErrorCopyFailureReason(err: &CFError) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFErrorCopyFailureReason(err) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFError::recovery_suggestion`"]
#[inline]
pub extern "C-unwind" fn CFErrorCopyRecoverySuggestion(
err: &CFError,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFErrorCopyRecoverySuggestion(err: &CFError) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFErrorCopyRecoverySuggestion(err) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,293 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptornativedescriptor?language=objc)
pub type CFFileDescriptorNativeDescriptor = c_int;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptor?language=objc)
#[repr(C)]
pub struct CFFileDescriptor {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFFileDescriptor {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFFileDescriptor"> for CFFileDescriptor {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcffiledescriptorreadcallback?language=objc)
pub const kCFFileDescriptorReadCallBack: CFOptionFlags = 1 << 0;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcffiledescriptorwritecallback?language=objc)
pub const kCFFileDescriptorWriteCallBack: CFOptionFlags = 1 << 1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptorcallback?language=objc)
pub type CFFileDescriptorCallBack =
Option<unsafe extern "C-unwind" fn(*mut CFFileDescriptor, CFOptionFlags, *mut c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffiledescriptorcontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFFileDescriptorContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: Option<unsafe extern "C-unwind" fn(*mut c_void) -> *mut c_void>,
pub release: Option<unsafe extern "C-unwind" fn(*mut c_void)>,
pub copyDescription: Option<unsafe extern "C-unwind" fn(*mut c_void) -> *const CFString>,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFFileDescriptorContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*mut c_void) -> *mut c_void>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*mut c_void)>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*mut c_void) -> *const CFString>>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFFileDescriptorContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFFileDescriptor {
#[doc(alias = "CFFileDescriptorGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFFileDescriptorGetTypeID() -> CFTypeID;
}
unsafe { CFFileDescriptorGetTypeID() }
}
}
impl CFFileDescriptor {
#[doc(alias = "CFFileDescriptorCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
fd: CFFileDescriptorNativeDescriptor,
close_on_invalidate: bool,
callout: CFFileDescriptorCallBack,
context: *const CFFileDescriptorContext,
) -> Option<CFRetained<CFFileDescriptor>> {
extern "C-unwind" {
fn CFFileDescriptorCreate(
allocator: Option<&CFAllocator>,
fd: CFFileDescriptorNativeDescriptor,
close_on_invalidate: Boolean,
callout: CFFileDescriptorCallBack,
context: *const CFFileDescriptorContext,
) -> Option<NonNull<CFFileDescriptor>>;
}
let ret = unsafe {
CFFileDescriptorCreate(allocator, fd, close_on_invalidate as _, callout, context)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFFileDescriptorGetNativeDescriptor")]
#[inline]
pub fn native_descriptor(self: &CFFileDescriptor) -> CFFileDescriptorNativeDescriptor {
extern "C-unwind" {
fn CFFileDescriptorGetNativeDescriptor(
f: &CFFileDescriptor,
) -> CFFileDescriptorNativeDescriptor;
}
unsafe { CFFileDescriptorGetNativeDescriptor(self) }
}
#[doc(alias = "CFFileDescriptorGetContext")]
#[inline]
pub unsafe fn context(self: &CFFileDescriptor, context: *mut CFFileDescriptorContext) {
extern "C-unwind" {
fn CFFileDescriptorGetContext(
f: &CFFileDescriptor,
context: *mut CFFileDescriptorContext,
);
}
unsafe { CFFileDescriptorGetContext(self, context) }
}
#[doc(alias = "CFFileDescriptorEnableCallBacks")]
#[inline]
pub fn enable_call_backs(self: &CFFileDescriptor, call_back_types: CFOptionFlags) {
extern "C-unwind" {
fn CFFileDescriptorEnableCallBacks(
f: &CFFileDescriptor,
call_back_types: CFOptionFlags,
);
}
unsafe { CFFileDescriptorEnableCallBacks(self, call_back_types) }
}
#[doc(alias = "CFFileDescriptorDisableCallBacks")]
#[inline]
pub fn disable_call_backs(self: &CFFileDescriptor, call_back_types: CFOptionFlags) {
extern "C-unwind" {
fn CFFileDescriptorDisableCallBacks(
f: &CFFileDescriptor,
call_back_types: CFOptionFlags,
);
}
unsafe { CFFileDescriptorDisableCallBacks(self, call_back_types) }
}
#[doc(alias = "CFFileDescriptorInvalidate")]
#[inline]
pub fn invalidate(self: &CFFileDescriptor) {
extern "C-unwind" {
fn CFFileDescriptorInvalidate(f: &CFFileDescriptor);
}
unsafe { CFFileDescriptorInvalidate(self) }
}
#[doc(alias = "CFFileDescriptorIsValid")]
#[inline]
pub fn is_valid(self: &CFFileDescriptor) -> bool {
extern "C-unwind" {
fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> Boolean;
}
let ret = unsafe { CFFileDescriptorIsValid(self) };
ret != 0
}
#[doc(alias = "CFFileDescriptorCreateRunLoopSource")]
#[cfg(feature = "CFRunLoop")]
#[inline]
pub fn new_run_loop_source(
allocator: Option<&CFAllocator>,
f: Option<&CFFileDescriptor>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFFileDescriptorCreateRunLoopSource(
allocator: Option<&CFAllocator>,
f: Option<&CFFileDescriptor>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFFileDescriptorCreateRunLoopSource(allocator, f, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
#[deprecated = "renamed to `CFFileDescriptor::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFFileDescriptorCreate(
allocator: Option<&CFAllocator>,
fd: CFFileDescriptorNativeDescriptor,
close_on_invalidate: bool,
callout: CFFileDescriptorCallBack,
context: *const CFFileDescriptorContext,
) -> Option<CFRetained<CFFileDescriptor>> {
extern "C-unwind" {
fn CFFileDescriptorCreate(
allocator: Option<&CFAllocator>,
fd: CFFileDescriptorNativeDescriptor,
close_on_invalidate: Boolean,
callout: CFFileDescriptorCallBack,
context: *const CFFileDescriptorContext,
) -> Option<NonNull<CFFileDescriptor>>;
}
let ret = unsafe {
CFFileDescriptorCreate(allocator, fd, close_on_invalidate as _, callout, context)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFFileDescriptor::native_descriptor`"]
#[inline]
pub extern "C-unwind" fn CFFileDescriptorGetNativeDescriptor(
f: &CFFileDescriptor,
) -> CFFileDescriptorNativeDescriptor {
extern "C-unwind" {
fn CFFileDescriptorGetNativeDescriptor(
f: &CFFileDescriptor,
) -> CFFileDescriptorNativeDescriptor;
}
unsafe { CFFileDescriptorGetNativeDescriptor(f) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFFileDescriptor::context`"]
pub fn CFFileDescriptorGetContext(f: &CFFileDescriptor, context: *mut CFFileDescriptorContext);
}
#[deprecated = "renamed to `CFFileDescriptor::enable_call_backs`"]
#[inline]
pub extern "C-unwind" fn CFFileDescriptorEnableCallBacks(
f: &CFFileDescriptor,
call_back_types: CFOptionFlags,
) {
extern "C-unwind" {
fn CFFileDescriptorEnableCallBacks(f: &CFFileDescriptor, call_back_types: CFOptionFlags);
}
unsafe { CFFileDescriptorEnableCallBacks(f, call_back_types) }
}
#[deprecated = "renamed to `CFFileDescriptor::disable_call_backs`"]
#[inline]
pub extern "C-unwind" fn CFFileDescriptorDisableCallBacks(
f: &CFFileDescriptor,
call_back_types: CFOptionFlags,
) {
extern "C-unwind" {
fn CFFileDescriptorDisableCallBacks(f: &CFFileDescriptor, call_back_types: CFOptionFlags);
}
unsafe { CFFileDescriptorDisableCallBacks(f, call_back_types) }
}
#[deprecated = "renamed to `CFFileDescriptor::invalidate`"]
#[inline]
pub extern "C-unwind" fn CFFileDescriptorInvalidate(f: &CFFileDescriptor) {
extern "C-unwind" {
fn CFFileDescriptorInvalidate(f: &CFFileDescriptor);
}
unsafe { CFFileDescriptorInvalidate(f) }
}
#[deprecated = "renamed to `CFFileDescriptor::is_valid`"]
#[inline]
pub extern "C-unwind" fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> bool {
extern "C-unwind" {
fn CFFileDescriptorIsValid(f: &CFFileDescriptor) -> Boolean;
}
let ret = unsafe { CFFileDescriptorIsValid(f) };
ret != 0
}
#[cfg(feature = "CFRunLoop")]
#[deprecated = "renamed to `CFFileDescriptor::new_run_loop_source`"]
#[inline]
pub extern "C-unwind" fn CFFileDescriptorCreateRunLoopSource(
allocator: Option<&CFAllocator>,
f: Option<&CFFileDescriptor>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFFileDescriptorCreateRunLoopSource(
allocator: Option<&CFAllocator>,
f: Option<&CFFileDescriptor>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFFileDescriptorCreateRunLoopSource(allocator, f, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,441 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffilesecurity?language=objc)
#[repr(C)]
pub struct CFFileSecurity {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFFileSecurity {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFFileSecurity"> for CFFileSecurity {}
);
unsafe impl ConcreteType for CFFileSecurity {
#[doc(alias = "CFFileSecurityGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFFileSecurityGetTypeID() -> CFTypeID;
}
unsafe { CFFileSecurityGetTypeID() }
}
}
impl CFFileSecurity {
#[doc(alias = "CFFileSecurityCreate")]
#[inline]
pub fn new(allocator: Option<&CFAllocator>) -> Option<CFRetained<CFFileSecurity>> {
extern "C-unwind" {
fn CFFileSecurityCreate(
allocator: Option<&CFAllocator>,
) -> Option<NonNull<CFFileSecurity>>;
}
let ret = unsafe { CFFileSecurityCreate(allocator) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFFileSecurityCreateCopy")]
#[inline]
pub fn new_copy(
allocator: Option<&CFAllocator>,
file_sec: Option<&CFFileSecurity>,
) -> Option<CFRetained<CFFileSecurity>> {
extern "C-unwind" {
fn CFFileSecurityCreateCopy(
allocator: Option<&CFAllocator>,
file_sec: Option<&CFFileSecurity>,
) -> Option<NonNull<CFFileSecurity>>;
}
let ret = unsafe { CFFileSecurityCreateCopy(allocator, file_sec) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFFileSecurityCopyOwnerUUID")]
#[cfg(feature = "CFUUID")]
#[inline]
pub unsafe fn owner_uuid(self: &CFFileSecurity, owner_uuid: *mut *const CFUUID) -> bool {
extern "C-unwind" {
fn CFFileSecurityCopyOwnerUUID(
file_sec: &CFFileSecurity,
owner_uuid: *mut *const CFUUID,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityCopyOwnerUUID(self, owner_uuid) };
ret != 0
}
#[doc(alias = "CFFileSecuritySetOwnerUUID")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn set_owner_uuid(self: &CFFileSecurity, owner_uuid: Option<&CFUUID>) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetOwnerUUID(
file_sec: &CFFileSecurity,
owner_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetOwnerUUID(self, owner_uuid) };
ret != 0
}
#[doc(alias = "CFFileSecurityCopyGroupUUID")]
#[cfg(feature = "CFUUID")]
#[inline]
pub unsafe fn group_uuid(self: &CFFileSecurity, group_uuid: *mut *const CFUUID) -> bool {
extern "C-unwind" {
fn CFFileSecurityCopyGroupUUID(
file_sec: &CFFileSecurity,
group_uuid: *mut *const CFUUID,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityCopyGroupUUID(self, group_uuid) };
ret != 0
}
#[doc(alias = "CFFileSecuritySetGroupUUID")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn set_group_uuid(self: &CFFileSecurity, group_uuid: Option<&CFUUID>) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetGroupUUID(
file_sec: &CFFileSecurity,
group_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetGroupUUID(self, group_uuid) };
ret != 0
}
#[doc(alias = "CFFileSecurityGetOwner")]
#[cfg(feature = "libc")]
#[inline]
pub unsafe fn owner(self: &CFFileSecurity, owner: *mut libc::uid_t) -> bool {
extern "C-unwind" {
fn CFFileSecurityGetOwner(
file_sec: &CFFileSecurity,
owner: *mut libc::uid_t,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityGetOwner(self, owner) };
ret != 0
}
#[doc(alias = "CFFileSecuritySetOwner")]
#[cfg(feature = "libc")]
#[inline]
pub fn set_owner(self: &CFFileSecurity, owner: libc::uid_t) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetOwner(file_sec: &CFFileSecurity, owner: libc::uid_t) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetOwner(self, owner) };
ret != 0
}
#[doc(alias = "CFFileSecurityGetGroup")]
#[cfg(feature = "libc")]
#[inline]
pub unsafe fn group(self: &CFFileSecurity, group: *mut libc::gid_t) -> bool {
extern "C-unwind" {
fn CFFileSecurityGetGroup(
file_sec: &CFFileSecurity,
group: *mut libc::gid_t,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityGetGroup(self, group) };
ret != 0
}
#[doc(alias = "CFFileSecuritySetGroup")]
#[cfg(feature = "libc")]
#[inline]
pub fn set_group(self: &CFFileSecurity, group: libc::gid_t) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetGroup(file_sec: &CFFileSecurity, group: libc::gid_t) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetGroup(self, group) };
ret != 0
}
#[doc(alias = "CFFileSecurityGetMode")]
#[cfg(feature = "libc")]
#[inline]
pub unsafe fn mode(self: &CFFileSecurity, mode: *mut libc::mode_t) -> bool {
extern "C-unwind" {
fn CFFileSecurityGetMode(file_sec: &CFFileSecurity, mode: *mut libc::mode_t)
-> Boolean;
}
let ret = unsafe { CFFileSecurityGetMode(self, mode) };
ret != 0
}
#[doc(alias = "CFFileSecuritySetMode")]
#[cfg(feature = "libc")]
#[inline]
pub fn set_mode(self: &CFFileSecurity, mode: libc::mode_t) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetMode(file_sec: &CFFileSecurity, mode: libc::mode_t) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetMode(self, mode) };
ret != 0
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cffilesecurityclearoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFFileSecurityClearOptions(pub CFOptionFlags);
bitflags::bitflags! {
impl CFFileSecurityClearOptions: CFOptionFlags {
#[doc(alias = "kCFFileSecurityClearOwner")]
const Owner = 1<<0;
#[doc(alias = "kCFFileSecurityClearGroup")]
const Group = 1<<1;
#[doc(alias = "kCFFileSecurityClearMode")]
const Mode = 1<<2;
#[doc(alias = "kCFFileSecurityClearOwnerUUID")]
const OwnerUUID = 1<<3;
#[doc(alias = "kCFFileSecurityClearGroupUUID")]
const GroupUUID = 1<<4;
#[doc(alias = "kCFFileSecurityClearAccessControlList")]
const AccessControlList = 1<<5;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFFileSecurityClearOptions {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFFileSecurityClearOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFFileSecurity {
#[doc(alias = "CFFileSecurityClearProperties")]
#[inline]
pub fn clear_properties(
self: &CFFileSecurity,
clear_property_mask: CFFileSecurityClearOptions,
) -> bool {
extern "C-unwind" {
fn CFFileSecurityClearProperties(
file_sec: &CFFileSecurity,
clear_property_mask: CFFileSecurityClearOptions,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityClearProperties(self, clear_property_mask) };
ret != 0
}
}
#[deprecated = "renamed to `CFFileSecurity::new`"]
#[inline]
pub extern "C-unwind" fn CFFileSecurityCreate(
allocator: Option<&CFAllocator>,
) -> Option<CFRetained<CFFileSecurity>> {
extern "C-unwind" {
fn CFFileSecurityCreate(allocator: Option<&CFAllocator>)
-> Option<NonNull<CFFileSecurity>>;
}
let ret = unsafe { CFFileSecurityCreate(allocator) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFFileSecurity::new_copy`"]
#[inline]
pub extern "C-unwind" fn CFFileSecurityCreateCopy(
allocator: Option<&CFAllocator>,
file_sec: Option<&CFFileSecurity>,
) -> Option<CFRetained<CFFileSecurity>> {
extern "C-unwind" {
fn CFFileSecurityCreateCopy(
allocator: Option<&CFAllocator>,
file_sec: Option<&CFFileSecurity>,
) -> Option<NonNull<CFFileSecurity>>;
}
let ret = unsafe { CFFileSecurityCreateCopy(allocator, file_sec) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFFileSecurity::owner_uuid`"]
#[inline]
pub unsafe extern "C-unwind" fn CFFileSecurityCopyOwnerUUID(
file_sec: &CFFileSecurity,
owner_uuid: *mut *const CFUUID,
) -> bool {
extern "C-unwind" {
fn CFFileSecurityCopyOwnerUUID(
file_sec: &CFFileSecurity,
owner_uuid: *mut *const CFUUID,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityCopyOwnerUUID(file_sec, owner_uuid) };
ret != 0
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFFileSecurity::set_owner_uuid`"]
#[inline]
pub extern "C-unwind" fn CFFileSecuritySetOwnerUUID(
file_sec: &CFFileSecurity,
owner_uuid: Option<&CFUUID>,
) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetOwnerUUID(
file_sec: &CFFileSecurity,
owner_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetOwnerUUID(file_sec, owner_uuid) };
ret != 0
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFFileSecurity::group_uuid`"]
#[inline]
pub unsafe extern "C-unwind" fn CFFileSecurityCopyGroupUUID(
file_sec: &CFFileSecurity,
group_uuid: *mut *const CFUUID,
) -> bool {
extern "C-unwind" {
fn CFFileSecurityCopyGroupUUID(
file_sec: &CFFileSecurity,
group_uuid: *mut *const CFUUID,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityCopyGroupUUID(file_sec, group_uuid) };
ret != 0
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFFileSecurity::set_group_uuid`"]
#[inline]
pub extern "C-unwind" fn CFFileSecuritySetGroupUUID(
file_sec: &CFFileSecurity,
group_uuid: Option<&CFUUID>,
) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetGroupUUID(
file_sec: &CFFileSecurity,
group_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetGroupUUID(file_sec, group_uuid) };
ret != 0
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFFileSecurity::owner`"]
#[inline]
pub unsafe extern "C-unwind" fn CFFileSecurityGetOwner(
file_sec: &CFFileSecurity,
owner: *mut libc::uid_t,
) -> bool {
extern "C-unwind" {
fn CFFileSecurityGetOwner(file_sec: &CFFileSecurity, owner: *mut libc::uid_t) -> Boolean;
}
let ret = unsafe { CFFileSecurityGetOwner(file_sec, owner) };
ret != 0
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFFileSecurity::set_owner`"]
#[inline]
pub extern "C-unwind" fn CFFileSecuritySetOwner(
file_sec: &CFFileSecurity,
owner: libc::uid_t,
) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetOwner(file_sec: &CFFileSecurity, owner: libc::uid_t) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetOwner(file_sec, owner) };
ret != 0
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFFileSecurity::group`"]
#[inline]
pub unsafe extern "C-unwind" fn CFFileSecurityGetGroup(
file_sec: &CFFileSecurity,
group: *mut libc::gid_t,
) -> bool {
extern "C-unwind" {
fn CFFileSecurityGetGroup(file_sec: &CFFileSecurity, group: *mut libc::gid_t) -> Boolean;
}
let ret = unsafe { CFFileSecurityGetGroup(file_sec, group) };
ret != 0
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFFileSecurity::set_group`"]
#[inline]
pub extern "C-unwind" fn CFFileSecuritySetGroup(
file_sec: &CFFileSecurity,
group: libc::gid_t,
) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetGroup(file_sec: &CFFileSecurity, group: libc::gid_t) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetGroup(file_sec, group) };
ret != 0
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFFileSecurity::mode`"]
#[inline]
pub unsafe extern "C-unwind" fn CFFileSecurityGetMode(
file_sec: &CFFileSecurity,
mode: *mut libc::mode_t,
) -> bool {
extern "C-unwind" {
fn CFFileSecurityGetMode(file_sec: &CFFileSecurity, mode: *mut libc::mode_t) -> Boolean;
}
let ret = unsafe { CFFileSecurityGetMode(file_sec, mode) };
ret != 0
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFFileSecurity::set_mode`"]
#[inline]
pub extern "C-unwind" fn CFFileSecuritySetMode(
file_sec: &CFFileSecurity,
mode: libc::mode_t,
) -> bool {
extern "C-unwind" {
fn CFFileSecuritySetMode(file_sec: &CFFileSecurity, mode: libc::mode_t) -> Boolean;
}
let ret = unsafe { CFFileSecuritySetMode(file_sec, mode) };
ret != 0
}
#[deprecated = "renamed to `CFFileSecurity::clear_properties`"]
#[inline]
pub extern "C-unwind" fn CFFileSecurityClearProperties(
file_sec: &CFFileSecurity,
clear_property_mask: CFFileSecurityClearOptions,
) -> bool {
extern "C-unwind" {
fn CFFileSecurityClearProperties(
file_sec: &CFFileSecurity,
clear_property_mask: CFFileSecurityClearOptions,
) -> Boolean;
}
let ret = unsafe { CFFileSecurityClearProperties(file_sec, clear_property_mask) };
ret != 0
}

View File

@@ -0,0 +1,860 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cflocaleidentifier?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type CFLocaleIdentifier = CFString;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cflocalekey?language=objc)
// NS_TYPED_ENUM
pub type CFLocaleKey = CFString;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cflocale?language=objc)
#[repr(C)]
pub struct CFLocale {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFLocale {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFLocale"> for CFLocale {}
);
unsafe impl ConcreteType for CFLocale {
#[doc(alias = "CFLocaleGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFLocaleGetTypeID() -> CFTypeID;
}
unsafe { CFLocaleGetTypeID() }
}
}
impl CFLocale {
#[doc(alias = "CFLocaleGetSystem")]
#[inline]
pub fn system() -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleGetSystem() -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleGetSystem() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFLocaleCopyCurrent")]
#[inline]
pub fn current() -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleCopyCurrent() -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleCopyCurrent() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCopyAvailableLocaleIdentifiers")]
#[cfg(feature = "CFArray")]
#[inline]
pub fn available_locale_identifiers() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyAvailableLocaleIdentifiers() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyAvailableLocaleIdentifiers() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCopyISOLanguageCodes")]
#[cfg(feature = "CFArray")]
#[inline]
pub fn iso_language_codes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyISOLanguageCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyISOLanguageCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCopyISOCountryCodes")]
#[cfg(feature = "CFArray")]
#[inline]
pub fn iso_country_codes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyISOCountryCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyISOCountryCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCopyISOCurrencyCodes")]
#[cfg(feature = "CFArray")]
#[inline]
pub fn iso_currency_codes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyISOCurrencyCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyISOCurrencyCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCopyCommonISOCurrencyCodes")]
#[cfg(feature = "CFArray")]
#[inline]
pub fn common_iso_currency_codes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyCommonISOCurrencyCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyCommonISOCurrencyCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCopyPreferredLanguages")]
#[cfg(feature = "CFArray")]
#[inline]
pub fn preferred_languages() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyPreferredLanguages() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyPreferredLanguages() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCreateCanonicalLanguageIdentifierFromString")]
#[inline]
pub fn new_canonical_language_identifier_from_string(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateCanonicalLanguageIdentifierFromString(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe {
CFLocaleCreateCanonicalLanguageIdentifierFromString(allocator, locale_identifier)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCreateCanonicalLocaleIdentifierFromString")]
#[inline]
pub fn new_canonical_locale_identifier_from_string(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateCanonicalLocaleIdentifierFromString(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe {
CFLocaleCreateCanonicalLocaleIdentifierFromString(allocator, locale_identifier)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes")]
#[inline]
pub fn new_canonical_locale_identifier_from_script_manager_codes(
allocator: Option<&CFAllocator>,
lcode: LangCode,
rcode: RegionCode,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes(
allocator: Option<&CFAllocator>,
lcode: LangCode,
rcode: RegionCode,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe {
CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes(allocator, lcode, rcode)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCreateLocaleIdentifierFromWindowsLocaleCode")]
#[inline]
pub fn new_locale_identifier_from_windows_locale_code(
allocator: Option<&CFAllocator>,
lcid: u32,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateLocaleIdentifierFromWindowsLocaleCode(
allocator: Option<&CFAllocator>,
lcid: u32,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe { CFLocaleCreateLocaleIdentifierFromWindowsLocaleCode(allocator, lcid) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleGetWindowsLocaleCodeFromLocaleIdentifier")]
#[inline]
pub fn windows_locale_code_from_locale_identifier(
locale_identifier: Option<&CFLocaleIdentifier>,
) -> u32 {
extern "C-unwind" {
fn CFLocaleGetWindowsLocaleCodeFromLocaleIdentifier(
locale_identifier: Option<&CFLocaleIdentifier>,
) -> u32;
}
unsafe { CFLocaleGetWindowsLocaleCodeFromLocaleIdentifier(locale_identifier) }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cflocalelanguagedirection?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFLocaleLanguageDirection(pub CFIndex);
impl CFLocaleLanguageDirection {
#[doc(alias = "kCFLocaleLanguageDirectionUnknown")]
pub const Unknown: Self = Self(0);
#[doc(alias = "kCFLocaleLanguageDirectionLeftToRight")]
pub const LeftToRight: Self = Self(1);
#[doc(alias = "kCFLocaleLanguageDirectionRightToLeft")]
pub const RightToLeft: Self = Self(2);
#[doc(alias = "kCFLocaleLanguageDirectionTopToBottom")]
pub const TopToBottom: Self = Self(3);
#[doc(alias = "kCFLocaleLanguageDirectionBottomToTop")]
pub const BottomToTop: Self = Self(4);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFLocaleLanguageDirection {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFLocaleLanguageDirection {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFLocale {
#[doc(alias = "CFLocaleGetLanguageCharacterDirection")]
#[inline]
pub fn language_character_direction(
iso_lang_code: Option<&CFString>,
) -> CFLocaleLanguageDirection {
extern "C-unwind" {
fn CFLocaleGetLanguageCharacterDirection(
iso_lang_code: Option<&CFString>,
) -> CFLocaleLanguageDirection;
}
unsafe { CFLocaleGetLanguageCharacterDirection(iso_lang_code) }
}
#[doc(alias = "CFLocaleGetLanguageLineDirection")]
#[inline]
pub fn language_line_direction(iso_lang_code: Option<&CFString>) -> CFLocaleLanguageDirection {
extern "C-unwind" {
fn CFLocaleGetLanguageLineDirection(
iso_lang_code: Option<&CFString>,
) -> CFLocaleLanguageDirection;
}
unsafe { CFLocaleGetLanguageLineDirection(iso_lang_code) }
}
#[doc(alias = "CFLocaleCreateComponentsFromLocaleIdentifier")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub fn new_components_from_locale_identifier(
allocator: Option<&CFAllocator>,
locale_id: Option<&CFLocaleIdentifier>,
) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFLocaleCreateComponentsFromLocaleIdentifier(
allocator: Option<&CFAllocator>,
locale_id: Option<&CFLocaleIdentifier>,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFLocaleCreateComponentsFromLocaleIdentifier(allocator, locale_id) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCreateLocaleIdentifierFromComponents")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn new_locale_identifier_from_components(
allocator: Option<&CFAllocator>,
dictionary: Option<&CFDictionary>,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateLocaleIdentifierFromComponents(
allocator: Option<&CFAllocator>,
dictionary: Option<&CFDictionary>,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe { CFLocaleCreateLocaleIdentifierFromComponents(allocator, dictionary) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCreate")]
#[inline]
pub fn new(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFLocaleIdentifier>,
) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleCreate(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFLocaleIdentifier>,
) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleCreate(allocator, locale_identifier) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleCreateCopy")]
#[inline]
pub fn new_copy(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleCreateCopy(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleCreateCopy(allocator, locale) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFLocaleGetIdentifier")]
#[inline]
pub fn identifier(self: &CFLocale) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleGetIdentifier(locale: &CFLocale) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe { CFLocaleGetIdentifier(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFLocaleGetValue")]
#[inline]
pub fn value(self: &CFLocale, key: Option<&CFLocaleKey>) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFLocaleGetValue(
locale: &CFLocale,
key: Option<&CFLocaleKey>,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFLocaleGetValue(self, key) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFLocaleCopyDisplayNameForPropertyValue")]
#[inline]
pub fn display_name_for_property_value(
self: &CFLocale,
key: Option<&CFLocaleKey>,
value: Option<&CFString>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFLocaleCopyDisplayNameForPropertyValue(
display_locale: &CFLocale,
key: Option<&CFLocaleKey>,
value: Option<&CFString>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFLocaleCopyDisplayNameForPropertyValue(self, key, value) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecurrentlocaledidchangenotification?language=objc)
#[cfg(feature = "CFNotificationCenter")]
pub static kCFLocaleCurrentLocaleDidChangeNotification: Option<&'static CFNotificationName>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocaleidentifier?language=objc)
pub static kCFLocaleIdentifier: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalelanguagecode?language=objc)
pub static kCFLocaleLanguageCode: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecountrycode?language=objc)
pub static kCFLocaleCountryCode: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalescriptcode?language=objc)
pub static kCFLocaleScriptCode: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalevariantcode?language=objc)
pub static kCFLocaleVariantCode: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocaleexemplarcharacterset?language=objc)
pub static kCFLocaleExemplarCharacterSet: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecalendaridentifier?language=objc)
pub static kCFLocaleCalendarIdentifier: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecalendar?language=objc)
pub static kCFLocaleCalendar: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecollationidentifier?language=objc)
pub static kCFLocaleCollationIdentifier: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocaleusesmetricsystem?language=objc)
pub static kCFLocaleUsesMetricSystem: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalemeasurementsystem?language=objc)
pub static kCFLocaleMeasurementSystem: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocaledecimalseparator?language=objc)
pub static kCFLocaleDecimalSeparator: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalegroupingseparator?language=objc)
pub static kCFLocaleGroupingSeparator: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecurrencysymbol?language=objc)
pub static kCFLocaleCurrencySymbol: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecurrencycode?language=objc)
pub static kCFLocaleCurrencyCode: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalecollatoridentifier?language=objc)
pub static kCFLocaleCollatorIdentifier: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalequotationbegindelimiterkey?language=objc)
pub static kCFLocaleQuotationBeginDelimiterKey: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalequotationenddelimiterkey?language=objc)
pub static kCFLocaleQuotationEndDelimiterKey: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalealternatequotationbegindelimiterkey?language=objc)
pub static kCFLocaleAlternateQuotationBeginDelimiterKey: Option<&'static CFLocaleKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcflocalealternatequotationenddelimiterkey?language=objc)
pub static kCFLocaleAlternateQuotationEndDelimiterKey: Option<&'static CFLocaleKey>;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcalendaridentifier?language=objc)
// NS_TYPED_ENUM
pub type CFCalendarIdentifier = CFString;
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfgregoriancalendar?language=objc)
pub static kCFGregorianCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfbuddhistcalendar?language=objc)
pub static kCFBuddhistCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfchinesecalendar?language=objc)
pub static kCFChineseCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfhebrewcalendar?language=objc)
pub static kCFHebrewCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfislamiccalendar?language=objc)
pub static kCFIslamicCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfislamiccivilcalendar?language=objc)
pub static kCFIslamicCivilCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfjapanesecalendar?language=objc)
pub static kCFJapaneseCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfrepublicofchinacalendar?language=objc)
pub static kCFRepublicOfChinaCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpersiancalendar?language=objc)
pub static kCFPersianCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfindiancalendar?language=objc)
pub static kCFIndianCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfiso8601calendar?language=objc)
pub static kCFISO8601Calendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfislamictabularcalendar?language=objc)
pub static kCFIslamicTabularCalendar: Option<&'static CFCalendarIdentifier>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfislamicummalquracalendar?language=objc)
pub static kCFIslamicUmmAlQuraCalendar: Option<&'static CFCalendarIdentifier>;
}
#[deprecated = "renamed to `CFLocale::system`"]
#[inline]
pub extern "C-unwind" fn CFLocaleGetSystem() -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleGetSystem() -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleGetSystem() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFLocale::current`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyCurrent() -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleCopyCurrent() -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleCopyCurrent() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFLocale::available_locale_identifiers`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyAvailableLocaleIdentifiers() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyAvailableLocaleIdentifiers() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyAvailableLocaleIdentifiers() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFLocale::iso_language_codes`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyISOLanguageCodes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyISOLanguageCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyISOLanguageCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFLocale::iso_country_codes`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyISOCountryCodes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyISOCountryCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyISOCountryCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFLocale::iso_currency_codes`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyISOCurrencyCodes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyISOCurrencyCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyISOCurrencyCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFLocale::common_iso_currency_codes`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyCommonISOCurrencyCodes() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyCommonISOCurrencyCodes() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyCommonISOCurrencyCodes() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFLocale::preferred_languages`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyPreferredLanguages() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFLocaleCopyPreferredLanguages() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFLocaleCopyPreferredLanguages() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::new_canonical_language_identifier_from_string`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCreateCanonicalLanguageIdentifierFromString(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateCanonicalLanguageIdentifierFromString(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe {
CFLocaleCreateCanonicalLanguageIdentifierFromString(allocator, locale_identifier)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::new_canonical_locale_identifier_from_string`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCreateCanonicalLocaleIdentifierFromString(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateCanonicalLocaleIdentifierFromString(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFString>,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret =
unsafe { CFLocaleCreateCanonicalLocaleIdentifierFromString(allocator, locale_identifier) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::new_canonical_locale_identifier_from_script_manager_codes`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes(
allocator: Option<&CFAllocator>,
lcode: LangCode,
rcode: RegionCode,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes(
allocator: Option<&CFAllocator>,
lcode: LangCode,
rcode: RegionCode,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe {
CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes(allocator, lcode, rcode)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::new_locale_identifier_from_windows_locale_code`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCreateLocaleIdentifierFromWindowsLocaleCode(
allocator: Option<&CFAllocator>,
lcid: u32,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateLocaleIdentifierFromWindowsLocaleCode(
allocator: Option<&CFAllocator>,
lcid: u32,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe { CFLocaleCreateLocaleIdentifierFromWindowsLocaleCode(allocator, lcid) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::windows_locale_code_from_locale_identifier`"]
#[inline]
pub extern "C-unwind" fn CFLocaleGetWindowsLocaleCodeFromLocaleIdentifier(
locale_identifier: Option<&CFLocaleIdentifier>,
) -> u32 {
extern "C-unwind" {
fn CFLocaleGetWindowsLocaleCodeFromLocaleIdentifier(
locale_identifier: Option<&CFLocaleIdentifier>,
) -> u32;
}
unsafe { CFLocaleGetWindowsLocaleCodeFromLocaleIdentifier(locale_identifier) }
}
#[deprecated = "renamed to `CFLocale::language_character_direction`"]
#[inline]
pub extern "C-unwind" fn CFLocaleGetLanguageCharacterDirection(
iso_lang_code: Option<&CFString>,
) -> CFLocaleLanguageDirection {
extern "C-unwind" {
fn CFLocaleGetLanguageCharacterDirection(
iso_lang_code: Option<&CFString>,
) -> CFLocaleLanguageDirection;
}
unsafe { CFLocaleGetLanguageCharacterDirection(iso_lang_code) }
}
#[deprecated = "renamed to `CFLocale::language_line_direction`"]
#[inline]
pub extern "C-unwind" fn CFLocaleGetLanguageLineDirection(
iso_lang_code: Option<&CFString>,
) -> CFLocaleLanguageDirection {
extern "C-unwind" {
fn CFLocaleGetLanguageLineDirection(
iso_lang_code: Option<&CFString>,
) -> CFLocaleLanguageDirection;
}
unsafe { CFLocaleGetLanguageLineDirection(iso_lang_code) }
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFLocale::new_components_from_locale_identifier`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCreateComponentsFromLocaleIdentifier(
allocator: Option<&CFAllocator>,
locale_id: Option<&CFLocaleIdentifier>,
) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFLocaleCreateComponentsFromLocaleIdentifier(
allocator: Option<&CFAllocator>,
locale_id: Option<&CFLocaleIdentifier>,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFLocaleCreateComponentsFromLocaleIdentifier(allocator, locale_id) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFLocale::new_locale_identifier_from_components`"]
#[inline]
pub unsafe extern "C-unwind" fn CFLocaleCreateLocaleIdentifierFromComponents(
allocator: Option<&CFAllocator>,
dictionary: Option<&CFDictionary>,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleCreateLocaleIdentifierFromComponents(
allocator: Option<&CFAllocator>,
dictionary: Option<&CFDictionary>,
) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe { CFLocaleCreateLocaleIdentifierFromComponents(allocator, dictionary) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::new`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCreate(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFLocaleIdentifier>,
) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleCreate(
allocator: Option<&CFAllocator>,
locale_identifier: Option<&CFLocaleIdentifier>,
) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleCreate(allocator, locale_identifier) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::new_copy`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCreateCopy(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFLocaleCreateCopy(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFLocaleCreateCopy(allocator, locale) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFLocale::identifier`"]
#[inline]
pub extern "C-unwind" fn CFLocaleGetIdentifier(
locale: &CFLocale,
) -> Option<CFRetained<CFLocaleIdentifier>> {
extern "C-unwind" {
fn CFLocaleGetIdentifier(locale: &CFLocale) -> Option<NonNull<CFLocaleIdentifier>>;
}
let ret = unsafe { CFLocaleGetIdentifier(locale) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFLocale::value`"]
#[inline]
pub extern "C-unwind" fn CFLocaleGetValue(
locale: &CFLocale,
key: Option<&CFLocaleKey>,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFLocaleGetValue(
locale: &CFLocale,
key: Option<&CFLocaleKey>,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFLocaleGetValue(locale, key) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFLocale::display_name_for_property_value`"]
#[inline]
pub extern "C-unwind" fn CFLocaleCopyDisplayNameForPropertyValue(
display_locale: &CFLocale,
key: Option<&CFLocaleKey>,
value: Option<&CFString>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFLocaleCopyDisplayNameForPropertyValue(
display_locale: &CFLocale,
key: Option<&CFLocaleKey>,
value: Option<&CFString>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFLocaleCopyDisplayNameForPropertyValue(display_locale, key, value) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,321 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachport?language=objc)
#[repr(C)]
pub struct CFMachPort {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFMachPort {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFMachPort"> for CFMachPort {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachportcontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFMachPortContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFMachPortContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFMachPortContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachportcallback?language=objc)
pub type CFMachPortCallBack =
Option<unsafe extern "C-unwind" fn(*mut CFMachPort, *mut c_void, CFIndex, *mut c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmachportinvalidationcallback?language=objc)
pub type CFMachPortInvalidationCallBack =
Option<unsafe extern "C-unwind" fn(*mut CFMachPort, *mut c_void)>;
unsafe impl ConcreteType for CFMachPort {
#[doc(alias = "CFMachPortGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFMachPortGetTypeID() -> CFTypeID;
}
unsafe { CFMachPortGetTypeID() }
}
}
impl CFMachPort {
#[doc(alias = "CFMachPortCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<CFRetained<CFMachPort>> {
extern "C-unwind" {
fn CFMachPortCreate(
allocator: Option<&CFAllocator>,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<NonNull<CFMachPort>>;
}
let ret = unsafe { CFMachPortCreate(allocator, callout, context, should_free_info) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFMachPortCreateWithPort")]
#[cfg(feature = "libc")]
#[inline]
pub unsafe fn with_port(
allocator: Option<&CFAllocator>,
port_num: libc::mach_port_t,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<CFRetained<CFMachPort>> {
extern "C-unwind" {
fn CFMachPortCreateWithPort(
allocator: Option<&CFAllocator>,
port_num: libc::mach_port_t,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<NonNull<CFMachPort>>;
}
let ret = unsafe {
CFMachPortCreateWithPort(allocator, port_num, callout, context, should_free_info)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFMachPortGetPort")]
#[cfg(feature = "libc")]
#[inline]
pub fn port(self: &CFMachPort) -> libc::mach_port_t {
extern "C-unwind" {
fn CFMachPortGetPort(port: &CFMachPort) -> libc::mach_port_t;
}
unsafe { CFMachPortGetPort(self) }
}
#[doc(alias = "CFMachPortGetContext")]
#[inline]
pub unsafe fn context(self: &CFMachPort, context: *mut CFMachPortContext) {
extern "C-unwind" {
fn CFMachPortGetContext(port: &CFMachPort, context: *mut CFMachPortContext);
}
unsafe { CFMachPortGetContext(self, context) }
}
#[doc(alias = "CFMachPortInvalidate")]
#[inline]
pub fn invalidate(self: &CFMachPort) {
extern "C-unwind" {
fn CFMachPortInvalidate(port: &CFMachPort);
}
unsafe { CFMachPortInvalidate(self) }
}
#[doc(alias = "CFMachPortIsValid")]
#[inline]
pub fn is_valid(self: &CFMachPort) -> bool {
extern "C-unwind" {
fn CFMachPortIsValid(port: &CFMachPort) -> Boolean;
}
let ret = unsafe { CFMachPortIsValid(self) };
ret != 0
}
#[doc(alias = "CFMachPortGetInvalidationCallBack")]
#[inline]
pub fn invalidation_call_back(self: &CFMachPort) -> CFMachPortInvalidationCallBack {
extern "C-unwind" {
fn CFMachPortGetInvalidationCallBack(
port: &CFMachPort,
) -> CFMachPortInvalidationCallBack;
}
unsafe { CFMachPortGetInvalidationCallBack(self) }
}
#[doc(alias = "CFMachPortSetInvalidationCallBack")]
#[inline]
pub unsafe fn set_invalidation_call_back(
self: &CFMachPort,
callout: CFMachPortInvalidationCallBack,
) {
extern "C-unwind" {
fn CFMachPortSetInvalidationCallBack(
port: &CFMachPort,
callout: CFMachPortInvalidationCallBack,
);
}
unsafe { CFMachPortSetInvalidationCallBack(self, callout) }
}
#[doc(alias = "CFMachPortCreateRunLoopSource")]
#[cfg(feature = "CFRunLoop")]
#[inline]
pub fn new_run_loop_source(
allocator: Option<&CFAllocator>,
port: Option<&CFMachPort>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFMachPortCreateRunLoopSource(
allocator: Option<&CFAllocator>,
port: Option<&CFMachPort>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFMachPortCreateRunLoopSource(allocator, port, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
#[deprecated = "renamed to `CFMachPort::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFMachPortCreate(
allocator: Option<&CFAllocator>,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<CFRetained<CFMachPort>> {
extern "C-unwind" {
fn CFMachPortCreate(
allocator: Option<&CFAllocator>,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<NonNull<CFMachPort>>;
}
let ret = unsafe { CFMachPortCreate(allocator, callout, context, should_free_info) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFMachPort::with_port`"]
#[inline]
pub unsafe extern "C-unwind" fn CFMachPortCreateWithPort(
allocator: Option<&CFAllocator>,
port_num: libc::mach_port_t,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<CFRetained<CFMachPort>> {
extern "C-unwind" {
fn CFMachPortCreateWithPort(
allocator: Option<&CFAllocator>,
port_num: libc::mach_port_t,
callout: CFMachPortCallBack,
context: *mut CFMachPortContext,
should_free_info: *mut Boolean,
) -> Option<NonNull<CFMachPort>>;
}
let ret = unsafe {
CFMachPortCreateWithPort(allocator, port_num, callout, context, should_free_info)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `CFMachPort::port`"]
#[inline]
pub extern "C-unwind" fn CFMachPortGetPort(port: &CFMachPort) -> libc::mach_port_t {
extern "C-unwind" {
fn CFMachPortGetPort(port: &CFMachPort) -> libc::mach_port_t;
}
unsafe { CFMachPortGetPort(port) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMachPort::context`"]
pub fn CFMachPortGetContext(port: &CFMachPort, context: *mut CFMachPortContext);
}
#[deprecated = "renamed to `CFMachPort::invalidate`"]
#[inline]
pub extern "C-unwind" fn CFMachPortInvalidate(port: &CFMachPort) {
extern "C-unwind" {
fn CFMachPortInvalidate(port: &CFMachPort);
}
unsafe { CFMachPortInvalidate(port) }
}
#[deprecated = "renamed to `CFMachPort::is_valid`"]
#[inline]
pub extern "C-unwind" fn CFMachPortIsValid(port: &CFMachPort) -> bool {
extern "C-unwind" {
fn CFMachPortIsValid(port: &CFMachPort) -> Boolean;
}
let ret = unsafe { CFMachPortIsValid(port) };
ret != 0
}
#[deprecated = "renamed to `CFMachPort::invalidation_call_back`"]
#[inline]
pub extern "C-unwind" fn CFMachPortGetInvalidationCallBack(
port: &CFMachPort,
) -> CFMachPortInvalidationCallBack {
extern "C-unwind" {
fn CFMachPortGetInvalidationCallBack(port: &CFMachPort) -> CFMachPortInvalidationCallBack;
}
unsafe { CFMachPortGetInvalidationCallBack(port) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMachPort::set_invalidation_call_back`"]
pub fn CFMachPortSetInvalidationCallBack(
port: &CFMachPort,
callout: CFMachPortInvalidationCallBack,
);
}
#[cfg(feature = "CFRunLoop")]
#[deprecated = "renamed to `CFMachPort::new_run_loop_source`"]
#[inline]
pub extern "C-unwind" fn CFMachPortCreateRunLoopSource(
allocator: Option<&CFAllocator>,
port: Option<&CFMachPort>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFMachPortCreateRunLoopSource(
allocator: Option<&CFAllocator>,
port: Option<&CFMachPort>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFMachPortCreateRunLoopSource(allocator, port, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,445 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "dispatch2")]
use dispatch2::*;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmessageport?language=objc)
#[repr(C)]
pub struct CFMessagePort {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFMessagePort {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFMessagePort"> for CFMessagePort {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfmessageportsuccess?language=objc)
pub const kCFMessagePortSuccess: i32 = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfmessageportsendtimeout?language=objc)
pub const kCFMessagePortSendTimeout: i32 = -1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfmessageportreceivetimeout?language=objc)
pub const kCFMessagePortReceiveTimeout: i32 = -2;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfmessageportisinvalid?language=objc)
pub const kCFMessagePortIsInvalid: i32 = -3;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfmessageporttransporterror?language=objc)
pub const kCFMessagePortTransportError: i32 = -4;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfmessageportbecameinvaliderror?language=objc)
pub const kCFMessagePortBecameInvalidError: i32 = -5;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmessageportcontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFMessagePortContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFMessagePortContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFMessagePortContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmessageportcallback?language=objc)
#[cfg(feature = "CFData")]
pub type CFMessagePortCallBack = Option<
unsafe extern "C-unwind" fn(
*mut CFMessagePort,
i32,
*const CFData,
*mut c_void,
) -> *const CFData,
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmessageportinvalidationcallback?language=objc)
pub type CFMessagePortInvalidationCallBack =
Option<unsafe extern "C-unwind" fn(*mut CFMessagePort, *mut c_void)>;
unsafe impl ConcreteType for CFMessagePort {
#[doc(alias = "CFMessagePortGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFMessagePortGetTypeID() -> CFTypeID;
}
unsafe { CFMessagePortGetTypeID() }
}
}
impl CFMessagePort {
#[doc(alias = "CFMessagePortCreateLocal")]
#[cfg(feature = "CFData")]
#[inline]
pub unsafe fn new_local(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
callout: CFMessagePortCallBack,
context: *mut CFMessagePortContext,
should_free_info: *mut Boolean,
) -> Option<CFRetained<CFMessagePort>> {
extern "C-unwind" {
fn CFMessagePortCreateLocal(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
callout: CFMessagePortCallBack,
context: *mut CFMessagePortContext,
should_free_info: *mut Boolean,
) -> Option<NonNull<CFMessagePort>>;
}
let ret = unsafe {
CFMessagePortCreateLocal(allocator, name, callout, context, should_free_info)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFMessagePortCreateRemote")]
#[inline]
pub fn new_remote(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
) -> Option<CFRetained<CFMessagePort>> {
extern "C-unwind" {
fn CFMessagePortCreateRemote(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
) -> Option<NonNull<CFMessagePort>>;
}
let ret = unsafe { CFMessagePortCreateRemote(allocator, name) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFMessagePortIsRemote")]
#[inline]
pub fn is_remote(self: &CFMessagePort) -> bool {
extern "C-unwind" {
fn CFMessagePortIsRemote(ms: &CFMessagePort) -> Boolean;
}
let ret = unsafe { CFMessagePortIsRemote(self) };
ret != 0
}
#[doc(alias = "CFMessagePortGetName")]
#[inline]
pub fn name(self: &CFMessagePort) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFMessagePortGetName(ms: &CFMessagePort) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFMessagePortGetName(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFMessagePortSetName")]
#[inline]
pub fn set_name(self: &CFMessagePort, new_name: Option<&CFString>) -> bool {
extern "C-unwind" {
fn CFMessagePortSetName(ms: &CFMessagePort, new_name: Option<&CFString>) -> Boolean;
}
let ret = unsafe { CFMessagePortSetName(self, new_name) };
ret != 0
}
#[doc(alias = "CFMessagePortGetContext")]
#[inline]
pub unsafe fn context(self: &CFMessagePort, context: *mut CFMessagePortContext) {
extern "C-unwind" {
fn CFMessagePortGetContext(ms: &CFMessagePort, context: *mut CFMessagePortContext);
}
unsafe { CFMessagePortGetContext(self, context) }
}
#[doc(alias = "CFMessagePortInvalidate")]
#[inline]
pub fn invalidate(self: &CFMessagePort) {
extern "C-unwind" {
fn CFMessagePortInvalidate(ms: &CFMessagePort);
}
unsafe { CFMessagePortInvalidate(self) }
}
#[doc(alias = "CFMessagePortIsValid")]
#[inline]
pub fn is_valid(self: &CFMessagePort) -> bool {
extern "C-unwind" {
fn CFMessagePortIsValid(ms: &CFMessagePort) -> Boolean;
}
let ret = unsafe { CFMessagePortIsValid(self) };
ret != 0
}
#[doc(alias = "CFMessagePortGetInvalidationCallBack")]
#[inline]
pub fn invalidation_call_back(self: &CFMessagePort) -> CFMessagePortInvalidationCallBack {
extern "C-unwind" {
fn CFMessagePortGetInvalidationCallBack(
ms: &CFMessagePort,
) -> CFMessagePortInvalidationCallBack;
}
unsafe { CFMessagePortGetInvalidationCallBack(self) }
}
#[doc(alias = "CFMessagePortSetInvalidationCallBack")]
#[inline]
pub unsafe fn set_invalidation_call_back(
self: &CFMessagePort,
callout: CFMessagePortInvalidationCallBack,
) {
extern "C-unwind" {
fn CFMessagePortSetInvalidationCallBack(
ms: &CFMessagePort,
callout: CFMessagePortInvalidationCallBack,
);
}
unsafe { CFMessagePortSetInvalidationCallBack(self, callout) }
}
#[doc(alias = "CFMessagePortSendRequest")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn send_request(
self: &CFMessagePort,
msgid: i32,
data: Option<&CFData>,
send_timeout: CFTimeInterval,
rcv_timeout: CFTimeInterval,
reply_mode: Option<&CFString>,
return_data: *mut *const CFData,
) -> i32 {
extern "C-unwind" {
fn CFMessagePortSendRequest(
remote: &CFMessagePort,
msgid: i32,
data: Option<&CFData>,
send_timeout: CFTimeInterval,
rcv_timeout: CFTimeInterval,
reply_mode: Option<&CFString>,
return_data: *mut *const CFData,
) -> i32;
}
unsafe {
CFMessagePortSendRequest(
self,
msgid,
data,
send_timeout,
rcv_timeout,
reply_mode,
return_data,
)
}
}
#[doc(alias = "CFMessagePortCreateRunLoopSource")]
#[cfg(feature = "CFRunLoop")]
#[inline]
pub fn new_run_loop_source(
allocator: Option<&CFAllocator>,
local: Option<&CFMessagePort>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFMessagePortCreateRunLoopSource(
allocator: Option<&CFAllocator>,
local: Option<&CFMessagePort>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFMessagePortCreateRunLoopSource(allocator, local, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFMessagePortSetDispatchQueue")]
#[cfg(feature = "dispatch2")]
#[inline]
pub unsafe fn set_dispatch_queue(self: &CFMessagePort, queue: Option<&DispatchQueue>) {
extern "C-unwind" {
fn CFMessagePortSetDispatchQueue(ms: &CFMessagePort, queue: Option<&DispatchQueue>);
}
unsafe { CFMessagePortSetDispatchQueue(self, queue) }
}
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFMessagePort::new_local`"]
#[inline]
pub unsafe extern "C-unwind" fn CFMessagePortCreateLocal(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
callout: CFMessagePortCallBack,
context: *mut CFMessagePortContext,
should_free_info: *mut Boolean,
) -> Option<CFRetained<CFMessagePort>> {
extern "C-unwind" {
fn CFMessagePortCreateLocal(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
callout: CFMessagePortCallBack,
context: *mut CFMessagePortContext,
should_free_info: *mut Boolean,
) -> Option<NonNull<CFMessagePort>>;
}
let ret =
unsafe { CFMessagePortCreateLocal(allocator, name, callout, context, should_free_info) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMessagePort::new_remote`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortCreateRemote(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
) -> Option<CFRetained<CFMessagePort>> {
extern "C-unwind" {
fn CFMessagePortCreateRemote(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
) -> Option<NonNull<CFMessagePort>>;
}
let ret = unsafe { CFMessagePortCreateRemote(allocator, name) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMessagePort::is_remote`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortIsRemote(ms: &CFMessagePort) -> bool {
extern "C-unwind" {
fn CFMessagePortIsRemote(ms: &CFMessagePort) -> Boolean;
}
let ret = unsafe { CFMessagePortIsRemote(ms) };
ret != 0
}
#[deprecated = "renamed to `CFMessagePort::name`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortGetName(ms: &CFMessagePort) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFMessagePortGetName(ms: &CFMessagePort) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFMessagePortGetName(ms) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFMessagePort::set_name`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortSetName(
ms: &CFMessagePort,
new_name: Option<&CFString>,
) -> bool {
extern "C-unwind" {
fn CFMessagePortSetName(ms: &CFMessagePort, new_name: Option<&CFString>) -> Boolean;
}
let ret = unsafe { CFMessagePortSetName(ms, new_name) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMessagePort::context`"]
pub fn CFMessagePortGetContext(ms: &CFMessagePort, context: *mut CFMessagePortContext);
}
#[deprecated = "renamed to `CFMessagePort::invalidate`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortInvalidate(ms: &CFMessagePort) {
extern "C-unwind" {
fn CFMessagePortInvalidate(ms: &CFMessagePort);
}
unsafe { CFMessagePortInvalidate(ms) }
}
#[deprecated = "renamed to `CFMessagePort::is_valid`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortIsValid(ms: &CFMessagePort) -> bool {
extern "C-unwind" {
fn CFMessagePortIsValid(ms: &CFMessagePort) -> Boolean;
}
let ret = unsafe { CFMessagePortIsValid(ms) };
ret != 0
}
#[deprecated = "renamed to `CFMessagePort::invalidation_call_back`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortGetInvalidationCallBack(
ms: &CFMessagePort,
) -> CFMessagePortInvalidationCallBack {
extern "C-unwind" {
fn CFMessagePortGetInvalidationCallBack(
ms: &CFMessagePort,
) -> CFMessagePortInvalidationCallBack;
}
unsafe { CFMessagePortGetInvalidationCallBack(ms) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMessagePort::set_invalidation_call_back`"]
pub fn CFMessagePortSetInvalidationCallBack(
ms: &CFMessagePort,
callout: CFMessagePortInvalidationCallBack,
);
}
extern "C-unwind" {
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFMessagePort::send_request`"]
pub fn CFMessagePortSendRequest(
remote: &CFMessagePort,
msgid: i32,
data: Option<&CFData>,
send_timeout: CFTimeInterval,
rcv_timeout: CFTimeInterval,
reply_mode: Option<&CFString>,
return_data: *mut *const CFData,
) -> i32;
}
#[cfg(feature = "CFRunLoop")]
#[deprecated = "renamed to `CFMessagePort::new_run_loop_source`"]
#[inline]
pub extern "C-unwind" fn CFMessagePortCreateRunLoopSource(
allocator: Option<&CFAllocator>,
local: Option<&CFMessagePort>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFMessagePortCreateRunLoopSource(
allocator: Option<&CFAllocator>,
local: Option<&CFMessagePort>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFMessagePortCreateRunLoopSource(allocator, local, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[cfg(feature = "dispatch2")]
#[deprecated = "renamed to `CFMessagePort::set_dispatch_queue`"]
pub fn CFMessagePortSetDispatchQueue(ms: &CFMessagePort, queue: Option<&DispatchQueue>);
}

View File

@@ -0,0 +1,341 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnotificationname?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type CFNotificationName = CFString;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnotificationcenter?language=objc)
#[repr(C)]
pub struct CFNotificationCenter {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFNotificationCenter {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFNotificationCenter"> for CFNotificationCenter {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnotificationcallback?language=objc)
#[cfg(feature = "CFDictionary")]
pub type CFNotificationCallback = Option<
unsafe extern "C-unwind" fn(
*mut CFNotificationCenter,
*mut c_void,
*const CFNotificationName,
*const c_void,
*const CFDictionary,
),
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnotificationsuspensionbehavior?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFNotificationSuspensionBehavior(pub CFIndex);
impl CFNotificationSuspensionBehavior {
#[doc(alias = "CFNotificationSuspensionBehaviorDrop")]
pub const Drop: Self = Self(1);
#[doc(alias = "CFNotificationSuspensionBehaviorCoalesce")]
pub const Coalesce: Self = Self(2);
#[doc(alias = "CFNotificationSuspensionBehaviorHold")]
pub const Hold: Self = Self(3);
#[doc(alias = "CFNotificationSuspensionBehaviorDeliverImmediately")]
pub const DeliverImmediately: Self = Self(4);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFNotificationSuspensionBehavior {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFNotificationSuspensionBehavior {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFNotificationCenter {
#[doc(alias = "CFNotificationCenterGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFNotificationCenterGetTypeID() -> CFTypeID;
}
unsafe { CFNotificationCenterGetTypeID() }
}
}
impl CFNotificationCenter {
#[doc(alias = "CFNotificationCenterGetLocalCenter")]
#[inline]
pub fn local_center() -> Option<CFRetained<CFNotificationCenter>> {
extern "C-unwind" {
fn CFNotificationCenterGetLocalCenter() -> Option<NonNull<CFNotificationCenter>>;
}
let ret = unsafe { CFNotificationCenterGetLocalCenter() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFNotificationCenterGetDistributedCenter")]
#[inline]
pub fn distributed_center() -> Option<CFRetained<CFNotificationCenter>> {
extern "C-unwind" {
fn CFNotificationCenterGetDistributedCenter() -> Option<NonNull<CFNotificationCenter>>;
}
let ret = unsafe { CFNotificationCenterGetDistributedCenter() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFNotificationCenterGetDarwinNotifyCenter")]
#[inline]
pub fn darwin_notify_center() -> Option<CFRetained<CFNotificationCenter>> {
extern "C-unwind" {
fn CFNotificationCenterGetDarwinNotifyCenter() -> Option<NonNull<CFNotificationCenter>>;
}
let ret = unsafe { CFNotificationCenterGetDarwinNotifyCenter() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFNotificationCenterAddObserver")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn add_observer(
self: &CFNotificationCenter,
observer: *const c_void,
call_back: CFNotificationCallback,
name: Option<&CFString>,
object: *const c_void,
suspension_behavior: CFNotificationSuspensionBehavior,
) {
extern "C-unwind" {
fn CFNotificationCenterAddObserver(
center: &CFNotificationCenter,
observer: *const c_void,
call_back: CFNotificationCallback,
name: Option<&CFString>,
object: *const c_void,
suspension_behavior: CFNotificationSuspensionBehavior,
);
}
unsafe {
CFNotificationCenterAddObserver(
self,
observer,
call_back,
name,
object,
suspension_behavior,
)
}
}
#[doc(alias = "CFNotificationCenterRemoveObserver")]
#[inline]
pub unsafe fn remove_observer(
self: &CFNotificationCenter,
observer: *const c_void,
name: Option<&CFNotificationName>,
object: *const c_void,
) {
extern "C-unwind" {
fn CFNotificationCenterRemoveObserver(
center: &CFNotificationCenter,
observer: *const c_void,
name: Option<&CFNotificationName>,
object: *const c_void,
);
}
unsafe { CFNotificationCenterRemoveObserver(self, observer, name, object) }
}
#[doc(alias = "CFNotificationCenterRemoveEveryObserver")]
#[inline]
pub unsafe fn remove_every_observer(self: &CFNotificationCenter, observer: *const c_void) {
extern "C-unwind" {
fn CFNotificationCenterRemoveEveryObserver(
center: &CFNotificationCenter,
observer: *const c_void,
);
}
unsafe { CFNotificationCenterRemoveEveryObserver(self, observer) }
}
#[doc(alias = "CFNotificationCenterPostNotification")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn post_notification(
self: &CFNotificationCenter,
name: Option<&CFNotificationName>,
object: *const c_void,
user_info: Option<&CFDictionary>,
deliver_immediately: bool,
) {
extern "C-unwind" {
fn CFNotificationCenterPostNotification(
center: &CFNotificationCenter,
name: Option<&CFNotificationName>,
object: *const c_void,
user_info: Option<&CFDictionary>,
deliver_immediately: Boolean,
);
}
unsafe {
CFNotificationCenterPostNotification(
self,
name,
object,
user_info,
deliver_immediately as _,
)
}
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnotificationdeliverimmediately?language=objc)
pub const kCFNotificationDeliverImmediately: CFOptionFlags = 1 << 0;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnotificationposttoallsessions?language=objc)
pub const kCFNotificationPostToAllSessions: CFOptionFlags = 1 << 1;
impl CFNotificationCenter {
#[doc(alias = "CFNotificationCenterPostNotificationWithOptions")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn post_notification_with_options(
self: &CFNotificationCenter,
name: Option<&CFNotificationName>,
object: *const c_void,
user_info: Option<&CFDictionary>,
options: CFOptionFlags,
) {
extern "C-unwind" {
fn CFNotificationCenterPostNotificationWithOptions(
center: &CFNotificationCenter,
name: Option<&CFNotificationName>,
object: *const c_void,
user_info: Option<&CFDictionary>,
options: CFOptionFlags,
);
}
unsafe {
CFNotificationCenterPostNotificationWithOptions(self, name, object, user_info, options)
}
}
}
#[deprecated = "renamed to `CFNotificationCenter::local_center`"]
#[inline]
pub extern "C-unwind" fn CFNotificationCenterGetLocalCenter(
) -> Option<CFRetained<CFNotificationCenter>> {
extern "C-unwind" {
fn CFNotificationCenterGetLocalCenter() -> Option<NonNull<CFNotificationCenter>>;
}
let ret = unsafe { CFNotificationCenterGetLocalCenter() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFNotificationCenter::distributed_center`"]
#[inline]
pub extern "C-unwind" fn CFNotificationCenterGetDistributedCenter(
) -> Option<CFRetained<CFNotificationCenter>> {
extern "C-unwind" {
fn CFNotificationCenterGetDistributedCenter() -> Option<NonNull<CFNotificationCenter>>;
}
let ret = unsafe { CFNotificationCenterGetDistributedCenter() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFNotificationCenter::darwin_notify_center`"]
#[inline]
pub extern "C-unwind" fn CFNotificationCenterGetDarwinNotifyCenter(
) -> Option<CFRetained<CFNotificationCenter>> {
extern "C-unwind" {
fn CFNotificationCenterGetDarwinNotifyCenter() -> Option<NonNull<CFNotificationCenter>>;
}
let ret = unsafe { CFNotificationCenterGetDarwinNotifyCenter() };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFNotificationCenter::add_observer`"]
pub fn CFNotificationCenterAddObserver(
center: &CFNotificationCenter,
observer: *const c_void,
call_back: CFNotificationCallback,
name: Option<&CFString>,
object: *const c_void,
suspension_behavior: CFNotificationSuspensionBehavior,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFNotificationCenter::remove_observer`"]
pub fn CFNotificationCenterRemoveObserver(
center: &CFNotificationCenter,
observer: *const c_void,
name: Option<&CFNotificationName>,
object: *const c_void,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFNotificationCenter::remove_every_observer`"]
pub fn CFNotificationCenterRemoveEveryObserver(
center: &CFNotificationCenter,
observer: *const c_void,
);
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFNotificationCenter::post_notification`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNotificationCenterPostNotification(
center: &CFNotificationCenter,
name: Option<&CFNotificationName>,
object: *const c_void,
user_info: Option<&CFDictionary>,
deliver_immediately: bool,
) {
extern "C-unwind" {
fn CFNotificationCenterPostNotification(
center: &CFNotificationCenter,
name: Option<&CFNotificationName>,
object: *const c_void,
user_info: Option<&CFDictionary>,
deliver_immediately: Boolean,
);
}
unsafe {
CFNotificationCenterPostNotification(
center,
name,
object,
user_info,
deliver_immediately as _,
)
}
}
extern "C-unwind" {
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFNotificationCenter::post_notification_with_options`"]
pub fn CFNotificationCenterPostNotificationWithOptions(
center: &CFNotificationCenter,
name: Option<&CFNotificationName>,
object: *const c_void,
user_info: Option<&CFDictionary>,
options: CFOptionFlags,
);
}

View File

@@ -0,0 +1,313 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfboolean?language=objc)
#[repr(C)]
pub struct CFBoolean {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFBoolean {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFBoolean"> for CFBoolean {}
);
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfbooleantrue?language=objc)
pub static kCFBooleanTrue: Option<&'static CFBoolean>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfbooleanfalse?language=objc)
pub static kCFBooleanFalse: Option<&'static CFBoolean>;
}
unsafe impl ConcreteType for CFBoolean {
#[doc(alias = "CFBooleanGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFBooleanGetTypeID() -> CFTypeID;
}
unsafe { CFBooleanGetTypeID() }
}
}
impl CFBoolean {
#[doc(alias = "CFBooleanGetValue")]
#[inline]
pub fn value(self: &CFBoolean) -> bool {
extern "C-unwind" {
fn CFBooleanGetValue(boolean: &CFBoolean) -> Boolean;
}
let ret = unsafe { CFBooleanGetValue(self) };
ret != 0
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumbertype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFNumberType(pub CFIndex);
impl CFNumberType {
#[doc(alias = "kCFNumberSInt8Type")]
pub const SInt8Type: Self = Self(1);
#[doc(alias = "kCFNumberSInt16Type")]
pub const SInt16Type: Self = Self(2);
#[doc(alias = "kCFNumberSInt32Type")]
pub const SInt32Type: Self = Self(3);
#[doc(alias = "kCFNumberSInt64Type")]
pub const SInt64Type: Self = Self(4);
#[doc(alias = "kCFNumberFloat32Type")]
pub const Float32Type: Self = Self(5);
#[doc(alias = "kCFNumberFloat64Type")]
pub const Float64Type: Self = Self(6);
#[doc(alias = "kCFNumberCharType")]
pub const CharType: Self = Self(7);
#[doc(alias = "kCFNumberShortType")]
pub const ShortType: Self = Self(8);
#[doc(alias = "kCFNumberIntType")]
pub const IntType: Self = Self(9);
#[doc(alias = "kCFNumberLongType")]
pub const LongType: Self = Self(10);
#[doc(alias = "kCFNumberLongLongType")]
pub const LongLongType: Self = Self(11);
#[doc(alias = "kCFNumberFloatType")]
pub const FloatType: Self = Self(12);
#[doc(alias = "kCFNumberDoubleType")]
pub const DoubleType: Self = Self(13);
#[doc(alias = "kCFNumberCFIndexType")]
pub const CFIndexType: Self = Self(14);
#[doc(alias = "kCFNumberNSIntegerType")]
pub const NSIntegerType: Self = Self(15);
#[doc(alias = "kCFNumberCGFloatType")]
pub const CGFloatType: Self = Self(16);
#[doc(alias = "kCFNumberMaxType")]
pub const MaxType: Self = Self(16);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFNumberType {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFNumberType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumber?language=objc)
#[repr(C)]
pub struct CFNumber {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFNumber {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFNumber"> for CFNumber {}
);
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberpositiveinfinity?language=objc)
pub static kCFNumberPositiveInfinity: Option<&'static CFNumber>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumbernegativeinfinity?language=objc)
pub static kCFNumberNegativeInfinity: Option<&'static CFNumber>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumbernan?language=objc)
pub static kCFNumberNaN: Option<&'static CFNumber>;
}
unsafe impl ConcreteType for CFNumber {
#[doc(alias = "CFNumberGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFNumberGetTypeID() -> CFTypeID;
}
unsafe { CFNumberGetTypeID() }
}
}
impl CFNumber {
#[doc(alias = "CFNumberCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
the_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<CFRetained<CFNumber>> {
extern "C-unwind" {
fn CFNumberCreate(
allocator: Option<&CFAllocator>,
the_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<NonNull<CFNumber>>;
}
let ret = unsafe { CFNumberCreate(allocator, the_type, value_ptr) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFNumberGetType")]
#[inline]
pub fn r#type(self: &CFNumber) -> CFNumberType {
extern "C-unwind" {
fn CFNumberGetType(number: &CFNumber) -> CFNumberType;
}
unsafe { CFNumberGetType(self) }
}
#[doc(alias = "CFNumberGetByteSize")]
#[inline]
pub fn byte_size(self: &CFNumber) -> CFIndex {
extern "C-unwind" {
fn CFNumberGetByteSize(number: &CFNumber) -> CFIndex;
}
unsafe { CFNumberGetByteSize(self) }
}
#[doc(alias = "CFNumberIsFloatType")]
#[inline]
pub fn is_float_type(self: &CFNumber) -> bool {
extern "C-unwind" {
fn CFNumberIsFloatType(number: &CFNumber) -> Boolean;
}
let ret = unsafe { CFNumberIsFloatType(self) };
ret != 0
}
#[doc(alias = "CFNumberGetValue")]
#[inline]
pub unsafe fn value(self: &CFNumber, the_type: CFNumberType, value_ptr: *mut c_void) -> bool {
extern "C-unwind" {
fn CFNumberGetValue(
number: &CFNumber,
the_type: CFNumberType,
value_ptr: *mut c_void,
) -> Boolean;
}
let ret = unsafe { CFNumberGetValue(self, the_type, value_ptr) };
ret != 0
}
#[doc(alias = "CFNumberCompare")]
#[inline]
pub unsafe fn compare(
self: &CFNumber,
other_number: Option<&CFNumber>,
context: *mut c_void,
) -> CFComparisonResult {
extern "C-unwind" {
fn CFNumberCompare(
number: &CFNumber,
other_number: Option<&CFNumber>,
context: *mut c_void,
) -> CFComparisonResult;
}
unsafe { CFNumberCompare(self, other_number, context) }
}
}
#[deprecated = "renamed to `CFBoolean::value`"]
#[inline]
pub extern "C-unwind" fn CFBooleanGetValue(boolean: &CFBoolean) -> bool {
extern "C-unwind" {
fn CFBooleanGetValue(boolean: &CFBoolean) -> Boolean;
}
let ret = unsafe { CFBooleanGetValue(boolean) };
ret != 0
}
#[deprecated = "renamed to `CFNumber::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberCreate(
allocator: Option<&CFAllocator>,
the_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<CFRetained<CFNumber>> {
extern "C-unwind" {
fn CFNumberCreate(
allocator: Option<&CFAllocator>,
the_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<NonNull<CFNumber>>;
}
let ret = unsafe { CFNumberCreate(allocator, the_type, value_ptr) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFNumber::type`"]
#[inline]
pub extern "C-unwind" fn CFNumberGetType(number: &CFNumber) -> CFNumberType {
extern "C-unwind" {
fn CFNumberGetType(number: &CFNumber) -> CFNumberType;
}
unsafe { CFNumberGetType(number) }
}
#[deprecated = "renamed to `CFNumber::byte_size`"]
#[inline]
pub extern "C-unwind" fn CFNumberGetByteSize(number: &CFNumber) -> CFIndex {
extern "C-unwind" {
fn CFNumberGetByteSize(number: &CFNumber) -> CFIndex;
}
unsafe { CFNumberGetByteSize(number) }
}
#[deprecated = "renamed to `CFNumber::is_float_type`"]
#[inline]
pub extern "C-unwind" fn CFNumberIsFloatType(number: &CFNumber) -> bool {
extern "C-unwind" {
fn CFNumberIsFloatType(number: &CFNumber) -> Boolean;
}
let ret = unsafe { CFNumberIsFloatType(number) };
ret != 0
}
#[deprecated = "renamed to `CFNumber::value`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberGetValue(
number: &CFNumber,
the_type: CFNumberType,
value_ptr: *mut c_void,
) -> bool {
extern "C-unwind" {
fn CFNumberGetValue(
number: &CFNumber,
the_type: CFNumberType,
value_ptr: *mut c_void,
) -> Boolean;
}
let ret = unsafe { CFNumberGetValue(number, the_type, value_ptr) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFNumber::compare`"]
pub fn CFNumberCompare(
number: &CFNumber,
other_number: Option<&CFNumber>,
context: *mut c_void,
) -> CFComparisonResult;
}

View File

@@ -0,0 +1,771 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterkey?language=objc)
// NS_TYPED_ENUM
pub type CFNumberFormatterKey = CFString;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatter?language=objc)
#[repr(C)]
pub struct CFNumberFormatter {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFNumberFormatter {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFNumberFormatter"> for CFNumberFormatter {}
);
unsafe impl ConcreteType for CFNumberFormatter {
#[doc(alias = "CFNumberFormatterGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFNumberFormatterGetTypeID() -> CFTypeID;
}
unsafe { CFNumberFormatterGetTypeID() }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterstyle?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFNumberFormatterStyle(pub CFIndex);
impl CFNumberFormatterStyle {
#[doc(alias = "kCFNumberFormatterNoStyle")]
pub const NoStyle: Self = Self(0);
#[doc(alias = "kCFNumberFormatterDecimalStyle")]
pub const DecimalStyle: Self = Self(1);
#[doc(alias = "kCFNumberFormatterCurrencyStyle")]
pub const CurrencyStyle: Self = Self(2);
#[doc(alias = "kCFNumberFormatterPercentStyle")]
pub const PercentStyle: Self = Self(3);
#[doc(alias = "kCFNumberFormatterScientificStyle")]
pub const ScientificStyle: Self = Self(4);
#[doc(alias = "kCFNumberFormatterSpellOutStyle")]
pub const SpellOutStyle: Self = Self(5);
#[doc(alias = "kCFNumberFormatterOrdinalStyle")]
pub const OrdinalStyle: Self = Self(6);
#[doc(alias = "kCFNumberFormatterCurrencyISOCodeStyle")]
pub const CurrencyISOCodeStyle: Self = Self(8);
#[doc(alias = "kCFNumberFormatterCurrencyPluralStyle")]
pub const CurrencyPluralStyle: Self = Self(9);
#[doc(alias = "kCFNumberFormatterCurrencyAccountingStyle")]
pub const CurrencyAccountingStyle: Self = Self(10);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFNumberFormatterStyle {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFNumberFormatterStyle {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFNumberFormatter {
#[doc(alias = "CFNumberFormatterCreate")]
#[cfg(feature = "CFLocale")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
style: CFNumberFormatterStyle,
) -> Option<CFRetained<CFNumberFormatter>> {
extern "C-unwind" {
fn CFNumberFormatterCreate(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
style: CFNumberFormatterStyle,
) -> Option<NonNull<CFNumberFormatter>>;
}
let ret = unsafe { CFNumberFormatterCreate(allocator, locale, style) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFNumberFormatterGetLocale")]
#[cfg(feature = "CFLocale")]
#[inline]
pub unsafe fn locale(self: &CFNumberFormatter) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFNumberFormatterGetLocale(
formatter: &CFNumberFormatter,
) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFNumberFormatterGetLocale(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFNumberFormatterGetStyle")]
#[inline]
pub unsafe fn style(self: &CFNumberFormatter) -> CFNumberFormatterStyle {
extern "C-unwind" {
fn CFNumberFormatterGetStyle(formatter: &CFNumberFormatter) -> CFNumberFormatterStyle;
}
unsafe { CFNumberFormatterGetStyle(self) }
}
#[doc(alias = "CFNumberFormatterGetFormat")]
#[inline]
pub unsafe fn format(self: &CFNumberFormatter) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFNumberFormatterGetFormat(
formatter: &CFNumberFormatter,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFNumberFormatterGetFormat(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFNumberFormatterSetFormat")]
#[inline]
pub unsafe fn set_format(self: &CFNumberFormatter, format_string: Option<&CFString>) {
extern "C-unwind" {
fn CFNumberFormatterSetFormat(
formatter: &CFNumberFormatter,
format_string: Option<&CFString>,
);
}
unsafe { CFNumberFormatterSetFormat(self, format_string) }
}
#[doc(alias = "CFNumberFormatterCreateStringWithNumber")]
#[cfg(feature = "CFNumber")]
#[inline]
pub unsafe fn new_string_with_number(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number: Option<&CFNumber>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFNumberFormatterCreateStringWithNumber(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number: Option<&CFNumber>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFNumberFormatterCreateStringWithNumber(allocator, formatter, number) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFNumberFormatterCreateStringWithValue")]
#[cfg(feature = "CFNumber")]
#[inline]
pub unsafe fn new_string_with_value(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFNumberFormatterCreateStringWithValue(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe {
CFNumberFormatterCreateStringWithValue(allocator, formatter, number_type, value_ptr)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatteroptionflags?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFNumberFormatterOptionFlags(pub CFOptionFlags);
bitflags::bitflags! {
impl CFNumberFormatterOptionFlags: CFOptionFlags {
#[doc(alias = "kCFNumberFormatterParseIntegersOnly")]
const ParseIntegersOnly = 1;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFNumberFormatterOptionFlags {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFNumberFormatterOptionFlags {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFNumberFormatter {
#[doc(alias = "CFNumberFormatterCreateNumberFromString")]
#[cfg(feature = "CFNumber")]
#[inline]
pub unsafe fn new_number_from_string(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
options: CFOptionFlags,
) -> Option<CFRetained<CFNumber>> {
extern "C-unwind" {
fn CFNumberFormatterCreateNumberFromString(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
options: CFOptionFlags,
) -> Option<NonNull<CFNumber>>;
}
let ret = unsafe {
CFNumberFormatterCreateNumberFromString(allocator, formatter, string, rangep, options)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFNumberFormatterGetValueFromString")]
#[cfg(feature = "CFNumber")]
#[inline]
pub unsafe fn value_from_string(
self: &CFNumberFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
number_type: CFNumberType,
value_ptr: *mut c_void,
) -> bool {
extern "C-unwind" {
fn CFNumberFormatterGetValueFromString(
formatter: &CFNumberFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
number_type: CFNumberType,
value_ptr: *mut c_void,
) -> Boolean;
}
let ret = unsafe {
CFNumberFormatterGetValueFromString(self, string, rangep, number_type, value_ptr)
};
ret != 0
}
#[doc(alias = "CFNumberFormatterSetProperty")]
#[inline]
pub unsafe fn set_property(
self: &CFNumberFormatter,
key: Option<&CFNumberFormatterKey>,
value: Option<&CFType>,
) {
extern "C-unwind" {
fn CFNumberFormatterSetProperty(
formatter: &CFNumberFormatter,
key: Option<&CFNumberFormatterKey>,
value: Option<&CFType>,
);
}
unsafe { CFNumberFormatterSetProperty(self, key, value) }
}
#[doc(alias = "CFNumberFormatterCopyProperty")]
#[inline]
pub unsafe fn property(
self: &CFNumberFormatter,
key: Option<&CFNumberFormatterKey>,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFNumberFormatterCopyProperty(
formatter: &CFNumberFormatter,
key: Option<&CFNumberFormatterKey>,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFNumberFormatterCopyProperty(self, key) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencycode?language=objc)
pub static kCFNumberFormatterCurrencyCode: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterdecimalseparator?language=objc)
pub static kCFNumberFormatterDecimalSeparator: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencydecimalseparator?language=objc)
pub static kCFNumberFormatterCurrencyDecimalSeparator: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatteralwaysshowdecimalseparator?language=objc)
pub static kCFNumberFormatterAlwaysShowDecimalSeparator: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattergroupingseparator?language=objc)
pub static kCFNumberFormatterGroupingSeparator: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterusegroupingseparator?language=objc)
pub static kCFNumberFormatterUseGroupingSeparator: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpercentsymbol?language=objc)
pub static kCFNumberFormatterPercentSymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterzerosymbol?language=objc)
pub static kCFNumberFormatterZeroSymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatternansymbol?language=objc)
pub static kCFNumberFormatterNaNSymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterinfinitysymbol?language=objc)
pub static kCFNumberFormatterInfinitySymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminussign?language=objc)
pub static kCFNumberFormatterMinusSign: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterplussign?language=objc)
pub static kCFNumberFormatterPlusSign: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencysymbol?language=objc)
pub static kCFNumberFormatterCurrencySymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterexponentsymbol?language=objc)
pub static kCFNumberFormatterExponentSymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminintegerdigits?language=objc)
pub static kCFNumberFormatterMinIntegerDigits: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermaxintegerdigits?language=objc)
pub static kCFNumberFormatterMaxIntegerDigits: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminfractiondigits?language=objc)
pub static kCFNumberFormatterMinFractionDigits: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermaxfractiondigits?language=objc)
pub static kCFNumberFormatterMaxFractionDigits: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattergroupingsize?language=objc)
pub static kCFNumberFormatterGroupingSize: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattersecondarygroupingsize?language=objc)
pub static kCFNumberFormatterSecondaryGroupingSize: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterroundingmode?language=objc)
pub static kCFNumberFormatterRoundingMode: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterroundingincrement?language=objc)
pub static kCFNumberFormatterRoundingIncrement: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterformatwidth?language=objc)
pub static kCFNumberFormatterFormatWidth: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpaddingposition?language=objc)
pub static kCFNumberFormatterPaddingPosition: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpaddingcharacter?language=objc)
pub static kCFNumberFormatterPaddingCharacter: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterdefaultformat?language=objc)
pub static kCFNumberFormatterDefaultFormat: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermultiplier?language=objc)
pub static kCFNumberFormatterMultiplier: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpositiveprefix?language=objc)
pub static kCFNumberFormatterPositivePrefix: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpositivesuffix?language=objc)
pub static kCFNumberFormatterPositiveSuffix: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatternegativeprefix?language=objc)
pub static kCFNumberFormatterNegativePrefix: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatternegativesuffix?language=objc)
pub static kCFNumberFormatterNegativeSuffix: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterpermillsymbol?language=objc)
pub static kCFNumberFormatterPerMillSymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterinternationalcurrencysymbol?language=objc)
pub static kCFNumberFormatterInternationalCurrencySymbol: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattercurrencygroupingseparator?language=objc)
pub static kCFNumberFormatterCurrencyGroupingSeparator: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterislenient?language=objc)
pub static kCFNumberFormatterIsLenient: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterusesignificantdigits?language=objc)
pub static kCFNumberFormatterUseSignificantDigits: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformatterminsignificantdigits?language=objc)
pub static kCFNumberFormatterMinSignificantDigits: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermaxsignificantdigits?language=objc)
pub static kCFNumberFormatterMaxSignificantDigits: Option<&'static CFNumberFormatterKey>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnumberformattermingroupingdigits?language=objc)
pub static kCFNumberFormatterMinGroupingDigits: Option<&'static CFNumberFormatterKey>;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterroundingmode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFNumberFormatterRoundingMode(pub CFIndex);
impl CFNumberFormatterRoundingMode {
#[doc(alias = "kCFNumberFormatterRoundCeiling")]
pub const RoundCeiling: Self = Self(0);
#[doc(alias = "kCFNumberFormatterRoundFloor")]
pub const RoundFloor: Self = Self(1);
#[doc(alias = "kCFNumberFormatterRoundDown")]
pub const RoundDown: Self = Self(2);
#[doc(alias = "kCFNumberFormatterRoundUp")]
pub const RoundUp: Self = Self(3);
#[doc(alias = "kCFNumberFormatterRoundHalfEven")]
pub const RoundHalfEven: Self = Self(4);
#[doc(alias = "kCFNumberFormatterRoundHalfDown")]
pub const RoundHalfDown: Self = Self(5);
#[doc(alias = "kCFNumberFormatterRoundHalfUp")]
pub const RoundHalfUp: Self = Self(6);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFNumberFormatterRoundingMode {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFNumberFormatterRoundingMode {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnumberformatterpadposition?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFNumberFormatterPadPosition(pub CFIndex);
impl CFNumberFormatterPadPosition {
#[doc(alias = "kCFNumberFormatterPadBeforePrefix")]
pub const BeforePrefix: Self = Self(0);
#[doc(alias = "kCFNumberFormatterPadAfterPrefix")]
pub const AfterPrefix: Self = Self(1);
#[doc(alias = "kCFNumberFormatterPadBeforeSuffix")]
pub const BeforeSuffix: Self = Self(2);
#[doc(alias = "kCFNumberFormatterPadAfterSuffix")]
pub const AfterSuffix: Self = Self(3);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFNumberFormatterPadPosition {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFNumberFormatterPadPosition {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFNumberFormatter {
#[doc(alias = "CFNumberFormatterGetDecimalInfoForCurrencyCode")]
#[inline]
pub unsafe fn decimal_info_for_currency_code(
currency_code: Option<&CFString>,
default_fraction_digits: *mut i32,
rounding_increment: *mut c_double,
) -> bool {
extern "C-unwind" {
fn CFNumberFormatterGetDecimalInfoForCurrencyCode(
currency_code: Option<&CFString>,
default_fraction_digits: *mut i32,
rounding_increment: *mut c_double,
) -> Boolean;
}
let ret = unsafe {
CFNumberFormatterGetDecimalInfoForCurrencyCode(
currency_code,
default_fraction_digits,
rounding_increment,
)
};
ret != 0
}
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFNumberFormatter::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterCreate(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
style: CFNumberFormatterStyle,
) -> Option<CFRetained<CFNumberFormatter>> {
extern "C-unwind" {
fn CFNumberFormatterCreate(
allocator: Option<&CFAllocator>,
locale: Option<&CFLocale>,
style: CFNumberFormatterStyle,
) -> Option<NonNull<CFNumberFormatter>>;
}
let ret = unsafe { CFNumberFormatterCreate(allocator, locale, style) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFNumberFormatter::locale`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterGetLocale(
formatter: &CFNumberFormatter,
) -> Option<CFRetained<CFLocale>> {
extern "C-unwind" {
fn CFNumberFormatterGetLocale(formatter: &CFNumberFormatter) -> Option<NonNull<CFLocale>>;
}
let ret = unsafe { CFNumberFormatterGetLocale(formatter) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFNumberFormatter::style`"]
pub fn CFNumberFormatterGetStyle(formatter: &CFNumberFormatter) -> CFNumberFormatterStyle;
}
#[deprecated = "renamed to `CFNumberFormatter::format`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterGetFormat(
formatter: &CFNumberFormatter,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFNumberFormatterGetFormat(formatter: &CFNumberFormatter) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFNumberFormatterGetFormat(formatter) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFNumberFormatter::set_format`"]
pub fn CFNumberFormatterSetFormat(
formatter: &CFNumberFormatter,
format_string: Option<&CFString>,
);
}
#[cfg(feature = "CFNumber")]
#[deprecated = "renamed to `CFNumberFormatter::new_string_with_number`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterCreateStringWithNumber(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number: Option<&CFNumber>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFNumberFormatterCreateStringWithNumber(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number: Option<&CFNumber>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFNumberFormatterCreateStringWithNumber(allocator, formatter, number) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFNumber")]
#[deprecated = "renamed to `CFNumberFormatter::new_string_with_value`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterCreateStringWithValue(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFNumberFormatterCreateStringWithValue(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
number_type: CFNumberType,
value_ptr: *const c_void,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe {
CFNumberFormatterCreateStringWithValue(allocator, formatter, number_type, value_ptr)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFNumber")]
#[deprecated = "renamed to `CFNumberFormatter::new_number_from_string`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterCreateNumberFromString(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
options: CFOptionFlags,
) -> Option<CFRetained<CFNumber>> {
extern "C-unwind" {
fn CFNumberFormatterCreateNumberFromString(
allocator: Option<&CFAllocator>,
formatter: Option<&CFNumberFormatter>,
string: Option<&CFString>,
rangep: *mut CFRange,
options: CFOptionFlags,
) -> Option<NonNull<CFNumber>>;
}
let ret = unsafe {
CFNumberFormatterCreateNumberFromString(allocator, formatter, string, rangep, options)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFNumber")]
#[deprecated = "renamed to `CFNumberFormatter::value_from_string`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterGetValueFromString(
formatter: &CFNumberFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
number_type: CFNumberType,
value_ptr: *mut c_void,
) -> bool {
extern "C-unwind" {
fn CFNumberFormatterGetValueFromString(
formatter: &CFNumberFormatter,
string: Option<&CFString>,
rangep: *mut CFRange,
number_type: CFNumberType,
value_ptr: *mut c_void,
) -> Boolean;
}
let ret = unsafe {
CFNumberFormatterGetValueFromString(formatter, string, rangep, number_type, value_ptr)
};
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFNumberFormatter::set_property`"]
pub fn CFNumberFormatterSetProperty(
formatter: &CFNumberFormatter,
key: Option<&CFNumberFormatterKey>,
value: Option<&CFType>,
);
}
#[deprecated = "renamed to `CFNumberFormatter::property`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterCopyProperty(
formatter: &CFNumberFormatter,
key: Option<&CFNumberFormatterKey>,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFNumberFormatterCopyProperty(
formatter: &CFNumberFormatter,
key: Option<&CFNumberFormatterKey>,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFNumberFormatterCopyProperty(formatter, key) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFNumberFormatter::decimal_info_for_currency_code`"]
#[inline]
pub unsafe extern "C-unwind" fn CFNumberFormatterGetDecimalInfoForCurrencyCode(
currency_code: Option<&CFString>,
default_fraction_digits: *mut i32,
rounding_increment: *mut c_double,
) -> bool {
extern "C-unwind" {
fn CFNumberFormatterGetDecimalInfoForCurrencyCode(
currency_code: Option<&CFString>,
default_fraction_digits: *mut i32,
rounding_increment: *mut c_double,
) -> Boolean;
}
let ret = unsafe {
CFNumberFormatterGetDecimalInfoForCurrencyCode(
currency_code,
default_fraction_digits,
rounding_increment,
)
};
ret != 0
}

View File

@@ -0,0 +1,654 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfplugindynamicregistrationkey?language=objc)
pub static kCFPlugInDynamicRegistrationKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfplugindynamicregisterfunctionkey?language=objc)
pub static kCFPlugInDynamicRegisterFunctionKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpluginunloadfunctionkey?language=objc)
pub static kCFPlugInUnloadFunctionKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpluginfactorieskey?language=objc)
pub static kCFPlugInFactoriesKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfplugintypeskey?language=objc)
pub static kCFPlugInTypesKey: Option<&'static CFString>;
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfplugindynamicregisterfunction?language=objc)
#[cfg(feature = "CFBundle")]
pub type CFPlugInDynamicRegisterFunction = Option<unsafe extern "C-unwind" fn(*mut CFPlugIn)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfpluginunloadfunction?language=objc)
#[cfg(feature = "CFBundle")]
pub type CFPlugInUnloadFunction = Option<unsafe extern "C-unwind" fn(*mut CFPlugIn)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfpluginfactoryfunction?language=objc)
#[cfg(feature = "CFUUID")]
pub type CFPlugInFactoryFunction =
Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const CFUUID) -> *mut c_void>;
#[cfg(feature = "CFBundle")]
unsafe impl ConcreteType for CFPlugIn {
#[doc(alias = "CFPlugInGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFPlugInGetTypeID() -> CFTypeID;
}
unsafe { CFPlugInGetTypeID() }
}
}
#[cfg(feature = "CFBundle")]
impl CFPlugIn {
#[doc(alias = "CFPlugInCreate")]
#[cfg(all(feature = "CFBundle", feature = "CFURL"))]
#[inline]
pub fn new(
allocator: Option<&CFAllocator>,
plug_in_url: Option<&CFURL>,
) -> Option<CFRetained<CFPlugIn>> {
extern "C-unwind" {
fn CFPlugInCreate(
allocator: Option<&CFAllocator>,
plug_in_url: Option<&CFURL>,
) -> Option<NonNull<CFPlugIn>>;
}
let ret = unsafe { CFPlugInCreate(allocator, plug_in_url) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFPlugInGetBundle")]
#[cfg(feature = "CFBundle")]
#[inline]
pub fn bundle(self: &CFPlugIn) -> Option<CFRetained<CFBundle>> {
extern "C-unwind" {
fn CFPlugInGetBundle(plug_in: &CFPlugIn) -> Option<NonNull<CFBundle>>;
}
let ret = unsafe { CFPlugInGetBundle(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFPlugInSetLoadOnDemand")]
#[cfg(feature = "CFBundle")]
#[inline]
pub fn set_load_on_demand(self: &CFPlugIn, flag: bool) {
extern "C-unwind" {
fn CFPlugInSetLoadOnDemand(plug_in: &CFPlugIn, flag: Boolean);
}
unsafe { CFPlugInSetLoadOnDemand(self, flag as _) }
}
#[doc(alias = "CFPlugInIsLoadOnDemand")]
#[cfg(feature = "CFBundle")]
#[inline]
pub fn is_load_on_demand(self: &CFPlugIn) -> bool {
extern "C-unwind" {
fn CFPlugInIsLoadOnDemand(plug_in: &CFPlugIn) -> Boolean;
}
let ret = unsafe { CFPlugInIsLoadOnDemand(self) };
ret != 0
}
#[doc(alias = "CFPlugInFindFactoriesForPlugInType")]
#[cfg(all(feature = "CFArray", feature = "CFUUID"))]
#[inline]
pub fn find_factories_for_plug_in_type(
type_uuid: Option<&CFUUID>,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFPlugInFindFactoriesForPlugInType(
type_uuid: Option<&CFUUID>,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFPlugInFindFactoriesForPlugInType(type_uuid) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFPlugInFindFactoriesForPlugInTypeInPlugIn")]
#[cfg(all(feature = "CFArray", feature = "CFBundle", feature = "CFUUID"))]
#[inline]
pub fn find_factories_for_plug_in_type_in_plug_in(
type_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFPlugInFindFactoriesForPlugInTypeInPlugIn(
type_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFPlugInFindFactoriesForPlugInTypeInPlugIn(type_uuid, plug_in) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFPlugInInstance {
#[doc(alias = "CFPlugInInstanceCreate")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn create(
allocator: Option<&CFAllocator>,
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> *mut c_void {
extern "C-unwind" {
fn CFPlugInInstanceCreate(
allocator: Option<&CFAllocator>,
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> *mut c_void;
}
unsafe { CFPlugInInstanceCreate(allocator, factory_uuid, type_uuid) }
}
}
#[cfg(feature = "CFBundle")]
impl CFPlugIn {
#[doc(alias = "CFPlugInRegisterFactoryFunction")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn register_factory_function(
factory_uuid: Option<&CFUUID>,
func: CFPlugInFactoryFunction,
) -> bool {
extern "C-unwind" {
fn CFPlugInRegisterFactoryFunction(
factory_uuid: Option<&CFUUID>,
func: CFPlugInFactoryFunction,
) -> Boolean;
}
let ret = unsafe { CFPlugInRegisterFactoryFunction(factory_uuid, func) };
ret != 0
}
#[doc(alias = "CFPlugInRegisterFactoryFunctionByName")]
#[cfg(all(feature = "CFBundle", feature = "CFUUID"))]
#[inline]
pub fn register_factory_function_by_name(
factory_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
function_name: Option<&CFString>,
) -> bool {
extern "C-unwind" {
fn CFPlugInRegisterFactoryFunctionByName(
factory_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
function_name: Option<&CFString>,
) -> Boolean;
}
let ret =
unsafe { CFPlugInRegisterFactoryFunctionByName(factory_uuid, plug_in, function_name) };
ret != 0
}
#[doc(alias = "CFPlugInUnregisterFactory")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn unregister_factory(factory_uuid: Option<&CFUUID>) -> bool {
extern "C-unwind" {
fn CFPlugInUnregisterFactory(factory_uuid: Option<&CFUUID>) -> Boolean;
}
let ret = unsafe { CFPlugInUnregisterFactory(factory_uuid) };
ret != 0
}
#[doc(alias = "CFPlugInRegisterPlugInType")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn register_plug_in_type(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> bool {
extern "C-unwind" {
fn CFPlugInRegisterPlugInType(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFPlugInRegisterPlugInType(factory_uuid, type_uuid) };
ret != 0
}
#[doc(alias = "CFPlugInUnregisterPlugInType")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn unregister_plug_in_type(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> bool {
extern "C-unwind" {
fn CFPlugInUnregisterPlugInType(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFPlugInUnregisterPlugInType(factory_uuid, type_uuid) };
ret != 0
}
#[doc(alias = "CFPlugInAddInstanceForFactory")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn add_instance_for_factory(factory_id: Option<&CFUUID>) {
extern "C-unwind" {
fn CFPlugInAddInstanceForFactory(factory_id: Option<&CFUUID>);
}
unsafe { CFPlugInAddInstanceForFactory(factory_id) }
}
#[doc(alias = "CFPlugInRemoveInstanceForFactory")]
#[cfg(feature = "CFUUID")]
#[inline]
pub fn remove_instance_for_factory(factory_id: Option<&CFUUID>) {
extern "C-unwind" {
fn CFPlugInRemoveInstanceForFactory(factory_id: Option<&CFUUID>);
}
unsafe { CFPlugInRemoveInstanceForFactory(factory_id) }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfplugininstance?language=objc)
#[repr(C)]
pub struct CFPlugInInstance {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFPlugInInstance {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFPlugInInstance"> for CFPlugInInstance {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfplugininstancegetinterfacefunction?language=objc)
pub type CFPlugInInstanceGetInterfaceFunction = Option<
unsafe extern "C-unwind" fn(
*mut CFPlugInInstance,
*const CFString,
*mut *mut c_void,
) -> Boolean,
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfplugininstancedeallocateinstancedatafunction?language=objc)
pub type CFPlugInInstanceDeallocateInstanceDataFunction =
Option<unsafe extern "C-unwind" fn(*mut c_void)>;
impl CFPlugInInstance {
#[doc(alias = "CFPlugInInstanceGetInterfaceFunctionTable")]
#[inline]
pub unsafe fn interface_function_table(
self: &CFPlugInInstance,
interface_name: Option<&CFString>,
ftbl: *mut *mut c_void,
) -> bool {
extern "C-unwind" {
fn CFPlugInInstanceGetInterfaceFunctionTable(
instance: &CFPlugInInstance,
interface_name: Option<&CFString>,
ftbl: *mut *mut c_void,
) -> Boolean;
}
let ret = unsafe { CFPlugInInstanceGetInterfaceFunctionTable(self, interface_name, ftbl) };
ret != 0
}
#[doc(alias = "CFPlugInInstanceGetFactoryName")]
#[inline]
pub fn factory_name(self: &CFPlugInInstance) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFPlugInInstanceGetFactoryName(
instance: &CFPlugInInstance,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFPlugInInstanceGetFactoryName(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFPlugInInstanceGetInstanceData")]
#[inline]
pub fn instance_data(self: &CFPlugInInstance) -> *mut c_void {
extern "C-unwind" {
fn CFPlugInInstanceGetInstanceData(instance: &CFPlugInInstance) -> *mut c_void;
}
unsafe { CFPlugInInstanceGetInstanceData(self) }
}
}
unsafe impl ConcreteType for CFPlugInInstance {
#[doc(alias = "CFPlugInInstanceGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFPlugInInstanceGetTypeID() -> CFTypeID;
}
unsafe { CFPlugInInstanceGetTypeID() }
}
}
impl CFPlugInInstance {
#[doc(alias = "CFPlugInInstanceCreateWithInstanceDataSize")]
#[inline]
pub unsafe fn with_instance_data_size(
allocator: Option<&CFAllocator>,
instance_data_size: CFIndex,
deallocate_instance_function: CFPlugInInstanceDeallocateInstanceDataFunction,
factory_name: Option<&CFString>,
get_interface_function: CFPlugInInstanceGetInterfaceFunction,
) -> Option<CFRetained<CFPlugInInstance>> {
extern "C-unwind" {
fn CFPlugInInstanceCreateWithInstanceDataSize(
allocator: Option<&CFAllocator>,
instance_data_size: CFIndex,
deallocate_instance_function: CFPlugInInstanceDeallocateInstanceDataFunction,
factory_name: Option<&CFString>,
get_interface_function: CFPlugInInstanceGetInterfaceFunction,
) -> Option<NonNull<CFPlugInInstance>>;
}
let ret = unsafe {
CFPlugInInstanceCreateWithInstanceDataSize(
allocator,
instance_data_size,
deallocate_instance_function,
factory_name,
get_interface_function,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
#[cfg(all(feature = "CFBundle", feature = "CFURL"))]
#[deprecated = "renamed to `CFPlugIn::new`"]
#[inline]
pub extern "C-unwind" fn CFPlugInCreate(
allocator: Option<&CFAllocator>,
plug_in_url: Option<&CFURL>,
) -> Option<CFRetained<CFPlugIn>> {
extern "C-unwind" {
fn CFPlugInCreate(
allocator: Option<&CFAllocator>,
plug_in_url: Option<&CFURL>,
) -> Option<NonNull<CFPlugIn>>;
}
let ret = unsafe { CFPlugInCreate(allocator, plug_in_url) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFBundle")]
#[deprecated = "renamed to `CFPlugIn::bundle`"]
#[inline]
pub extern "C-unwind" fn CFPlugInGetBundle(plug_in: &CFPlugIn) -> Option<CFRetained<CFBundle>> {
extern "C-unwind" {
fn CFPlugInGetBundle(plug_in: &CFPlugIn) -> Option<NonNull<CFBundle>>;
}
let ret = unsafe { CFPlugInGetBundle(plug_in) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[cfg(feature = "CFBundle")]
#[deprecated = "renamed to `CFPlugIn::set_load_on_demand`"]
#[inline]
pub extern "C-unwind" fn CFPlugInSetLoadOnDemand(plug_in: &CFPlugIn, flag: bool) {
extern "C-unwind" {
fn CFPlugInSetLoadOnDemand(plug_in: &CFPlugIn, flag: Boolean);
}
unsafe { CFPlugInSetLoadOnDemand(plug_in, flag as _) }
}
#[cfg(feature = "CFBundle")]
#[deprecated = "renamed to `CFPlugIn::is_load_on_demand`"]
#[inline]
pub extern "C-unwind" fn CFPlugInIsLoadOnDemand(plug_in: &CFPlugIn) -> bool {
extern "C-unwind" {
fn CFPlugInIsLoadOnDemand(plug_in: &CFPlugIn) -> Boolean;
}
let ret = unsafe { CFPlugInIsLoadOnDemand(plug_in) };
ret != 0
}
#[cfg(all(feature = "CFArray", feature = "CFUUID"))]
#[deprecated = "renamed to `CFPlugIn::find_factories_for_plug_in_type`"]
#[inline]
pub extern "C-unwind" fn CFPlugInFindFactoriesForPlugInType(
type_uuid: Option<&CFUUID>,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFPlugInFindFactoriesForPlugInType(
type_uuid: Option<&CFUUID>,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFPlugInFindFactoriesForPlugInType(type_uuid) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFArray", feature = "CFBundle", feature = "CFUUID"))]
#[deprecated = "renamed to `CFPlugIn::find_factories_for_plug_in_type_in_plug_in`"]
#[inline]
pub extern "C-unwind" fn CFPlugInFindFactoriesForPlugInTypeInPlugIn(
type_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFPlugInFindFactoriesForPlugInTypeInPlugIn(
type_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFPlugInFindFactoriesForPlugInTypeInPlugIn(type_uuid, plug_in) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFPlugInInstance::create`"]
#[inline]
pub extern "C-unwind" fn CFPlugInInstanceCreate(
allocator: Option<&CFAllocator>,
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> *mut c_void {
extern "C-unwind" {
fn CFPlugInInstanceCreate(
allocator: Option<&CFAllocator>,
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> *mut c_void;
}
unsafe { CFPlugInInstanceCreate(allocator, factory_uuid, type_uuid) }
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFPlugIn::register_factory_function`"]
#[inline]
pub extern "C-unwind" fn CFPlugInRegisterFactoryFunction(
factory_uuid: Option<&CFUUID>,
func: CFPlugInFactoryFunction,
) -> bool {
extern "C-unwind" {
fn CFPlugInRegisterFactoryFunction(
factory_uuid: Option<&CFUUID>,
func: CFPlugInFactoryFunction,
) -> Boolean;
}
let ret = unsafe { CFPlugInRegisterFactoryFunction(factory_uuid, func) };
ret != 0
}
#[cfg(all(feature = "CFBundle", feature = "CFUUID"))]
#[deprecated = "renamed to `CFPlugIn::register_factory_function_by_name`"]
#[inline]
pub extern "C-unwind" fn CFPlugInRegisterFactoryFunctionByName(
factory_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
function_name: Option<&CFString>,
) -> bool {
extern "C-unwind" {
fn CFPlugInRegisterFactoryFunctionByName(
factory_uuid: Option<&CFUUID>,
plug_in: Option<&CFPlugIn>,
function_name: Option<&CFString>,
) -> Boolean;
}
let ret =
unsafe { CFPlugInRegisterFactoryFunctionByName(factory_uuid, plug_in, function_name) };
ret != 0
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFPlugIn::unregister_factory`"]
#[inline]
pub extern "C-unwind" fn CFPlugInUnregisterFactory(factory_uuid: Option<&CFUUID>) -> bool {
extern "C-unwind" {
fn CFPlugInUnregisterFactory(factory_uuid: Option<&CFUUID>) -> Boolean;
}
let ret = unsafe { CFPlugInUnregisterFactory(factory_uuid) };
ret != 0
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFPlugIn::register_plug_in_type`"]
#[inline]
pub extern "C-unwind" fn CFPlugInRegisterPlugInType(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> bool {
extern "C-unwind" {
fn CFPlugInRegisterPlugInType(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFPlugInRegisterPlugInType(factory_uuid, type_uuid) };
ret != 0
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFPlugIn::unregister_plug_in_type`"]
#[inline]
pub extern "C-unwind" fn CFPlugInUnregisterPlugInType(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> bool {
extern "C-unwind" {
fn CFPlugInUnregisterPlugInType(
factory_uuid: Option<&CFUUID>,
type_uuid: Option<&CFUUID>,
) -> Boolean;
}
let ret = unsafe { CFPlugInUnregisterPlugInType(factory_uuid, type_uuid) };
ret != 0
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFPlugIn::add_instance_for_factory`"]
#[inline]
pub extern "C-unwind" fn CFPlugInAddInstanceForFactory(factory_id: Option<&CFUUID>) {
extern "C-unwind" {
fn CFPlugInAddInstanceForFactory(factory_id: Option<&CFUUID>);
}
unsafe { CFPlugInAddInstanceForFactory(factory_id) }
}
#[cfg(feature = "CFUUID")]
#[deprecated = "renamed to `CFPlugIn::remove_instance_for_factory`"]
#[inline]
pub extern "C-unwind" fn CFPlugInRemoveInstanceForFactory(factory_id: Option<&CFUUID>) {
extern "C-unwind" {
fn CFPlugInRemoveInstanceForFactory(factory_id: Option<&CFUUID>);
}
unsafe { CFPlugInRemoveInstanceForFactory(factory_id) }
}
#[deprecated = "renamed to `CFPlugInInstance::interface_function_table`"]
#[inline]
pub unsafe extern "C-unwind" fn CFPlugInInstanceGetInterfaceFunctionTable(
instance: &CFPlugInInstance,
interface_name: Option<&CFString>,
ftbl: *mut *mut c_void,
) -> bool {
extern "C-unwind" {
fn CFPlugInInstanceGetInterfaceFunctionTable(
instance: &CFPlugInInstance,
interface_name: Option<&CFString>,
ftbl: *mut *mut c_void,
) -> Boolean;
}
let ret = unsafe { CFPlugInInstanceGetInterfaceFunctionTable(instance, interface_name, ftbl) };
ret != 0
}
#[deprecated = "renamed to `CFPlugInInstance::factory_name`"]
#[inline]
pub extern "C-unwind" fn CFPlugInInstanceGetFactoryName(
instance: &CFPlugInInstance,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFPlugInInstanceGetFactoryName(instance: &CFPlugInInstance)
-> Option<NonNull<CFString>>;
}
let ret = unsafe { CFPlugInInstanceGetFactoryName(instance) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFPlugInInstance::instance_data`"]
#[inline]
pub extern "C-unwind" fn CFPlugInInstanceGetInstanceData(
instance: &CFPlugInInstance,
) -> *mut c_void {
extern "C-unwind" {
fn CFPlugInInstanceGetInstanceData(instance: &CFPlugInInstance) -> *mut c_void;
}
unsafe { CFPlugInInstanceGetInstanceData(instance) }
}
#[deprecated = "renamed to `CFPlugInInstance::with_instance_data_size`"]
#[inline]
pub unsafe extern "C-unwind" fn CFPlugInInstanceCreateWithInstanceDataSize(
allocator: Option<&CFAllocator>,
instance_data_size: CFIndex,
deallocate_instance_function: CFPlugInInstanceDeallocateInstanceDataFunction,
factory_name: Option<&CFString>,
get_interface_function: CFPlugInInstanceGetInterfaceFunction,
) -> Option<CFRetained<CFPlugInInstance>> {
extern "C-unwind" {
fn CFPlugInInstanceCreateWithInstanceDataSize(
allocator: Option<&CFAllocator>,
instance_data_size: CFIndex,
deallocate_instance_function: CFPlugInInstanceDeallocateInstanceDataFunction,
factory_name: Option<&CFString>,
get_interface_function: CFPlugInInstanceGetInterfaceFunction,
) -> Option<NonNull<CFPlugInInstance>>;
}
let ret = unsafe {
CFPlugInInstanceCreateWithInstanceDataSize(
allocator,
instance_data_size,
deallocate_instance_function,
factory_name,
get_interface_function,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,47 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/hresult?language=objc)
pub type HRESULT = i32;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/ulong?language=objc)
pub type ULONG = u32;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/lpvoid?language=objc)
pub type LPVOID = *mut c_void;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/refiid?language=objc)
#[cfg(feature = "CFUUID")]
pub type REFIID = CFUUIDBytes;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/iunknownvtbl?language=objc)
#[cfg(feature = "CFUUID")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct IUnknownVTbl {
pub(crate) _reserved: *mut c_void,
pub QueryInterface:
Option<unsafe extern "C-unwind" fn(*mut c_void, REFIID, *mut LPVOID) -> HRESULT>,
pub AddRef: Option<unsafe extern "C-unwind" fn(*mut c_void) -> ULONG>,
pub Release: Option<unsafe extern "C-unwind" fn(*mut c_void) -> ULONG>,
}
#[cfg(all(feature = "CFUUID", feature = "objc2"))]
unsafe impl Encode for IUnknownVTbl {
const ENCODING: Encoding = Encoding::Struct("IUnknownVTbl", &[
<*mut c_void>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*mut c_void,REFIID,*mut LPVOID,) -> HRESULT>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*mut c_void,) -> ULONG>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*mut c_void,) -> ULONG>>::ENCODING,
]);
}
#[cfg(all(feature = "CFUUID", feature = "objc2"))]
unsafe impl RefEncode for IUnknownVTbl {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

View File

@@ -0,0 +1,246 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use crate::*;
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpreferencesanyapplication?language=objc)
pub static kCFPreferencesAnyApplication: &'static CFString;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpreferencescurrentapplication?language=objc)
pub static kCFPreferencesCurrentApplication: &'static CFString;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpreferencesanyhost?language=objc)
pub static kCFPreferencesAnyHost: &'static CFString;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpreferencescurrenthost?language=objc)
pub static kCFPreferencesCurrentHost: &'static CFString;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpreferencesanyuser?language=objc)
pub static kCFPreferencesAnyUser: &'static CFString;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpreferencescurrentuser?language=objc)
pub static kCFPreferencesCurrentUser: &'static CFString;
}
#[inline]
pub extern "C-unwind" fn CFPreferencesCopyAppValue(
key: &CFString,
application_id: &CFString,
) -> Option<CFRetained<CFPropertyList>> {
extern "C-unwind" {
fn CFPreferencesCopyAppValue(
key: &CFString,
application_id: &CFString,
) -> Option<NonNull<CFPropertyList>>;
}
let ret = unsafe { CFPreferencesCopyAppValue(key, application_id) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[inline]
pub unsafe extern "C-unwind" fn CFPreferencesGetAppBooleanValue(
key: &CFString,
application_id: &CFString,
key_exists_and_has_valid_format: *mut Boolean,
) -> bool {
extern "C-unwind" {
fn CFPreferencesGetAppBooleanValue(
key: &CFString,
application_id: &CFString,
key_exists_and_has_valid_format: *mut Boolean,
) -> Boolean;
}
let ret = unsafe {
CFPreferencesGetAppBooleanValue(key, application_id, key_exists_and_has_valid_format)
};
ret != 0
}
extern "C-unwind" {
pub fn CFPreferencesGetAppIntegerValue(
key: &CFString,
application_id: &CFString,
key_exists_and_has_valid_format: *mut Boolean,
) -> CFIndex;
}
extern "C-unwind" {
pub fn CFPreferencesSetAppValue(
key: &CFString,
value: Option<&CFPropertyList>,
application_id: &CFString,
);
}
#[inline]
pub extern "C-unwind" fn CFPreferencesAddSuitePreferencesToApp(
application_id: &CFString,
suite_id: &CFString,
) {
extern "C-unwind" {
fn CFPreferencesAddSuitePreferencesToApp(application_id: &CFString, suite_id: &CFString);
}
unsafe { CFPreferencesAddSuitePreferencesToApp(application_id, suite_id) }
}
#[inline]
pub extern "C-unwind" fn CFPreferencesRemoveSuitePreferencesFromApp(
application_id: &CFString,
suite_id: &CFString,
) {
extern "C-unwind" {
fn CFPreferencesRemoveSuitePreferencesFromApp(
application_id: &CFString,
suite_id: &CFString,
);
}
unsafe { CFPreferencesRemoveSuitePreferencesFromApp(application_id, suite_id) }
}
#[inline]
pub extern "C-unwind" fn CFPreferencesAppSynchronize(application_id: &CFString) -> bool {
extern "C-unwind" {
fn CFPreferencesAppSynchronize(application_id: &CFString) -> Boolean;
}
let ret = unsafe { CFPreferencesAppSynchronize(application_id) };
ret != 0
}
#[inline]
pub extern "C-unwind" fn CFPreferencesCopyValue(
key: &CFString,
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> Option<CFRetained<CFPropertyList>> {
extern "C-unwind" {
fn CFPreferencesCopyValue(
key: &CFString,
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> Option<NonNull<CFPropertyList>>;
}
let ret = unsafe { CFPreferencesCopyValue(key, application_id, user_name, host_name) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFArray", feature = "CFDictionary"))]
#[inline]
pub extern "C-unwind" fn CFPreferencesCopyMultiple(
keys_to_fetch: Option<&CFArray>,
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> CFRetained<CFDictionary> {
extern "C-unwind" {
fn CFPreferencesCopyMultiple(
keys_to_fetch: Option<&CFArray>,
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> Option<NonNull<CFDictionary>>;
}
let ret =
unsafe { CFPreferencesCopyMultiple(keys_to_fetch, application_id, user_name, host_name) };
let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
unsafe { CFRetained::from_raw(ret) }
}
extern "C-unwind" {
pub fn CFPreferencesSetValue(
key: &CFString,
value: Option<&CFPropertyList>,
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
);
}
extern "C-unwind" {
#[cfg(all(feature = "CFArray", feature = "CFDictionary"))]
pub fn CFPreferencesSetMultiple(
keys_to_set: Option<&CFDictionary>,
keys_to_remove: Option<&CFArray>,
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
);
}
#[inline]
pub unsafe extern "C-unwind" fn CFPreferencesSynchronize(
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> bool {
extern "C-unwind" {
fn CFPreferencesSynchronize(
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> Boolean;
}
let ret = unsafe { CFPreferencesSynchronize(application_id, user_name, host_name) };
ret != 0
}
#[cfg(feature = "CFArray")]
#[deprecated = "Unsupported API"]
#[inline]
pub unsafe extern "C-unwind" fn CFPreferencesCopyApplicationList(
user_name: &CFString,
host_name: &CFString,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFPreferencesCopyApplicationList(
user_name: &CFString,
host_name: &CFString,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFPreferencesCopyApplicationList(user_name, host_name) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[inline]
pub extern "C-unwind" fn CFPreferencesCopyKeyList(
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFPreferencesCopyKeyList(
application_id: &CFString,
user_name: &CFString,
host_name: &CFString,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFPreferencesCopyKeyList(application_id, user_name, host_name) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[inline]
pub extern "C-unwind" fn CFPreferencesAppValueIsForced(
key: &CFString,
application_id: &CFString,
) -> bool {
extern "C-unwind" {
fn CFPreferencesAppValueIsForced(key: &CFString, application_id: &CFString) -> Boolean;
}
let ret = unsafe { CFPreferencesAppValueIsForced(key, application_id) };
ret != 0
}

View File

@@ -0,0 +1,261 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfpropertylistmutabilityoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFPropertyListMutabilityOptions(pub CFOptionFlags);
bitflags::bitflags! {
impl CFPropertyListMutabilityOptions: CFOptionFlags {
#[doc(alias = "kCFPropertyListImmutable")]
const Immutable = 0;
#[doc(alias = "kCFPropertyListMutableContainers")]
const MutableContainers = 1<<0;
#[doc(alias = "kCFPropertyListMutableContainersAndLeaves")]
const MutableContainersAndLeaves = 1<<1;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFPropertyListMutabilityOptions {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFPropertyListMutabilityOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[cfg(feature = "CFData")]
#[deprecated = "Use CFPropertyListCreateWithData instead."]
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListCreateFromXMLData(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
mutability_option: CFOptionFlags,
error_string: *mut *const CFString,
) -> Option<CFRetained<CFPropertyList>> {
extern "C-unwind" {
fn CFPropertyListCreateFromXMLData(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
mutability_option: CFOptionFlags,
error_string: *mut *const CFString,
) -> Option<NonNull<CFPropertyList>>;
}
let ret = unsafe {
CFPropertyListCreateFromXMLData(allocator, xml_data, mutability_option, error_string)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFData")]
#[deprecated = "Use CFPropertyListCreateData instead."]
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListCreateXMLData(
allocator: Option<&CFAllocator>,
property_list: Option<&CFPropertyList>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFPropertyListCreateXMLData(
allocator: Option<&CFAllocator>,
property_list: Option<&CFPropertyList>,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFPropertyListCreateXMLData(allocator, property_list) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListCreateDeepCopy(
allocator: Option<&CFAllocator>,
property_list: Option<&CFPropertyList>,
mutability_option: CFOptionFlags,
) -> Option<CFRetained<CFPropertyList>> {
extern "C-unwind" {
fn CFPropertyListCreateDeepCopy(
allocator: Option<&CFAllocator>,
property_list: Option<&CFPropertyList>,
mutability_option: CFOptionFlags,
) -> Option<NonNull<CFPropertyList>>;
}
let ret = unsafe { CFPropertyListCreateDeepCopy(allocator, property_list, mutability_option) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfpropertylistformat?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFPropertyListFormat(pub CFIndex);
impl CFPropertyListFormat {
#[doc(alias = "kCFPropertyListOpenStepFormat")]
pub const OpenStepFormat: Self = Self(1);
#[doc(alias = "kCFPropertyListXMLFormat_v1_0")]
pub const XMLFormat_v1_0: Self = Self(100);
#[doc(alias = "kCFPropertyListBinaryFormat_v1_0")]
pub const BinaryFormat_v1_0: Self = Self(200);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFPropertyListFormat {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFPropertyListFormat {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListIsValid(
plist: &CFPropertyList,
format: CFPropertyListFormat,
) -> bool {
extern "C-unwind" {
fn CFPropertyListIsValid(plist: &CFPropertyList, format: CFPropertyListFormat) -> Boolean;
}
let ret = unsafe { CFPropertyListIsValid(plist, format) };
ret != 0
}
extern "C-unwind" {
#[cfg(feature = "CFStream")]
#[deprecated = "Use CFPropertyListWrite instead."]
pub fn CFPropertyListWriteToStream(
property_list: &CFPropertyList,
stream: Option<&CFWriteStream>,
format: CFPropertyListFormat,
error_string: *mut *const CFString,
) -> CFIndex;
}
#[cfg(feature = "CFStream")]
#[deprecated = "Use CFPropertyListCreateWithStream instead."]
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListCreateFromStream(
allocator: Option<&CFAllocator>,
stream: Option<&CFReadStream>,
stream_length: CFIndex,
mutability_option: CFOptionFlags,
format: *mut CFPropertyListFormat,
error_string: *mut *const CFString,
) -> Option<CFRetained<CFPropertyList>> {
extern "C-unwind" {
fn CFPropertyListCreateFromStream(
allocator: Option<&CFAllocator>,
stream: Option<&CFReadStream>,
stream_length: CFIndex,
mutability_option: CFOptionFlags,
format: *mut CFPropertyListFormat,
error_string: *mut *const CFString,
) -> Option<NonNull<CFPropertyList>>;
}
let ret = unsafe {
CFPropertyListCreateFromStream(
allocator,
stream,
stream_length,
mutability_option,
format,
error_string,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpropertylistreadcorrupterror?language=objc)
pub const kCFPropertyListReadCorruptError: CFIndex = 3840;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpropertylistreadunknownversionerror?language=objc)
pub const kCFPropertyListReadUnknownVersionError: CFIndex = 3841;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpropertylistreadstreamerror?language=objc)
pub const kCFPropertyListReadStreamError: CFIndex = 3842;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfpropertylistwritestreamerror?language=objc)
pub const kCFPropertyListWriteStreamError: CFIndex = 3851;
#[cfg(all(feature = "CFData", feature = "CFError"))]
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListCreateWithData(
allocator: Option<&CFAllocator>,
data: Option<&CFData>,
options: CFOptionFlags,
format: *mut CFPropertyListFormat,
error: *mut *mut CFError,
) -> Option<CFRetained<CFPropertyList>> {
extern "C-unwind" {
fn CFPropertyListCreateWithData(
allocator: Option<&CFAllocator>,
data: Option<&CFData>,
options: CFOptionFlags,
format: *mut CFPropertyListFormat,
error: *mut *mut CFError,
) -> Option<NonNull<CFPropertyList>>;
}
let ret = unsafe { CFPropertyListCreateWithData(allocator, data, options, format, error) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFError", feature = "CFStream"))]
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListCreateWithStream(
allocator: Option<&CFAllocator>,
stream: Option<&CFReadStream>,
stream_length: CFIndex,
options: CFOptionFlags,
format: *mut CFPropertyListFormat,
error: *mut *mut CFError,
) -> Option<CFRetained<CFPropertyList>> {
extern "C-unwind" {
fn CFPropertyListCreateWithStream(
allocator: Option<&CFAllocator>,
stream: Option<&CFReadStream>,
stream_length: CFIndex,
options: CFOptionFlags,
format: *mut CFPropertyListFormat,
error: *mut *mut CFError,
) -> Option<NonNull<CFPropertyList>>;
}
let ret = unsafe {
CFPropertyListCreateWithStream(allocator, stream, stream_length, options, format, error)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[cfg(all(feature = "CFError", feature = "CFStream"))]
pub fn CFPropertyListWrite(
property_list: &CFPropertyList,
stream: Option<&CFWriteStream>,
format: CFPropertyListFormat,
options: CFOptionFlags,
error: *mut *mut CFError,
) -> CFIndex;
}
#[cfg(all(feature = "CFData", feature = "CFError"))]
#[inline]
pub unsafe extern "C-unwind" fn CFPropertyListCreateData(
allocator: Option<&CFAllocator>,
property_list: Option<&CFPropertyList>,
format: CFPropertyListFormat,
options: CFOptionFlags,
error: *mut *mut CFError,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFPropertyListCreateData(
allocator: Option<&CFAllocator>,
property_list: Option<&CFPropertyList>,
format: CFPropertyListFormat,
options: CFOptionFlags,
error: *mut *mut CFError,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFPropertyListCreateData(allocator, property_list, format, options, error) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,850 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// Type of the callback function used by CFSets for retaining values.
///
/// Parameter `allocator`: The allocator of the CFSet.
///
/// Parameter `value`: The value to retain.
///
/// Returns: The value to store in the set, which is usually the value
/// parameter passed to this callback, but may be a different
/// value if a different value should be stored in the set.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetretaincallback?language=objc)
pub type CFSetRetainCallBack =
Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void>;
/// Type of the callback function used by CFSets for releasing a retain on values.
///
/// Parameter `allocator`: The allocator of the CFSet.
///
/// Parameter `value`: The value to release.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetreleasecallback?language=objc)
pub type CFSetReleaseCallBack =
Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>;
/// Type of the callback function used by CFSets for describing values.
///
/// Parameter `value`: The value to describe.
///
/// Returns: A description of the specified value.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetcopydescriptioncallback?language=objc)
pub type CFSetCopyDescriptionCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
/// Type of the callback function used by CFSets for comparing values.
///
/// Parameter `value1`: The first value to compare.
///
/// Parameter `value2`: The second value to compare.
///
/// Returns: True if the values are equal, otherwise false.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetequalcallback?language=objc)
pub type CFSetEqualCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void, *const c_void) -> Boolean>;
/// Type of the callback function used by CFSets for hashing values.
///
/// Parameter `value`: The value to hash.
///
/// Returns: The hash of the value.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsethashcallback?language=objc)
pub type CFSetHashCallBack = Option<unsafe extern "C-unwind" fn(*const c_void) -> CFHashCode>;
/// Structure containing the callbacks of a CFSet.
/// Field: version The version number of the structure type being passed
/// in as a parameter to the CFSet creation functions. This
/// structure is version 0.
/// Field: retain The callback used to add a retain for the set on
/// values as they are put into the set. This callback returns
/// the value to store in the set, which is usually the value
/// parameter passed to this callback, but may be a different
/// value if a different value should be stored in the set.
/// The set's allocator is passed as the first argument.
/// Field: release The callback used to remove a retain previously added
/// for the set from values as they are removed from the
/// set. The set's allocator is passed as the first
/// argument.
/// Field: copyDescription The callback used to create a descriptive
/// string representation of each value in the set. This is
/// used by the CFCopyDescription() function.
/// Field: equal The callback used to compare values in the set for
/// equality for some operations.
/// Field: hash The callback used to compare values in the set for
/// uniqueness for some operations.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetcallbacks?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFSetCallBacks {
pub version: CFIndex,
pub retain: CFSetRetainCallBack,
pub release: CFSetReleaseCallBack,
pub copyDescription: CFSetCopyDescriptionCallBack,
pub equal: CFSetEqualCallBack,
pub hash: CFSetHashCallBack,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFSetCallBacks {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<CFSetRetainCallBack>::ENCODING,
<CFSetReleaseCallBack>::ENCODING,
<CFSetCopyDescriptionCallBack>::ENCODING,
<CFSetEqualCallBack>::ENCODING,
<CFSetHashCallBack>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFSetCallBacks {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern "C" {
/// Predefined CFSetCallBacks structure containing a set of callbacks
/// appropriate for use when the values in a CFSet are all CFTypes.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcftypesetcallbacks?language=objc)
pub static kCFTypeSetCallBacks: CFSetCallBacks;
}
extern "C" {
/// Predefined CFSetCallBacks structure containing a set of callbacks
/// appropriate for use when the values in a CFSet should be copies
/// of a CFString.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcopystringsetcallbacks?language=objc)
pub static kCFCopyStringSetCallBacks: CFSetCallBacks;
}
/// Type of the callback function used by the apply functions of
/// CFSets.
///
/// Parameter `value`: The current value from the set.
///
/// Parameter `context`: The user-defined context parameter given to the apply
/// function.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetapplierfunction?language=objc)
pub type CFSetApplierFunction = Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
/// This is the type of a reference to immutable CFSets.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfset?language=objc)
#[repr(C)]
pub struct CFSet<T: ?Sized = Opaque> {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
_generics: PhantomData<(*mut T,)>,
}
cf_type!(
unsafe impl<T: ?Sized> CFSet<T> {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl<T: ?Sized> RefEncode<"__CFSet"> for CFSet<T> {}
);
/// This is the type of a reference to mutable CFSets.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutableset?language=objc)
#[repr(C)]
pub struct CFMutableSet<T: ?Sized = Opaque> {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
_generics: PhantomData<(*mut T,)>,
}
cf_type!(
unsafe impl<T: ?Sized> CFMutableSet<T>: CFSet<T> {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl<T: ?Sized> RefEncode<"__CFSet"> for CFMutableSet<T> {}
);
unsafe impl ConcreteType for CFSet {
/// Returns the type identifier of all CFSet instances.
#[doc(alias = "CFSetGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFSetGetTypeID() -> CFTypeID;
}
unsafe { CFSetGetTypeID() }
}
}
impl CFSet {
/// Creates a new immutable set with the given values.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate
/// memory for the set and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `values`: A C array of the pointer-sized values to be in the
/// set. This C array is not changed or freed by this function.
/// If this parameter is not a valid pointer to a C array of at
/// least numValues pointers, the behavior is undefined.
///
/// Parameter `numValues`: The number of values to copy from the values C
/// array into the CFSet. This number will be the count of the
/// set. If this parameter is zero, negative, or greater than
/// the number of values actually in the values C array, the
/// behavior is undefined.
///
/// Parameter `callBacks`: A C pointer to a CFSetCallBacks structure
/// initialized with the callbacks for the set to use on each
/// value in the set. A copy of the contents of the
/// callbacks structure is made, so that a pointer to a
/// structure on the stack can be passed in, or can be reused
/// for multiple set creations. If the version field of this
/// callbacks structure is not one of the defined ones for
/// CFSet, the behavior is undefined. The retain field may be
/// NULL, in which case the CFSet will do nothing to add a
/// retain to the contained values for the set. The release
/// field may be NULL, in which case the CFSet will do nothing
/// to remove the set's retain (if any) on the values when the
/// set is destroyed. If the copyDescription field is NULL,
/// the set will create a simple description for the value. If
/// the equal field is NULL, the set will use pointer equality
/// to test for equality of values. The hash field may be NULL,
/// in which case the CFSet will determine uniqueness by pointer
/// equality. This callbacks parameter
/// itself may be NULL, which is treated as if a valid structure
/// of version 0 with all fields NULL had been passed in.
/// Otherwise, if any of the fields are not valid pointers to
/// functions of the correct type, or this parameter is not a
/// valid pointer to a CFSetCallBacks callbacks structure,
/// the behavior is undefined. If any of the values put into the
/// set is not one understood by one of the callback functions
/// the behavior when that callback function is used is
/// undefined.
///
/// Returns: A reference to the new immutable CFSet.
#[doc(alias = "CFSetCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<CFRetained<CFSet>> {
extern "C-unwind" {
fn CFSetCreate(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<NonNull<CFSet>>;
}
let ret = unsafe { CFSetCreate(allocator, values, num_values, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a new immutable set with the values from the given set.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate
/// memory for the set and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `theSet`: The set which is to be copied. The values from the
/// set are copied as pointers into the new set (that is,
/// the values themselves are copied, not that which the values
/// point to, if anything). However, the values are also
/// retained by the new set. The count of the new set will
/// be the same as the copied set. The new set uses the same
/// callbacks as the set to be copied. If this parameter is
/// not a valid CFSet, the behavior is undefined.
///
/// Returns: A reference to the new immutable CFSet.
#[doc(alias = "CFSetCreateCopy")]
#[inline]
pub fn new_copy(
allocator: Option<&CFAllocator>,
the_set: Option<&CFSet>,
) -> Option<CFRetained<CFSet>> {
extern "C-unwind" {
fn CFSetCreateCopy(
allocator: Option<&CFAllocator>,
the_set: Option<&CFSet>,
) -> Option<NonNull<CFSet>>;
}
let ret = unsafe { CFSetCreateCopy(allocator, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFMutableSet {
/// Creates a new empty mutable set.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate
/// memory for the set and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `capacity`: A hint about the number of values that will be held
/// by the CFSet. Pass 0 for no hint. The implementation may
/// ignore this hint, or may use it to optimize various
/// operations. A set's actual capacity is only limited by
/// address space and available memory constraints). If this
/// parameter is negative, the behavior is undefined.
///
/// Parameter `callBacks`: A C pointer to a CFSetCallBacks structure
/// initialized with the callbacks for the set to use on each
/// value in the set. A copy of the contents of the
/// callbacks structure is made, so that a pointer to a
/// structure on the stack can be passed in, or can be reused
/// for multiple set creations. If the version field of this
/// callbacks structure is not one of the defined ones for
/// CFSet, the behavior is undefined. The retain field may be
/// NULL, in which case the CFSet will do nothing to add a
/// retain to the contained values for the set. The release
/// field may be NULL, in which case the CFSet will do nothing
/// to remove the set's retain (if any) on the values when the
/// set is destroyed. If the copyDescription field is NULL,
/// the set will create a simple description for the value. If
/// the equal field is NULL, the set will use pointer equality
/// to test for equality of values. The hash field may be NULL,
/// in which case the CFSet will determine uniqueness by pointer
/// equality. This callbacks parameter
/// itself may be NULL, which is treated as if a valid structure
/// of version 0 with all fields NULL had been passed in.
/// Otherwise, if any of the fields are not valid pointers to
/// functions of the correct type, or this parameter is not a
/// valid pointer to a CFSetCallBacks callbacks structure,
/// the behavior is undefined. If any of the values put into the
/// set is not one understood by one of the callback functions
/// the behavior when that callback function is used is
/// undefined.
///
/// Returns: A reference to the new mutable CFSet.
#[doc(alias = "CFSetCreateMutable")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<CFRetained<CFMutableSet>> {
extern "C-unwind" {
fn CFSetCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<NonNull<CFMutableSet>>;
}
let ret = unsafe { CFSetCreateMutable(allocator, capacity, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Creates a new immutable set with the values from the given set.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate
/// memory for the set and its storage for values. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `capacity`: A hint about the number of values that will be held
/// by the CFSet. Pass 0 for no hint. The implementation may
/// ignore this hint, or may use it to optimize various
/// operations. A set's actual capacity is only limited by
/// address space and available memory constraints).
/// This parameter must be greater than or equal
/// to the count of the set which is to be copied, or the
/// behavior is undefined. If this parameter is negative, the
/// behavior is undefined.
///
/// Parameter `theSet`: The set which is to be copied. The values from the
/// set are copied as pointers into the new set (that is,
/// the values themselves are copied, not that which the values
/// point to, if anything). However, the values are also
/// retained by the new set. The count of the new set will
/// be the same as the copied set. The new set uses the same
/// callbacks as the set to be copied. If this parameter is
/// not a valid CFSet, the behavior is undefined.
///
/// Returns: A reference to the new mutable CFSet.
#[doc(alias = "CFSetCreateMutableCopy")]
#[inline]
pub unsafe fn new_copy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_set: Option<&CFSet>,
) -> Option<CFRetained<CFMutableSet>> {
extern "C-unwind" {
fn CFSetCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_set: Option<&CFSet>,
) -> Option<NonNull<CFMutableSet>>;
}
let ret = unsafe { CFSetCreateMutableCopy(allocator, capacity, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl CFSet {
/// Returns the number of values currently in the set.
///
/// Parameter `theSet`: The set to be queried. If this parameter is not a valid
/// CFSet, the behavior is undefined.
///
/// Returns: The number of values in the set.
#[doc(alias = "CFSetGetCount")]
#[inline]
pub fn count(self: &CFSet) -> CFIndex {
extern "C-unwind" {
fn CFSetGetCount(the_set: &CFSet) -> CFIndex;
}
unsafe { CFSetGetCount(self) }
}
/// Counts the number of times the given value occurs in the set. Since
/// sets by definition contain only one instance of a value, this function
/// is synonymous to CFSetContainsValue.
///
/// Parameter `theSet`: The set to be searched. If this parameter is not a
/// valid CFSet, the behavior is undefined.
///
/// Parameter `value`: The value for which to find matches in the set. The
/// equal() callback provided when the set was created is
/// used to compare. If the equal() callback was NULL, pointer
/// equality (in C, ==) is used. If value, or any of the values
/// in the set, are not understood by the equal() callback,
/// the behavior is undefined.
///
/// Returns: The number of times the given value occurs in the set.
#[doc(alias = "CFSetGetCountOfValue")]
#[inline]
pub unsafe fn count_of_value(self: &CFSet, value: *const c_void) -> CFIndex {
extern "C-unwind" {
fn CFSetGetCountOfValue(the_set: &CFSet, value: *const c_void) -> CFIndex;
}
unsafe { CFSetGetCountOfValue(self, value) }
}
/// Reports whether or not the value is in the set.
///
/// Parameter `theSet`: The set to be searched. If this parameter is not a
/// valid CFSet, the behavior is undefined.
///
/// Parameter `value`: The value for which to find matches in the set. The
/// equal() callback provided when the set was created is
/// used to compare. If the equal() callback was NULL, pointer
/// equality (in C, ==) is used. If value, or any of the values
/// in the set, are not understood by the equal() callback,
/// the behavior is undefined.
///
/// Returns: true, if the value is in the set, otherwise false.
#[doc(alias = "CFSetContainsValue")]
#[inline]
pub unsafe fn contains_value(self: &CFSet, value: *const c_void) -> bool {
extern "C-unwind" {
fn CFSetContainsValue(the_set: &CFSet, value: *const c_void) -> Boolean;
}
let ret = unsafe { CFSetContainsValue(self, value) };
ret != 0
}
/// Retrieves a value in the set which hashes the same as the specified value.
///
/// Parameter `theSet`: The set to be queried. If this parameter is not a
/// valid CFSet, the behavior is undefined.
///
/// Parameter `value`: The value to retrieve. The equal() callback provided when
/// the set was created is used to compare. If the equal() callback
/// was NULL, pointer equality (in C, ==) is used. If a value, or
/// any of the values in the set, are not understood by the equal()
/// callback, the behavior is undefined.
///
/// Returns: The value in the set with the given hash.
#[doc(alias = "CFSetGetValue")]
#[inline]
pub unsafe fn value(self: &CFSet, value: *const c_void) -> *const c_void {
extern "C-unwind" {
fn CFSetGetValue(the_set: &CFSet, value: *const c_void) -> *const c_void;
}
unsafe { CFSetGetValue(self, value) }
}
/// Retrieves a value in the set which hashes the same as the specified value,
/// if present.
///
/// Parameter `theSet`: The set to be queried. If this parameter is not a
/// valid CFSet, the behavior is undefined.
///
/// Parameter `candidate`: This value is hashed and compared with values in the
/// set to determine which value to retrieve. The equal() callback provided when
/// the set was created is used to compare. If the equal() callback
/// was NULL, pointer equality (in C, ==) is used. If a value, or
/// any of the values in the set, are not understood by the equal()
/// callback, the behavior is undefined.
///
/// Parameter `value`: A pointer to memory which should be filled with the
/// pointer-sized value if a matching value is found. If no
/// match is found, the contents of the storage pointed to by
/// this parameter are undefined. This parameter may be NULL,
/// in which case the value from the dictionary is not returned
/// (but the return value of this function still indicates
/// whether or not the value was present).
///
/// Returns: True if the value was present in the set, otherwise false.
#[doc(alias = "CFSetGetValueIfPresent")]
#[inline]
pub unsafe fn value_if_present(
self: &CFSet,
candidate: *const c_void,
value: *mut *const c_void,
) -> bool {
extern "C-unwind" {
fn CFSetGetValueIfPresent(
the_set: &CFSet,
candidate: *const c_void,
value: *mut *const c_void,
) -> Boolean;
}
let ret = unsafe { CFSetGetValueIfPresent(self, candidate, value) };
ret != 0
}
/// Fills the buffer with values from the set.
///
/// Parameter `theSet`: The set to be queried. If this parameter is not a
/// valid CFSet, the behavior is undefined.
///
/// Parameter `values`: A C array of pointer-sized values to be filled with
/// values from the set. The values in the C array are ordered
/// in the same order in which they appear in the set. If this
/// parameter is not a valid pointer to a C array of at least
/// CFSetGetCount() pointers, the behavior is undefined.
#[doc(alias = "CFSetGetValues")]
#[inline]
pub unsafe fn values(self: &CFSet, values: *mut *const c_void) {
extern "C-unwind" {
fn CFSetGetValues(the_set: &CFSet, values: *mut *const c_void);
}
unsafe { CFSetGetValues(self, values) }
}
/// Calls a function once for each value in the set.
///
/// Parameter `theSet`: The set to be operated upon. If this parameter is not
/// a valid CFSet, the behavior is undefined.
///
/// Parameter `applier`: The callback function to call once for each value in
/// the given set. If this parameter is not a
/// pointer to a function of the correct prototype, the behavior
/// is undefined. If there are values in the set which the
/// applier function does not expect or cannot properly apply
/// to, the behavior is undefined.
///
/// Parameter `context`: A pointer-sized user-defined value, which is passed
/// as the second parameter to the applier function, but is
/// otherwise unused by this function. If the context is not
/// what is expected by the applier function, the behavior is
/// undefined.
#[doc(alias = "CFSetApplyFunction")]
#[inline]
pub unsafe fn apply_function(
self: &CFSet,
applier: CFSetApplierFunction,
context: *mut c_void,
) {
extern "C-unwind" {
fn CFSetApplyFunction(
the_set: &CFSet,
applier: CFSetApplierFunction,
context: *mut c_void,
);
}
unsafe { CFSetApplyFunction(self, applier, context) }
}
}
impl CFMutableSet {
/// Adds the value to the set if it is not already present.
///
/// Parameter `theSet`: The set to which the value is to be added. If this
/// parameter is not a valid mutable CFSet, the behavior is
/// undefined.
///
/// Parameter `value`: The value to add to the set. The value is retained by
/// the set using the retain callback provided when the set
/// was created. If the value is not of the sort expected by the
/// retain callback, the behavior is undefined. The count of the
/// set is increased by one.
#[doc(alias = "CFSetAddValue")]
#[inline]
pub unsafe fn add_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
extern "C-unwind" {
fn CFSetAddValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
unsafe { CFSetAddValue(the_set, value) }
}
/// Replaces the value in the set if it is present.
///
/// Parameter `theSet`: The set to which the value is to be replaced. If this
/// parameter is not a valid mutable CFSet, the behavior is
/// undefined.
///
/// Parameter `value`: The value to replace in the set. The equal() callback provided when
/// the set was created is used to compare. If the equal() callback
/// was NULL, pointer equality (in C, ==) is used. If a value, or
/// any of the values in the set, are not understood by the equal()
/// callback, the behavior is undefined. The value is retained by
/// the set using the retain callback provided when the set
/// was created. If the value is not of the sort expected by the
/// retain callback, the behavior is undefined. The count of the
/// set is increased by one.
#[doc(alias = "CFSetReplaceValue")]
#[inline]
pub unsafe fn replace_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
extern "C-unwind" {
fn CFSetReplaceValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
unsafe { CFSetReplaceValue(the_set, value) }
}
/// Replaces the value in the set if it is present, or adds the value to
/// the set if it is absent.
///
/// Parameter `theSet`: The set to which the value is to be replaced. If this
/// parameter is not a valid mutable CFSet, the behavior is
/// undefined.
///
/// Parameter `value`: The value to set in the CFSet. The equal() callback provided when
/// the set was created is used to compare. If the equal() callback
/// was NULL, pointer equality (in C, ==) is used. If a value, or
/// any of the values in the set, are not understood by the equal()
/// callback, the behavior is undefined. The value is retained by
/// the set using the retain callback provided when the set
/// was created. If the value is not of the sort expected by the
/// retain callback, the behavior is undefined. The count of the
/// set is increased by one.
#[doc(alias = "CFSetSetValue")]
#[inline]
pub unsafe fn set_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
extern "C-unwind" {
fn CFSetSetValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
unsafe { CFSetSetValue(the_set, value) }
}
/// Removes the specified value from the set.
///
/// Parameter `theSet`: The set from which the value is to be removed.
/// If this parameter is not a valid mutable CFSet,
/// the behavior is undefined.
///
/// Parameter `value`: The value to remove. The equal() callback provided when
/// the set was created is used to compare. If the equal() callback
/// was NULL, pointer equality (in C, ==) is used. If a value, or
/// any of the values in the set, are not understood by the equal()
/// callback, the behavior is undefined.
#[doc(alias = "CFSetRemoveValue")]
#[inline]
pub unsafe fn remove_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
extern "C-unwind" {
fn CFSetRemoveValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
unsafe { CFSetRemoveValue(the_set, value) }
}
/// Removes all the values from the set, making it empty.
///
/// Parameter `theSet`: The set from which all of the values are to be
/// removed. If this parameter is not a valid mutable CFSet,
/// the behavior is undefined.
#[doc(alias = "CFSetRemoveAllValues")]
#[inline]
pub fn remove_all_values(the_set: Option<&CFMutableSet>) {
extern "C-unwind" {
fn CFSetRemoveAllValues(the_set: Option<&CFMutableSet>);
}
unsafe { CFSetRemoveAllValues(the_set) }
}
}
#[deprecated = "renamed to `CFSet::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSetCreate(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<CFRetained<CFSet>> {
extern "C-unwind" {
fn CFSetCreate(
allocator: Option<&CFAllocator>,
values: *mut *const c_void,
num_values: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<NonNull<CFSet>>;
}
let ret = unsafe { CFSetCreate(allocator, values, num_values, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFSet::new_copy`"]
#[inline]
pub extern "C-unwind" fn CFSetCreateCopy(
allocator: Option<&CFAllocator>,
the_set: Option<&CFSet>,
) -> Option<CFRetained<CFSet>> {
extern "C-unwind" {
fn CFSetCreateCopy(
allocator: Option<&CFAllocator>,
the_set: Option<&CFSet>,
) -> Option<NonNull<CFSet>>;
}
let ret = unsafe { CFSetCreateCopy(allocator, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableSet::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSetCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<CFRetained<CFMutableSet>> {
extern "C-unwind" {
fn CFSetCreateMutable(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
call_backs: *const CFSetCallBacks,
) -> Option<NonNull<CFMutableSet>>;
}
let ret = unsafe { CFSetCreateMutable(allocator, capacity, call_backs) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFMutableSet::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSetCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_set: Option<&CFSet>,
) -> Option<CFRetained<CFMutableSet>> {
extern "C-unwind" {
fn CFSetCreateMutableCopy(
allocator: Option<&CFAllocator>,
capacity: CFIndex,
the_set: Option<&CFSet>,
) -> Option<NonNull<CFMutableSet>>;
}
let ret = unsafe { CFSetCreateMutableCopy(allocator, capacity, the_set) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFSet::count`"]
#[inline]
pub extern "C-unwind" fn CFSetGetCount(the_set: &CFSet) -> CFIndex {
extern "C-unwind" {
fn CFSetGetCount(the_set: &CFSet) -> CFIndex;
}
unsafe { CFSetGetCount(the_set) }
}
extern "C-unwind" {
#[deprecated = "renamed to `CFSet::count_of_value`"]
pub fn CFSetGetCountOfValue(the_set: &CFSet, value: *const c_void) -> CFIndex;
}
#[deprecated = "renamed to `CFSet::contains_value`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSetContainsValue(the_set: &CFSet, value: *const c_void) -> bool {
extern "C-unwind" {
fn CFSetContainsValue(the_set: &CFSet, value: *const c_void) -> Boolean;
}
let ret = unsafe { CFSetContainsValue(the_set, value) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFSet::value`"]
pub fn CFSetGetValue(the_set: &CFSet, value: *const c_void) -> *const c_void;
}
#[deprecated = "renamed to `CFSet::value_if_present`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSetGetValueIfPresent(
the_set: &CFSet,
candidate: *const c_void,
value: *mut *const c_void,
) -> bool {
extern "C-unwind" {
fn CFSetGetValueIfPresent(
the_set: &CFSet,
candidate: *const c_void,
value: *mut *const c_void,
) -> Boolean;
}
let ret = unsafe { CFSetGetValueIfPresent(the_set, candidate, value) };
ret != 0
}
extern "C-unwind" {
#[deprecated = "renamed to `CFSet::values`"]
pub fn CFSetGetValues(the_set: &CFSet, values: *mut *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFSet::apply_function`"]
pub fn CFSetApplyFunction(the_set: &CFSet, applier: CFSetApplierFunction, context: *mut c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableSet::add_value`"]
pub fn CFSetAddValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableSet::replace_value`"]
pub fn CFSetReplaceValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableSet::set_value`"]
pub fn CFSetSetValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFMutableSet::remove_value`"]
pub fn CFSetRemoveValue(the_set: Option<&CFMutableSet>, value: *const c_void);
}
#[deprecated = "renamed to `CFMutableSet::remove_all_values`"]
#[inline]
pub extern "C-unwind" fn CFSetRemoveAllValues(the_set: Option<&CFMutableSet>) {
extern "C-unwind" {
fn CFSetRemoveAllValues(the_set: Option<&CFMutableSet>);
}
unsafe { CFSetRemoveAllValues(the_set) }
}

View File

@@ -0,0 +1,995 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocket?language=objc)
#[repr(C)]
pub struct CFSocket {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFSocket {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFSocket"> for CFSocket {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketerror?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFSocketError(pub CFIndex);
impl CFSocketError {
#[doc(alias = "kCFSocketSuccess")]
pub const Success: Self = Self(0);
#[doc(alias = "kCFSocketError")]
pub const Error: Self = Self(-1);
#[doc(alias = "kCFSocketTimeout")]
pub const Timeout: Self = Self(-2);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFSocketError {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFSocketError {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketsignature?language=objc)
#[cfg(feature = "CFData")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFSocketSignature {
pub protocolFamily: i32,
pub socketType: i32,
pub protocol: i32,
pub address: *const CFData,
}
#[cfg(all(feature = "CFData", feature = "objc2"))]
unsafe impl Encode for CFSocketSignature {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<i32>::ENCODING,
<i32>::ENCODING,
<i32>::ENCODING,
<*const CFData>::ENCODING,
],
);
}
#[cfg(all(feature = "CFData", feature = "objc2"))]
unsafe impl RefEncode for CFSocketSignature {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcallbacktype?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFSocketCallBackType(pub CFOptionFlags);
bitflags::bitflags! {
impl CFSocketCallBackType: CFOptionFlags {
#[doc(alias = "kCFSocketNoCallBack")]
const NoCallBack = 0;
#[doc(alias = "kCFSocketReadCallBack")]
const ReadCallBack = 1;
#[doc(alias = "kCFSocketAcceptCallBack")]
const AcceptCallBack = 2;
#[doc(alias = "kCFSocketDataCallBack")]
const DataCallBack = 3;
#[doc(alias = "kCFSocketConnectCallBack")]
const ConnectCallBack = 4;
#[doc(alias = "kCFSocketWriteCallBack")]
const WriteCallBack = 8;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFSocketCallBackType {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFSocketCallBackType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenablereadcallback?language=objc)
pub const kCFSocketAutomaticallyReenableReadCallBack: CFOptionFlags = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenableacceptcallback?language=objc)
pub const kCFSocketAutomaticallyReenableAcceptCallBack: CFOptionFlags = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenabledatacallback?language=objc)
pub const kCFSocketAutomaticallyReenableDataCallBack: CFOptionFlags = 3;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenablewritecallback?language=objc)
pub const kCFSocketAutomaticallyReenableWriteCallBack: CFOptionFlags = 8;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketleaveerrors?language=objc)
pub const kCFSocketLeaveErrors: CFOptionFlags = 64;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketcloseoninvalidate?language=objc)
pub const kCFSocketCloseOnInvalidate: CFOptionFlags = 128;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcallback?language=objc)
#[cfg(feature = "CFData")]
pub type CFSocketCallBack = Option<
unsafe extern "C-unwind" fn(
*mut CFSocket,
CFSocketCallBackType,
*const CFData,
*const c_void,
*mut c_void,
),
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFSocketContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFSocketContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFSocketContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketnativehandle?language=objc)
pub type CFSocketNativeHandle = c_int;
unsafe impl ConcreteType for CFSocket {
#[doc(alias = "CFSocketGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFSocketGetTypeID() -> CFTypeID;
}
unsafe { CFSocketGetTypeID() }
}
}
impl CFSocket {
#[doc(alias = "CFSocketCreate")]
#[cfg(feature = "CFData")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
protocol_family: i32,
socket_type: i32,
protocol: i32,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreate(
allocator: Option<&CFAllocator>,
protocol_family: i32,
socket_type: i32,
protocol: i32,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<NonNull<CFSocket>>;
}
let ret = unsafe {
CFSocketCreate(
allocator,
protocol_family,
socket_type,
protocol,
call_back_types,
callout,
context,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFSocketCreateWithNative")]
#[cfg(feature = "CFData")]
#[inline]
pub unsafe fn with_native(
allocator: Option<&CFAllocator>,
sock: CFSocketNativeHandle,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreateWithNative(
allocator: Option<&CFAllocator>,
sock: CFSocketNativeHandle,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<NonNull<CFSocket>>;
}
let ret =
unsafe { CFSocketCreateWithNative(allocator, sock, call_back_types, callout, context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFSocketCreateWithSocketSignature")]
#[cfg(feature = "CFData")]
#[inline]
pub unsafe fn with_socket_signature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreateWithSocketSignature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<NonNull<CFSocket>>;
}
let ret = unsafe {
CFSocketCreateWithSocketSignature(
allocator,
signature,
call_back_types,
callout,
context,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFSocketCreateConnectedToSocketSignature")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn new_connected_to_socket_signature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
timeout: CFTimeInterval,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreateConnectedToSocketSignature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
timeout: CFTimeInterval,
) -> Option<NonNull<CFSocket>>;
}
let ret = unsafe {
CFSocketCreateConnectedToSocketSignature(
allocator,
signature,
call_back_types,
callout,
context,
timeout,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFSocketSetAddress")]
#[cfg(feature = "CFData")]
#[inline]
pub fn set_address(self: &CFSocket, address: Option<&CFData>) -> CFSocketError {
extern "C-unwind" {
fn CFSocketSetAddress(s: &CFSocket, address: Option<&CFData>) -> CFSocketError;
}
unsafe { CFSocketSetAddress(self, address) }
}
#[doc(alias = "CFSocketConnectToAddress")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub fn connect_to_address(
self: &CFSocket,
address: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketConnectToAddress(
s: &CFSocket,
address: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError;
}
unsafe { CFSocketConnectToAddress(self, address, timeout) }
}
#[doc(alias = "CFSocketInvalidate")]
#[inline]
pub fn invalidate(self: &CFSocket) {
extern "C-unwind" {
fn CFSocketInvalidate(s: &CFSocket);
}
unsafe { CFSocketInvalidate(self) }
}
#[doc(alias = "CFSocketIsValid")]
#[inline]
pub fn is_valid(self: &CFSocket) -> bool {
extern "C-unwind" {
fn CFSocketIsValid(s: &CFSocket) -> Boolean;
}
let ret = unsafe { CFSocketIsValid(self) };
ret != 0
}
#[doc(alias = "CFSocketCopyAddress")]
#[cfg(feature = "CFData")]
#[inline]
pub fn address(self: &CFSocket) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFSocketCopyAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFSocketCopyAddress(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFSocketCopyPeerAddress")]
#[cfg(feature = "CFData")]
#[inline]
pub fn peer_address(self: &CFSocket) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFSocketCopyPeerAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFSocketCopyPeerAddress(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFSocketGetContext")]
#[inline]
pub unsafe fn context(self: &CFSocket, context: *mut CFSocketContext) {
extern "C-unwind" {
fn CFSocketGetContext(s: &CFSocket, context: *mut CFSocketContext);
}
unsafe { CFSocketGetContext(self, context) }
}
#[doc(alias = "CFSocketGetNative")]
#[inline]
pub fn native(self: &CFSocket) -> CFSocketNativeHandle {
extern "C-unwind" {
fn CFSocketGetNative(s: &CFSocket) -> CFSocketNativeHandle;
}
unsafe { CFSocketGetNative(self) }
}
#[doc(alias = "CFSocketCreateRunLoopSource")]
#[cfg(feature = "CFRunLoop")]
#[inline]
pub fn new_run_loop_source(
allocator: Option<&CFAllocator>,
s: Option<&CFSocket>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFSocketCreateRunLoopSource(
allocator: Option<&CFAllocator>,
s: Option<&CFSocket>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFSocketCreateRunLoopSource(allocator, s, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFSocketGetSocketFlags")]
#[inline]
pub fn socket_flags(self: &CFSocket) -> CFOptionFlags {
extern "C-unwind" {
fn CFSocketGetSocketFlags(s: &CFSocket) -> CFOptionFlags;
}
unsafe { CFSocketGetSocketFlags(self) }
}
#[doc(alias = "CFSocketSetSocketFlags")]
#[inline]
pub fn set_socket_flags(self: &CFSocket, flags: CFOptionFlags) {
extern "C-unwind" {
fn CFSocketSetSocketFlags(s: &CFSocket, flags: CFOptionFlags);
}
unsafe { CFSocketSetSocketFlags(self, flags) }
}
#[doc(alias = "CFSocketDisableCallBacks")]
#[inline]
pub fn disable_call_backs(self: &CFSocket, call_back_types: CFOptionFlags) {
extern "C-unwind" {
fn CFSocketDisableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
}
unsafe { CFSocketDisableCallBacks(self, call_back_types) }
}
#[doc(alias = "CFSocketEnableCallBacks")]
#[inline]
pub fn enable_call_backs(self: &CFSocket, call_back_types: CFOptionFlags) {
extern "C-unwind" {
fn CFSocketEnableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
}
unsafe { CFSocketEnableCallBacks(self, call_back_types) }
}
#[doc(alias = "CFSocketSendData")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub fn send_data(
self: &CFSocket,
address: Option<&CFData>,
data: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketSendData(
s: &CFSocket,
address: Option<&CFData>,
data: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError;
}
unsafe { CFSocketSendData(self, address, data, timeout) }
}
#[doc(alias = "CFSocketRegisterValue")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn register_value(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
value: Option<&CFPropertyList>,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketRegisterValue(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
value: Option<&CFPropertyList>,
) -> CFSocketError;
}
unsafe { CFSocketRegisterValue(name_server_signature, timeout, name, value) }
}
#[doc(alias = "CFSocketCopyRegisteredValue")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn copy_registered_value(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
value: *mut *const CFPropertyList,
name_server_address: *mut *const CFData,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketCopyRegisteredValue(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
value: *mut *const CFPropertyList,
name_server_address: *mut *const CFData,
) -> CFSocketError;
}
unsafe {
CFSocketCopyRegisteredValue(
name_server_signature,
timeout,
name,
value,
name_server_address,
)
}
}
#[doc(alias = "CFSocketRegisterSocketSignature")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn register_socket_signature(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
signature: *const CFSocketSignature,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketRegisterSocketSignature(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
signature: *const CFSocketSignature,
) -> CFSocketError;
}
unsafe { CFSocketRegisterSocketSignature(name_server_signature, timeout, name, signature) }
}
#[doc(alias = "CFSocketCopyRegisteredSocketSignature")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn copy_registered_socket_signature(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
signature: *mut CFSocketSignature,
name_server_address: *mut *const CFData,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketCopyRegisteredSocketSignature(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
signature: *mut CFSocketSignature,
name_server_address: *mut *const CFData,
) -> CFSocketError;
}
unsafe {
CFSocketCopyRegisteredSocketSignature(
name_server_signature,
timeout,
name,
signature,
name_server_address,
)
}
}
#[doc(alias = "CFSocketUnregister")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn unregister(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketUnregister(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
) -> CFSocketError;
}
unsafe { CFSocketUnregister(name_server_signature, timeout, name) }
}
#[doc(alias = "CFSocketSetDefaultNameRegistryPortNumber")]
#[inline]
pub fn set_default_name_registry_port_number(port: u16) {
extern "C-unwind" {
fn CFSocketSetDefaultNameRegistryPortNumber(port: u16);
}
unsafe { CFSocketSetDefaultNameRegistryPortNumber(port) }
}
#[doc(alias = "CFSocketGetDefaultNameRegistryPortNumber")]
#[inline]
pub fn default_name_registry_port_number() -> u16 {
extern "C-unwind" {
fn CFSocketGetDefaultNameRegistryPortNumber() -> u16;
}
unsafe { CFSocketGetDefaultNameRegistryPortNumber() }
}
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketcommandkey?language=objc)
pub static kCFSocketCommandKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketnamekey?language=objc)
pub static kCFSocketNameKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketvaluekey?language=objc)
pub static kCFSocketValueKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketresultkey?language=objc)
pub static kCFSocketResultKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketerrorkey?language=objc)
pub static kCFSocketErrorKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketregistercommand?language=objc)
pub static kCFSocketRegisterCommand: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketretrievecommand?language=objc)
pub static kCFSocketRetrieveCommand: Option<&'static CFString>;
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFSocket::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSocketCreate(
allocator: Option<&CFAllocator>,
protocol_family: i32,
socket_type: i32,
protocol: i32,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreate(
allocator: Option<&CFAllocator>,
protocol_family: i32,
socket_type: i32,
protocol: i32,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<NonNull<CFSocket>>;
}
let ret = unsafe {
CFSocketCreate(
allocator,
protocol_family,
socket_type,
protocol,
call_back_types,
callout,
context,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFSocket::with_native`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSocketCreateWithNative(
allocator: Option<&CFAllocator>,
sock: CFSocketNativeHandle,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreateWithNative(
allocator: Option<&CFAllocator>,
sock: CFSocketNativeHandle,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<NonNull<CFSocket>>;
}
let ret =
unsafe { CFSocketCreateWithNative(allocator, sock, call_back_types, callout, context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFSocket::with_socket_signature`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSocketCreateWithSocketSignature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreateWithSocketSignature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
) -> Option<NonNull<CFSocket>>;
}
let ret = unsafe {
CFSocketCreateWithSocketSignature(allocator, signature, call_back_types, callout, context)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::new_connected_to_socket_signature`"]
#[inline]
pub unsafe extern "C-unwind" fn CFSocketCreateConnectedToSocketSignature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
timeout: CFTimeInterval,
) -> Option<CFRetained<CFSocket>> {
extern "C-unwind" {
fn CFSocketCreateConnectedToSocketSignature(
allocator: Option<&CFAllocator>,
signature: *const CFSocketSignature,
call_back_types: CFOptionFlags,
callout: CFSocketCallBack,
context: *const CFSocketContext,
timeout: CFTimeInterval,
) -> Option<NonNull<CFSocket>>;
}
let ret = unsafe {
CFSocketCreateConnectedToSocketSignature(
allocator,
signature,
call_back_types,
callout,
context,
timeout,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFSocket::set_address`"]
#[inline]
pub extern "C-unwind" fn CFSocketSetAddress(
s: &CFSocket,
address: Option<&CFData>,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketSetAddress(s: &CFSocket, address: Option<&CFData>) -> CFSocketError;
}
unsafe { CFSocketSetAddress(s, address) }
}
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::connect_to_address`"]
#[inline]
pub extern "C-unwind" fn CFSocketConnectToAddress(
s: &CFSocket,
address: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketConnectToAddress(
s: &CFSocket,
address: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError;
}
unsafe { CFSocketConnectToAddress(s, address, timeout) }
}
#[deprecated = "renamed to `CFSocket::invalidate`"]
#[inline]
pub extern "C-unwind" fn CFSocketInvalidate(s: &CFSocket) {
extern "C-unwind" {
fn CFSocketInvalidate(s: &CFSocket);
}
unsafe { CFSocketInvalidate(s) }
}
#[deprecated = "renamed to `CFSocket::is_valid`"]
#[inline]
pub extern "C-unwind" fn CFSocketIsValid(s: &CFSocket) -> bool {
extern "C-unwind" {
fn CFSocketIsValid(s: &CFSocket) -> Boolean;
}
let ret = unsafe { CFSocketIsValid(s) };
ret != 0
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFSocket::address`"]
#[inline]
pub extern "C-unwind" fn CFSocketCopyAddress(s: &CFSocket) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFSocketCopyAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFSocketCopyAddress(s) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFData")]
#[deprecated = "renamed to `CFSocket::peer_address`"]
#[inline]
pub extern "C-unwind" fn CFSocketCopyPeerAddress(s: &CFSocket) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFSocketCopyPeerAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFSocketCopyPeerAddress(s) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFSocket::context`"]
pub fn CFSocketGetContext(s: &CFSocket, context: *mut CFSocketContext);
}
#[deprecated = "renamed to `CFSocket::native`"]
#[inline]
pub extern "C-unwind" fn CFSocketGetNative(s: &CFSocket) -> CFSocketNativeHandle {
extern "C-unwind" {
fn CFSocketGetNative(s: &CFSocket) -> CFSocketNativeHandle;
}
unsafe { CFSocketGetNative(s) }
}
#[cfg(feature = "CFRunLoop")]
#[deprecated = "renamed to `CFSocket::new_run_loop_source`"]
#[inline]
pub extern "C-unwind" fn CFSocketCreateRunLoopSource(
allocator: Option<&CFAllocator>,
s: Option<&CFSocket>,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFSocketCreateRunLoopSource(
allocator: Option<&CFAllocator>,
s: Option<&CFSocket>,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe { CFSocketCreateRunLoopSource(allocator, s, order) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFSocket::socket_flags`"]
#[inline]
pub extern "C-unwind" fn CFSocketGetSocketFlags(s: &CFSocket) -> CFOptionFlags {
extern "C-unwind" {
fn CFSocketGetSocketFlags(s: &CFSocket) -> CFOptionFlags;
}
unsafe { CFSocketGetSocketFlags(s) }
}
#[deprecated = "renamed to `CFSocket::set_socket_flags`"]
#[inline]
pub extern "C-unwind" fn CFSocketSetSocketFlags(s: &CFSocket, flags: CFOptionFlags) {
extern "C-unwind" {
fn CFSocketSetSocketFlags(s: &CFSocket, flags: CFOptionFlags);
}
unsafe { CFSocketSetSocketFlags(s, flags) }
}
#[deprecated = "renamed to `CFSocket::disable_call_backs`"]
#[inline]
pub extern "C-unwind" fn CFSocketDisableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags) {
extern "C-unwind" {
fn CFSocketDisableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
}
unsafe { CFSocketDisableCallBacks(s, call_back_types) }
}
#[deprecated = "renamed to `CFSocket::enable_call_backs`"]
#[inline]
pub extern "C-unwind" fn CFSocketEnableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags) {
extern "C-unwind" {
fn CFSocketEnableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
}
unsafe { CFSocketEnableCallBacks(s, call_back_types) }
}
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::send_data`"]
#[inline]
pub extern "C-unwind" fn CFSocketSendData(
s: &CFSocket,
address: Option<&CFData>,
data: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError {
extern "C-unwind" {
fn CFSocketSendData(
s: &CFSocket,
address: Option<&CFData>,
data: Option<&CFData>,
timeout: CFTimeInterval,
) -> CFSocketError;
}
unsafe { CFSocketSendData(s, address, data, timeout) }
}
extern "C-unwind" {
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::register_value`"]
pub fn CFSocketRegisterValue(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
value: Option<&CFPropertyList>,
) -> CFSocketError;
}
extern "C-unwind" {
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::copy_registered_value`"]
pub fn CFSocketCopyRegisteredValue(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
value: *mut *const CFPropertyList,
name_server_address: *mut *const CFData,
) -> CFSocketError;
}
extern "C-unwind" {
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::register_socket_signature`"]
pub fn CFSocketRegisterSocketSignature(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
signature: *const CFSocketSignature,
) -> CFSocketError;
}
extern "C-unwind" {
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::copy_registered_socket_signature`"]
pub fn CFSocketCopyRegisteredSocketSignature(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
signature: *mut CFSocketSignature,
name_server_address: *mut *const CFData,
) -> CFSocketError;
}
extern "C-unwind" {
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFSocket::unregister`"]
pub fn CFSocketUnregister(
name_server_signature: *const CFSocketSignature,
timeout: CFTimeInterval,
name: Option<&CFString>,
) -> CFSocketError;
}
#[deprecated = "renamed to `CFSocket::set_default_name_registry_port_number`"]
#[inline]
pub extern "C-unwind" fn CFSocketSetDefaultNameRegistryPortNumber(port: u16) {
extern "C-unwind" {
fn CFSocketSetDefaultNameRegistryPortNumber(port: u16);
}
unsafe { CFSocketSetDefaultNameRegistryPortNumber(port) }
}
#[deprecated = "renamed to `CFSocket::default_name_registry_port_number`"]
#[inline]
pub extern "C-unwind" fn CFSocketGetDefaultNameRegistryPortNumber() -> u16 {
extern "C-unwind" {
fn CFSocketGetDefaultNameRegistryPortNumber() -> u16;
}
unsafe { CFSocketGetDefaultNameRegistryPortNumber() }
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,282 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfstringencodings?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFStringEncodings(pub CFIndex);
impl CFStringEncodings {
#[doc(alias = "kCFStringEncodingMacJapanese")]
pub const MacJapanese: Self = Self(1);
#[doc(alias = "kCFStringEncodingMacChineseTrad")]
pub const MacChineseTrad: Self = Self(2);
#[doc(alias = "kCFStringEncodingMacKorean")]
pub const MacKorean: Self = Self(3);
#[doc(alias = "kCFStringEncodingMacArabic")]
pub const MacArabic: Self = Self(4);
#[doc(alias = "kCFStringEncodingMacHebrew")]
pub const MacHebrew: Self = Self(5);
#[doc(alias = "kCFStringEncodingMacGreek")]
pub const MacGreek: Self = Self(6);
#[doc(alias = "kCFStringEncodingMacCyrillic")]
pub const MacCyrillic: Self = Self(7);
#[doc(alias = "kCFStringEncodingMacDevanagari")]
pub const MacDevanagari: Self = Self(9);
#[doc(alias = "kCFStringEncodingMacGurmukhi")]
pub const MacGurmukhi: Self = Self(10);
#[doc(alias = "kCFStringEncodingMacGujarati")]
pub const MacGujarati: Self = Self(11);
#[doc(alias = "kCFStringEncodingMacOriya")]
pub const MacOriya: Self = Self(12);
#[doc(alias = "kCFStringEncodingMacBengali")]
pub const MacBengali: Self = Self(13);
#[doc(alias = "kCFStringEncodingMacTamil")]
pub const MacTamil: Self = Self(14);
#[doc(alias = "kCFStringEncodingMacTelugu")]
pub const MacTelugu: Self = Self(15);
#[doc(alias = "kCFStringEncodingMacKannada")]
pub const MacKannada: Self = Self(16);
#[doc(alias = "kCFStringEncodingMacMalayalam")]
pub const MacMalayalam: Self = Self(17);
#[doc(alias = "kCFStringEncodingMacSinhalese")]
pub const MacSinhalese: Self = Self(18);
#[doc(alias = "kCFStringEncodingMacBurmese")]
pub const MacBurmese: Self = Self(19);
#[doc(alias = "kCFStringEncodingMacKhmer")]
pub const MacKhmer: Self = Self(20);
#[doc(alias = "kCFStringEncodingMacThai")]
pub const MacThai: Self = Self(21);
#[doc(alias = "kCFStringEncodingMacLaotian")]
pub const MacLaotian: Self = Self(22);
#[doc(alias = "kCFStringEncodingMacGeorgian")]
pub const MacGeorgian: Self = Self(23);
#[doc(alias = "kCFStringEncodingMacArmenian")]
pub const MacArmenian: Self = Self(24);
#[doc(alias = "kCFStringEncodingMacChineseSimp")]
pub const MacChineseSimp: Self = Self(25);
#[doc(alias = "kCFStringEncodingMacTibetan")]
pub const MacTibetan: Self = Self(26);
#[doc(alias = "kCFStringEncodingMacMongolian")]
pub const MacMongolian: Self = Self(27);
#[doc(alias = "kCFStringEncodingMacEthiopic")]
pub const MacEthiopic: Self = Self(28);
#[doc(alias = "kCFStringEncodingMacCentralEurRoman")]
pub const MacCentralEurRoman: Self = Self(29);
#[doc(alias = "kCFStringEncodingMacVietnamese")]
pub const MacVietnamese: Self = Self(30);
#[doc(alias = "kCFStringEncodingMacExtArabic")]
pub const MacExtArabic: Self = Self(31);
#[doc(alias = "kCFStringEncodingMacSymbol")]
pub const MacSymbol: Self = Self(33);
#[doc(alias = "kCFStringEncodingMacDingbats")]
pub const MacDingbats: Self = Self(34);
#[doc(alias = "kCFStringEncodingMacTurkish")]
pub const MacTurkish: Self = Self(35);
#[doc(alias = "kCFStringEncodingMacCroatian")]
pub const MacCroatian: Self = Self(36);
#[doc(alias = "kCFStringEncodingMacIcelandic")]
pub const MacIcelandic: Self = Self(37);
#[doc(alias = "kCFStringEncodingMacRomanian")]
pub const MacRomanian: Self = Self(38);
#[doc(alias = "kCFStringEncodingMacCeltic")]
pub const MacCeltic: Self = Self(39);
#[doc(alias = "kCFStringEncodingMacGaelic")]
pub const MacGaelic: Self = Self(40);
#[doc(alias = "kCFStringEncodingMacFarsi")]
pub const MacFarsi: Self = Self(0x8C);
#[doc(alias = "kCFStringEncodingMacUkrainian")]
pub const MacUkrainian: Self = Self(0x98);
#[doc(alias = "kCFStringEncodingMacInuit")]
pub const MacInuit: Self = Self(0xEC);
#[doc(alias = "kCFStringEncodingMacVT100")]
pub const MacVT100: Self = Self(0xFC);
#[doc(alias = "kCFStringEncodingMacHFS")]
pub const MacHFS: Self = Self(0xFF);
#[doc(alias = "kCFStringEncodingISOLatin2")]
pub const ISOLatin2: Self = Self(0x0202);
#[doc(alias = "kCFStringEncodingISOLatin3")]
pub const ISOLatin3: Self = Self(0x0203);
#[doc(alias = "kCFStringEncodingISOLatin4")]
pub const ISOLatin4: Self = Self(0x0204);
#[doc(alias = "kCFStringEncodingISOLatinCyrillic")]
pub const ISOLatinCyrillic: Self = Self(0x0205);
#[doc(alias = "kCFStringEncodingISOLatinArabic")]
pub const ISOLatinArabic: Self = Self(0x0206);
#[doc(alias = "kCFStringEncodingISOLatinGreek")]
pub const ISOLatinGreek: Self = Self(0x0207);
#[doc(alias = "kCFStringEncodingISOLatinHebrew")]
pub const ISOLatinHebrew: Self = Self(0x0208);
#[doc(alias = "kCFStringEncodingISOLatin5")]
pub const ISOLatin5: Self = Self(0x0209);
#[doc(alias = "kCFStringEncodingISOLatin6")]
pub const ISOLatin6: Self = Self(0x020A);
#[doc(alias = "kCFStringEncodingISOLatinThai")]
pub const ISOLatinThai: Self = Self(0x020B);
#[doc(alias = "kCFStringEncodingISOLatin7")]
pub const ISOLatin7: Self = Self(0x020D);
#[doc(alias = "kCFStringEncodingISOLatin8")]
pub const ISOLatin8: Self = Self(0x020E);
#[doc(alias = "kCFStringEncodingISOLatin9")]
pub const ISOLatin9: Self = Self(0x020F);
#[doc(alias = "kCFStringEncodingISOLatin10")]
pub const ISOLatin10: Self = Self(0x0210);
#[doc(alias = "kCFStringEncodingDOSLatinUS")]
pub const DOSLatinUS: Self = Self(0x0400);
#[doc(alias = "kCFStringEncodingDOSGreek")]
pub const DOSGreek: Self = Self(0x0405);
#[doc(alias = "kCFStringEncodingDOSBalticRim")]
pub const DOSBalticRim: Self = Self(0x0406);
#[doc(alias = "kCFStringEncodingDOSLatin1")]
pub const DOSLatin1: Self = Self(0x0410);
#[doc(alias = "kCFStringEncodingDOSGreek1")]
pub const DOSGreek1: Self = Self(0x0411);
#[doc(alias = "kCFStringEncodingDOSLatin2")]
pub const DOSLatin2: Self = Self(0x0412);
#[doc(alias = "kCFStringEncodingDOSCyrillic")]
pub const DOSCyrillic: Self = Self(0x0413);
#[doc(alias = "kCFStringEncodingDOSTurkish")]
pub const DOSTurkish: Self = Self(0x0414);
#[doc(alias = "kCFStringEncodingDOSPortuguese")]
pub const DOSPortuguese: Self = Self(0x0415);
#[doc(alias = "kCFStringEncodingDOSIcelandic")]
pub const DOSIcelandic: Self = Self(0x0416);
#[doc(alias = "kCFStringEncodingDOSHebrew")]
pub const DOSHebrew: Self = Self(0x0417);
#[doc(alias = "kCFStringEncodingDOSCanadianFrench")]
pub const DOSCanadianFrench: Self = Self(0x0418);
#[doc(alias = "kCFStringEncodingDOSArabic")]
pub const DOSArabic: Self = Self(0x0419);
#[doc(alias = "kCFStringEncodingDOSNordic")]
pub const DOSNordic: Self = Self(0x041A);
#[doc(alias = "kCFStringEncodingDOSRussian")]
pub const DOSRussian: Self = Self(0x041B);
#[doc(alias = "kCFStringEncodingDOSGreek2")]
pub const DOSGreek2: Self = Self(0x041C);
#[doc(alias = "kCFStringEncodingDOSThai")]
pub const DOSThai: Self = Self(0x041D);
#[doc(alias = "kCFStringEncodingDOSJapanese")]
pub const DOSJapanese: Self = Self(0x0420);
#[doc(alias = "kCFStringEncodingDOSChineseSimplif")]
pub const DOSChineseSimplif: Self = Self(0x0421);
#[doc(alias = "kCFStringEncodingDOSKorean")]
pub const DOSKorean: Self = Self(0x0422);
#[doc(alias = "kCFStringEncodingDOSChineseTrad")]
pub const DOSChineseTrad: Self = Self(0x0423);
#[doc(alias = "kCFStringEncodingWindowsLatin2")]
pub const WindowsLatin2: Self = Self(0x0501);
#[doc(alias = "kCFStringEncodingWindowsCyrillic")]
pub const WindowsCyrillic: Self = Self(0x0502);
#[doc(alias = "kCFStringEncodingWindowsGreek")]
pub const WindowsGreek: Self = Self(0x0503);
#[doc(alias = "kCFStringEncodingWindowsLatin5")]
pub const WindowsLatin5: Self = Self(0x0504);
#[doc(alias = "kCFStringEncodingWindowsHebrew")]
pub const WindowsHebrew: Self = Self(0x0505);
#[doc(alias = "kCFStringEncodingWindowsArabic")]
pub const WindowsArabic: Self = Self(0x0506);
#[doc(alias = "kCFStringEncodingWindowsBalticRim")]
pub const WindowsBalticRim: Self = Self(0x0507);
#[doc(alias = "kCFStringEncodingWindowsVietnamese")]
pub const WindowsVietnamese: Self = Self(0x0508);
#[doc(alias = "kCFStringEncodingWindowsKoreanJohab")]
pub const WindowsKoreanJohab: Self = Self(0x0510);
#[doc(alias = "kCFStringEncodingANSEL")]
pub const ANSEL: Self = Self(0x0601);
#[doc(alias = "kCFStringEncodingJIS_X0201_76")]
pub const JIS_X0201_76: Self = Self(0x0620);
#[doc(alias = "kCFStringEncodingJIS_X0208_83")]
pub const JIS_X0208_83: Self = Self(0x0621);
#[doc(alias = "kCFStringEncodingJIS_X0208_90")]
pub const JIS_X0208_90: Self = Self(0x0622);
#[doc(alias = "kCFStringEncodingJIS_X0212_90")]
pub const JIS_X0212_90: Self = Self(0x0623);
#[doc(alias = "kCFStringEncodingJIS_C6226_78")]
pub const JIS_C6226_78: Self = Self(0x0624);
#[doc(alias = "kCFStringEncodingShiftJIS_X0213")]
pub const ShiftJIS_X0213: Self = Self(0x0628);
#[doc(alias = "kCFStringEncodingShiftJIS_X0213_MenKuTen")]
pub const ShiftJIS_X0213_MenKuTen: Self = Self(0x0629);
#[doc(alias = "kCFStringEncodingGB_2312_80")]
pub const GB_2312_80: Self = Self(0x0630);
#[doc(alias = "kCFStringEncodingGBK_95")]
pub const GBK_95: Self = Self(0x0631);
#[doc(alias = "kCFStringEncodingGB_18030_2000")]
pub const GB_18030_2000: Self = Self(0x0632);
#[doc(alias = "kCFStringEncodingKSC_5601_87")]
pub const KSC_5601_87: Self = Self(0x0640);
#[doc(alias = "kCFStringEncodingKSC_5601_92_Johab")]
pub const KSC_5601_92_Johab: Self = Self(0x0641);
#[doc(alias = "kCFStringEncodingCNS_11643_92_P1")]
pub const CNS_11643_92_P1: Self = Self(0x0651);
#[doc(alias = "kCFStringEncodingCNS_11643_92_P2")]
pub const CNS_11643_92_P2: Self = Self(0x0652);
#[doc(alias = "kCFStringEncodingCNS_11643_92_P3")]
pub const CNS_11643_92_P3: Self = Self(0x0653);
#[doc(alias = "kCFStringEncodingISO_2022_JP")]
pub const ISO_2022_JP: Self = Self(0x0820);
#[doc(alias = "kCFStringEncodingISO_2022_JP_2")]
pub const ISO_2022_JP_2: Self = Self(0x0821);
#[doc(alias = "kCFStringEncodingISO_2022_JP_1")]
pub const ISO_2022_JP_1: Self = Self(0x0822);
#[doc(alias = "kCFStringEncodingISO_2022_JP_3")]
pub const ISO_2022_JP_3: Self = Self(0x0823);
#[doc(alias = "kCFStringEncodingISO_2022_CN")]
pub const ISO_2022_CN: Self = Self(0x0830);
#[doc(alias = "kCFStringEncodingISO_2022_CN_EXT")]
pub const ISO_2022_CN_EXT: Self = Self(0x0831);
#[doc(alias = "kCFStringEncodingISO_2022_KR")]
pub const ISO_2022_KR: Self = Self(0x0840);
#[doc(alias = "kCFStringEncodingEUC_JP")]
pub const EUC_JP: Self = Self(0x0920);
#[doc(alias = "kCFStringEncodingEUC_CN")]
pub const EUC_CN: Self = Self(0x0930);
#[doc(alias = "kCFStringEncodingEUC_TW")]
pub const EUC_TW: Self = Self(0x0931);
#[doc(alias = "kCFStringEncodingEUC_KR")]
pub const EUC_KR: Self = Self(0x0940);
#[doc(alias = "kCFStringEncodingShiftJIS")]
pub const ShiftJIS: Self = Self(0x0A01);
#[doc(alias = "kCFStringEncodingKOI8_R")]
pub const KOI8_R: Self = Self(0x0A02);
#[doc(alias = "kCFStringEncodingBig5")]
pub const Big5: Self = Self(0x0A03);
#[doc(alias = "kCFStringEncodingMacRomanLatin1")]
pub const MacRomanLatin1: Self = Self(0x0A04);
#[doc(alias = "kCFStringEncodingHZ_GB_2312")]
pub const HZ_GB_2312: Self = Self(0x0A05);
#[doc(alias = "kCFStringEncodingBig5_HKSCS_1999")]
pub const Big5_HKSCS_1999: Self = Self(0x0A06);
#[doc(alias = "kCFStringEncodingVISCII")]
pub const VISCII: Self = Self(0x0A07);
#[doc(alias = "kCFStringEncodingKOI8_U")]
pub const KOI8_U: Self = Self(0x0A08);
#[doc(alias = "kCFStringEncodingBig5_E")]
pub const Big5_E: Self = Self(0x0A09);
#[doc(alias = "kCFStringEncodingNextStepJapanese")]
pub const NextStepJapanese: Self = Self(0x0B02);
#[doc(alias = "kCFStringEncodingEBCDIC_US")]
pub const EBCDIC_US: Self = Self(0x0C01);
#[doc(alias = "kCFStringEncodingEBCDIC_CP037")]
pub const EBCDIC_CP037: Self = Self(0x0C02);
#[doc(alias = "kCFStringEncodingUTF7")]
pub const UTF7: Self = Self(0x04000100);
#[doc(alias = "kCFStringEncodingUTF7_IMAP")]
pub const UTF7_IMAP: Self = Self(0x0A10);
#[doc(alias = "kCFStringEncodingShiftJIS_X0213_00")]
pub const ShiftJIS_X0213_00: Self = Self(0x0628);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFStringEncodings {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFStringEncodings {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

View File

@@ -0,0 +1,486 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
impl CFStringTokenizer {
/// Guesses the language of a string and returns the BCP 47 string of the
/// language.
///
/// Parameter `string`: The string whose language is to be guessed.
///
/// Parameter `range`: The range of characters in string whose language to be
/// guessed. The specified range must not exceed the bounds of the string.
///
/// Returns: A language represented in BCP 47 string. NULL is returned either if
/// string is NULL, the location of range is negative, the length of range
/// is 0, or the language of the string cannot be guessed.
///
/// The result is not guaranteed to be accurate. Typically 200-400
/// characters are required to reliably guess the language of a string.
#[doc(alias = "CFStringTokenizerCopyBestStringLanguage")]
#[inline]
pub unsafe fn best_string_language(
string: &CFString,
range: CFRange,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFStringTokenizerCopyBestStringLanguage(
string: &CFString,
range: CFRange,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFStringTokenizerCopyBestStringLanguage(string, range) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfstringtokenizer?language=objc)
#[repr(C)]
pub struct CFStringTokenizer {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFStringTokenizer {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFStringTokenizer"> for CFStringTokenizer {}
);
/// Tokenization Unit
/// Use one of tokenization unit options with CFStringTokenizerCreate to
/// specify how the string should be tokenized.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitword?language=objc)
pub const kCFStringTokenizerUnitWord: CFOptionFlags = 0;
/// Tokenization Unit
/// Use one of tokenization unit options with CFStringTokenizerCreate to
/// specify how the string should be tokenized.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitsentence?language=objc)
pub const kCFStringTokenizerUnitSentence: CFOptionFlags = 1;
/// Tokenization Unit
/// Use one of tokenization unit options with CFStringTokenizerCreate to
/// specify how the string should be tokenized.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitparagraph?language=objc)
pub const kCFStringTokenizerUnitParagraph: CFOptionFlags = 2;
/// Tokenization Unit
/// Use one of tokenization unit options with CFStringTokenizerCreate to
/// specify how the string should be tokenized.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitlinebreak?language=objc)
pub const kCFStringTokenizerUnitLineBreak: CFOptionFlags = 3;
/// Tokenization Unit
/// Use one of tokenization unit options with CFStringTokenizerCreate to
/// specify how the string should be tokenized.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitwordboundary?language=objc)
pub const kCFStringTokenizerUnitWordBoundary: CFOptionFlags = 4;
/// Attribute Specifier
/// Use attribute specifier to tell tokenizer to prepare the specified attribute
/// when it tokenizes the given string. The attribute value can be retrieved by
/// calling CFStringTokenizerCopyCurrentTokenAttribute with one of the attribute
/// option.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerattributelatintranscription?language=objc)
pub const kCFStringTokenizerAttributeLatinTranscription: CFOptionFlags = 1 << 16;
/// Attribute Specifier
/// Use attribute specifier to tell tokenizer to prepare the specified attribute
/// when it tokenizes the given string. The attribute value can be retrieved by
/// calling CFStringTokenizerCopyCurrentTokenAttribute with one of the attribute
/// option.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerattributelanguage?language=objc)
pub const kCFStringTokenizerAttributeLanguage: CFOptionFlags = 1 << 17;
/// Token type
/// CFStringTokenizerGoToTokenAtIndex / CFStringTokenizerAdvanceToNextToken returns
/// the type of current token.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfstringtokenizertokentype?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFStringTokenizerTokenType(pub CFOptionFlags);
bitflags::bitflags! {
impl CFStringTokenizerTokenType: CFOptionFlags {
#[doc(alias = "kCFStringTokenizerTokenNone")]
const None = 0;
#[doc(alias = "kCFStringTokenizerTokenNormal")]
const Normal = 1<<0;
/// Compound token which may contain subtokens but with no derived subtokens.
/// Its subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens.
#[doc(alias = "kCFStringTokenizerTokenHasSubTokensMask")]
const HasSubTokensMask = 1<<1;
/// Compound token which may contain derived subtokens.
/// Its subtokens and derived subtokens can be obtained by calling
/// CFStringTokenizerGetCurrentSubTokens.
#[doc(alias = "kCFStringTokenizerTokenHasDerivedSubTokensMask")]
const HasDerivedSubTokensMask = 1<<2;
/// Compound token which may contain derived subtokens.
/// Its subtokens and derived subtokens can be obtained by calling
/// CFStringTokenizerGetCurrentSubTokens.
#[doc(alias = "kCFStringTokenizerTokenHasHasNumbersMask")]
const HasHasNumbersMask = 1<<3;
/// Compound token which may contain derived subtokens.
/// Its subtokens and derived subtokens can be obtained by calling
/// CFStringTokenizerGetCurrentSubTokens.
#[doc(alias = "kCFStringTokenizerTokenHasNonLettersMask")]
const HasNonLettersMask = 1<<4;
/// Compound token which may contain derived subtokens.
/// Its subtokens and derived subtokens can be obtained by calling
/// CFStringTokenizerGetCurrentSubTokens.
#[doc(alias = "kCFStringTokenizerTokenIsCJWordMask")]
const IsCJWordMask = 1<<5;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFStringTokenizerTokenType {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFStringTokenizerTokenType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFStringTokenizer {
/// Get the type identifier.
///
/// Returns: the type identifier of all CFStringTokenizer instances.
#[doc(alias = "CFStringTokenizerGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFStringTokenizerGetTypeID() -> CFTypeID;
}
unsafe { CFStringTokenizerGetTypeID() }
}
}
impl CFStringTokenizer {
/// Creates a tokenizer instance.
///
/// Parameter `alloc`: The CFAllocator which should be used to allocate memory for the
/// tokenizer and its storage for values. This parameter may be NULL in which
/// case the current default CFAllocator is used.
///
/// Parameter `string`: The string to tokenize.
///
/// Parameter `range`: The range of characters within the string to be tokenized. The
/// specified range must not exceed the length of the string.
///
/// Parameter `options`: Use one of the Tokenization Unit options to specify how the
/// string should be tokenized. Optionally specify one or more attribute
/// specifiers to tell the tokenizer to prepare specified attributes when it
/// tokenizes the string.
///
/// Parameter `locale`: The locale to specify language or region specific behavior. Pass
/// NULL if you want tokenizer to identify the locale automatically.
///
/// Returns: A reference to the new CFStringTokenizer.
#[doc(alias = "CFStringTokenizerCreate")]
#[cfg(feature = "CFLocale")]
#[inline]
pub unsafe fn new(
alloc: Option<&CFAllocator>,
string: Option<&CFString>,
range: CFRange,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFStringTokenizer>> {
extern "C-unwind" {
fn CFStringTokenizerCreate(
alloc: Option<&CFAllocator>,
string: Option<&CFString>,
range: CFRange,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFStringTokenizer>>;
}
let ret = unsafe { CFStringTokenizerCreate(alloc, string, range, options, locale) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Set the string to tokenize.
///
/// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
/// CFStringTokenizerCreate.
///
/// Parameter `string`: The string to tokenize.
///
/// Parameter `range`: The range of characters within the string to be tokenized. The
/// specified range must not exceed the length of the string.
#[doc(alias = "CFStringTokenizerSetString")]
#[inline]
pub unsafe fn set_string(self: &CFStringTokenizer, string: Option<&CFString>, range: CFRange) {
extern "C-unwind" {
fn CFStringTokenizerSetString(
tokenizer: &CFStringTokenizer,
string: Option<&CFString>,
range: CFRange,
);
}
unsafe { CFStringTokenizerSetString(self, string, range) }
}
/// Random access to a token. Find a token that includes the character specified
/// by character index, and set it as the current token.
///
/// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
/// CFStringTokenizerCreate.
///
/// Parameter `index`: The index of the Unicode character in the CFString.
///
/// Returns: Type of the token if succeeded in finding a token and setting it as
/// current token. kCFStringTokenizerTokenNone if failed in finding a token.
///
/// The range and attribute of the token can be obtained by calling
/// CFStringTokenizerGetCurrentTokenRange and CFStringTokenizerCopyCurrentTokenAttribute.
/// If the token is a compound (with type kCFStringTokenizerTokenHasSubTokensMask or
/// kCFStringTokenizerTokenHasDerivedSubTokensMask), its subtokens and
/// (or) derived subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens.
#[doc(alias = "CFStringTokenizerGoToTokenAtIndex")]
#[inline]
pub unsafe fn go_to_token_at_index(
self: &CFStringTokenizer,
index: CFIndex,
) -> CFStringTokenizerTokenType {
extern "C-unwind" {
fn CFStringTokenizerGoToTokenAtIndex(
tokenizer: &CFStringTokenizer,
index: CFIndex,
) -> CFStringTokenizerTokenType;
}
unsafe { CFStringTokenizerGoToTokenAtIndex(self, index) }
}
/// Token enumerator.
///
/// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
/// CFStringTokenizerCreate.
///
/// Returns: Type of the token if succeeded in finding a token and setting it as
/// current token. kCFStringTokenizerTokenNone if failed in finding a token.
///
/// If there is no preceding call to CFStringTokenizerGoToTokenAtIndex
/// or CFStringTokenizerAdvanceToNextToken, it finds the first token in the range
/// specified to CFStringTokenizerCreate. If there is a current token after successful
/// call to CFStringTokenizerGoToTokenAtIndex or CFStringTokenizerAdvanceToNextToken,
/// it proceeds to the next token. If succeeded in finding a token, set it as current
/// token and return its token type. Otherwise invalidate current token and return
/// kCFStringTokenizerTokenNone.
/// The range and attribute of the token can be obtained by calling
/// CFStringTokenizerGetCurrentTokenRange and
/// CFStringTokenizerCopyCurrentTokenAttribute. If the token is a compound
/// (with type kCFStringTokenizerTokenHasSubTokensMask or
/// kCFStringTokenizerTokenHasDerivedSubTokensMask), its subtokens and
/// (or) derived subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens.
#[doc(alias = "CFStringTokenizerAdvanceToNextToken")]
#[inline]
pub unsafe fn advance_to_next_token(self: &CFStringTokenizer) -> CFStringTokenizerTokenType {
extern "C-unwind" {
fn CFStringTokenizerAdvanceToNextToken(
tokenizer: &CFStringTokenizer,
) -> CFStringTokenizerTokenType;
}
unsafe { CFStringTokenizerAdvanceToNextToken(self) }
}
/// Returns the range of current token.
///
/// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
/// CFStringTokenizerCreate.
///
/// Returns: Range of current token, or {kCFNotFound,0} if there is no current token.
#[doc(alias = "CFStringTokenizerGetCurrentTokenRange")]
#[inline]
pub unsafe fn current_token_range(self: &CFStringTokenizer) -> CFRange {
extern "C-unwind" {
fn CFStringTokenizerGetCurrentTokenRange(tokenizer: &CFStringTokenizer) -> CFRange;
}
unsafe { CFStringTokenizerGetCurrentTokenRange(self) }
}
/// Copies the specified attribute of current token.
///
/// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
/// CFStringTokenizerCreate.
///
/// Parameter `attribute`: Specify a token attribute you want to obtain. The value is
/// one of kCFStringTokenizerAttributeLatinTranscription or
/// kCFStringTokenizerAttributeLanguage.
///
/// Returns: Token attribute, or NULL if current token does not have the specified
/// attribute or if there is no current token.
#[doc(alias = "CFStringTokenizerCopyCurrentTokenAttribute")]
#[inline]
pub unsafe fn current_token_attribute(
self: &CFStringTokenizer,
attribute: CFOptionFlags,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFStringTokenizerCopyCurrentTokenAttribute(
tokenizer: &CFStringTokenizer,
attribute: CFOptionFlags,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFStringTokenizerCopyCurrentTokenAttribute(self, attribute) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Retrieves the subtokens or derived subtokens contained in the compound token.
///
/// Parameter `tokenizer`: The reference to CFStringTokenizer returned by CFStringTokenizerCreate.
///
/// Parameter `ranges`: An array of CFRange to fill in with the ranges of subtokens. The filled in
/// ranges are relative to the string specified to CFStringTokenizerCreate. This parameter
/// can be NULL.
///
/// Parameter `maxRangeLength`: The maximum number of ranges to return.
///
/// Parameter `derivedSubTokens`: An array of CFMutableArray to which the derived subtokens are to
/// be added. This parameter can be NULL.
///
/// Returns: number of subtokens.
///
/// If token type is kCFStringTokenizerTokenNone, the ranges array and
/// derivedSubTokens array are untouched and the return value is 0.
/// If token type is kCFStringTokenizerTokenNormal, the ranges array has one item
/// filled in with the entire range of the token (if maxRangeLength >= 1) and a string
/// taken from the entire token range is added to the derivedSubTokens array and the
/// return value is 1.
/// If token type is kCFStringTokenizerTokenHasSubTokensMask or
/// kCFStringTokenizerTokenHasDerivedSubTokensMask, the ranges array is filled
/// in with as many items as there are subtokens (up to a limit of maxRangeLength).
/// The derivedSubTokens array will have sub tokens added even when the sub token is a
/// substring of the token. If token type is kCFStringTokenizerTokenHasSubTokensMask,
/// the ordinary non-derived subtokens are added to the derivedSubTokens array.
#[doc(alias = "CFStringTokenizerGetCurrentSubTokens")]
#[cfg(feature = "CFArray")]
#[inline]
pub unsafe fn current_sub_tokens(
self: &CFStringTokenizer,
ranges: *mut CFRange,
max_range_length: CFIndex,
derived_sub_tokens: Option<&CFMutableArray>,
) -> CFIndex {
extern "C-unwind" {
fn CFStringTokenizerGetCurrentSubTokens(
tokenizer: &CFStringTokenizer,
ranges: *mut CFRange,
max_range_length: CFIndex,
derived_sub_tokens: Option<&CFMutableArray>,
) -> CFIndex;
}
unsafe {
CFStringTokenizerGetCurrentSubTokens(self, ranges, max_range_length, derived_sub_tokens)
}
}
}
#[deprecated = "renamed to `CFStringTokenizer::best_string_language`"]
#[inline]
pub unsafe extern "C-unwind" fn CFStringTokenizerCopyBestStringLanguage(
string: &CFString,
range: CFRange,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFStringTokenizerCopyBestStringLanguage(
string: &CFString,
range: CFRange,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFStringTokenizerCopyBestStringLanguage(string, range) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFLocale")]
#[deprecated = "renamed to `CFStringTokenizer::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFStringTokenizerCreate(
alloc: Option<&CFAllocator>,
string: Option<&CFString>,
range: CFRange,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFStringTokenizer>> {
extern "C-unwind" {
fn CFStringTokenizerCreate(
alloc: Option<&CFAllocator>,
string: Option<&CFString>,
range: CFRange,
options: CFOptionFlags,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFStringTokenizer>>;
}
let ret = unsafe { CFStringTokenizerCreate(alloc, string, range, options, locale) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFStringTokenizer::set_string`"]
pub fn CFStringTokenizerSetString(
tokenizer: &CFStringTokenizer,
string: Option<&CFString>,
range: CFRange,
);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFStringTokenizer::go_to_token_at_index`"]
pub fn CFStringTokenizerGoToTokenAtIndex(
tokenizer: &CFStringTokenizer,
index: CFIndex,
) -> CFStringTokenizerTokenType;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFStringTokenizer::advance_to_next_token`"]
pub fn CFStringTokenizerAdvanceToNextToken(
tokenizer: &CFStringTokenizer,
) -> CFStringTokenizerTokenType;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFStringTokenizer::current_token_range`"]
pub fn CFStringTokenizerGetCurrentTokenRange(tokenizer: &CFStringTokenizer) -> CFRange;
}
#[deprecated = "renamed to `CFStringTokenizer::current_token_attribute`"]
#[inline]
pub unsafe extern "C-unwind" fn CFStringTokenizerCopyCurrentTokenAttribute(
tokenizer: &CFStringTokenizer,
attribute: CFOptionFlags,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFStringTokenizerCopyCurrentTokenAttribute(
tokenizer: &CFStringTokenizer,
attribute: CFOptionFlags,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFStringTokenizerCopyCurrentTokenAttribute(tokenizer, attribute) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFStringTokenizer::current_sub_tokens`"]
pub fn CFStringTokenizerGetCurrentSubTokens(
tokenizer: &CFStringTokenizer,
ranges: *mut CFRange,
max_range_length: CFIndex,
derived_sub_tokens: Option<&CFMutableArray>,
) -> CFIndex;
}

View File

@@ -0,0 +1,533 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
#[cfg(feature = "CFDate")]
unsafe impl ConcreteType for CFTimeZone {
#[doc(alias = "CFTimeZoneGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFTimeZoneGetTypeID() -> CFTypeID;
}
unsafe { CFTimeZoneGetTypeID() }
}
}
#[cfg(feature = "CFDate")]
impl CFTimeZone {
#[doc(alias = "CFTimeZoneCopySystem")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn system() -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCopySystem() -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCopySystem() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneResetSystem")]
#[inline]
pub unsafe fn reset_system() {
extern "C-unwind" {
fn CFTimeZoneResetSystem();
}
unsafe { CFTimeZoneResetSystem() }
}
#[doc(alias = "CFTimeZoneCopyDefault")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn default() -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCopyDefault() -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCopyDefault() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneSetDefault")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn set_default(self: &CFTimeZone) {
extern "C-unwind" {
fn CFTimeZoneSetDefault(tz: &CFTimeZone);
}
unsafe { CFTimeZoneSetDefault(self) }
}
#[doc(alias = "CFTimeZoneCopyKnownNames")]
#[cfg(feature = "CFArray")]
#[inline]
pub fn known_names() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFTimeZoneCopyKnownNames() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFTimeZoneCopyKnownNames() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneCopyAbbreviationDictionary")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub fn abbreviation_dictionary() -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFTimeZoneCopyAbbreviationDictionary() -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFTimeZoneCopyAbbreviationDictionary() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneSetAbbreviationDictionary")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe fn set_abbreviation_dictionary(dict: Option<&CFDictionary>) {
extern "C-unwind" {
fn CFTimeZoneSetAbbreviationDictionary(dict: Option<&CFDictionary>);
}
unsafe { CFTimeZoneSetAbbreviationDictionary(dict) }
}
#[doc(alias = "CFTimeZoneCreate")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
data: Option<&CFData>,
) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCreate(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
data: Option<&CFData>,
) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCreate(allocator, name, data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneCreateWithTimeIntervalFromGMT")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn with_time_interval_from_gmt(
allocator: Option<&CFAllocator>,
ti: CFTimeInterval,
) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCreateWithTimeIntervalFromGMT(
allocator: Option<&CFAllocator>,
ti: CFTimeInterval,
) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCreateWithTimeIntervalFromGMT(allocator, ti) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneCreateWithName")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn with_name(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
try_abbrev: bool,
) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCreateWithName(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
try_abbrev: Boolean,
) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCreateWithName(allocator, name, try_abbrev as _) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneGetName")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn name(self: &CFTimeZone) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFTimeZoneGetName(tz: &CFTimeZone) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFTimeZoneGetName(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFTimeZoneGetData")]
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[inline]
pub fn data(self: &CFTimeZone) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFTimeZoneGetData(tz: &CFTimeZone) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFTimeZoneGetData(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFTimeZoneGetSecondsFromGMT")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn seconds_from_gmt(self: &CFTimeZone, at: CFAbsoluteTime) -> CFTimeInterval {
extern "C-unwind" {
fn CFTimeZoneGetSecondsFromGMT(tz: &CFTimeZone, at: CFAbsoluteTime) -> CFTimeInterval;
}
unsafe { CFTimeZoneGetSecondsFromGMT(self, at) }
}
#[doc(alias = "CFTimeZoneCopyAbbreviation")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn abbreviation(self: &CFTimeZone, at: CFAbsoluteTime) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFTimeZoneCopyAbbreviation(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFTimeZoneCopyAbbreviation(self, at) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFTimeZoneIsDaylightSavingTime")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn is_daylight_saving_time(self: &CFTimeZone, at: CFAbsoluteTime) -> bool {
extern "C-unwind" {
fn CFTimeZoneIsDaylightSavingTime(tz: &CFTimeZone, at: CFAbsoluteTime) -> Boolean;
}
let ret = unsafe { CFTimeZoneIsDaylightSavingTime(self, at) };
ret != 0
}
#[doc(alias = "CFTimeZoneGetDaylightSavingTimeOffset")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn daylight_saving_time_offset(self: &CFTimeZone, at: CFAbsoluteTime) -> CFTimeInterval {
extern "C-unwind" {
fn CFTimeZoneGetDaylightSavingTimeOffset(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFTimeInterval;
}
unsafe { CFTimeZoneGetDaylightSavingTimeOffset(self, at) }
}
#[doc(alias = "CFTimeZoneGetNextDaylightSavingTimeTransition")]
#[cfg(feature = "CFDate")]
#[inline]
pub fn next_daylight_saving_time_transition(
self: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFAbsoluteTime {
extern "C-unwind" {
fn CFTimeZoneGetNextDaylightSavingTimeTransition(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFAbsoluteTime;
}
unsafe { CFTimeZoneGetNextDaylightSavingTimeTransition(self, at) }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftimezonenamestyle?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFTimeZoneNameStyle(pub CFIndex);
impl CFTimeZoneNameStyle {
#[doc(alias = "kCFTimeZoneNameStyleStandard")]
pub const Standard: Self = Self(0);
#[doc(alias = "kCFTimeZoneNameStyleShortStandard")]
pub const ShortStandard: Self = Self(1);
#[doc(alias = "kCFTimeZoneNameStyleDaylightSaving")]
pub const DaylightSaving: Self = Self(2);
#[doc(alias = "kCFTimeZoneNameStyleShortDaylightSaving")]
pub const ShortDaylightSaving: Self = Self(3);
#[doc(alias = "kCFTimeZoneNameStyleGeneric")]
pub const Generic: Self = Self(4);
#[doc(alias = "kCFTimeZoneNameStyleShortGeneric")]
pub const ShortGeneric: Self = Self(5);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFTimeZoneNameStyle {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFTimeZoneNameStyle {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[cfg(feature = "CFDate")]
impl CFTimeZone {
#[doc(alias = "CFTimeZoneCopyLocalizedName")]
#[cfg(all(feature = "CFDate", feature = "CFLocale"))]
#[inline]
pub fn localized_name(
self: &CFTimeZone,
style: CFTimeZoneNameStyle,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFTimeZoneCopyLocalizedName(
tz: &CFTimeZone,
style: CFTimeZoneNameStyle,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFTimeZoneCopyLocalizedName(self, style, locale) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcftimezonesystemtimezonedidchangenotification?language=objc)
#[cfg(feature = "CFNotificationCenter")]
pub static kCFTimeZoneSystemTimeZoneDidChangeNotification: Option<&'static CFNotificationName>;
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::system`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCopySystem() -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCopySystem() -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCopySystem() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTimeZone::reset_system`"]
pub fn CFTimeZoneResetSystem();
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::default`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCopyDefault() -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCopyDefault() -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCopyDefault() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::set_default`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneSetDefault(tz: &CFTimeZone) {
extern "C-unwind" {
fn CFTimeZoneSetDefault(tz: &CFTimeZone);
}
unsafe { CFTimeZoneSetDefault(tz) }
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFTimeZone::known_names`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCopyKnownNames() -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn CFTimeZoneCopyKnownNames() -> Option<NonNull<CFArray>>;
}
let ret = unsafe { CFTimeZoneCopyKnownNames() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFTimeZone::abbreviation_dictionary`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCopyAbbreviationDictionary() -> Option<CFRetained<CFDictionary>>
{
extern "C-unwind" {
fn CFTimeZoneCopyAbbreviationDictionary() -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFTimeZoneCopyAbbreviationDictionary() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFTimeZone::set_abbreviation_dictionary`"]
pub fn CFTimeZoneSetAbbreviationDictionary(dict: Option<&CFDictionary>);
}
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFTimeZone::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFTimeZoneCreate(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
data: Option<&CFData>,
) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCreate(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
data: Option<&CFData>,
) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCreate(allocator, name, data) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::with_time_interval_from_gmt`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCreateWithTimeIntervalFromGMT(
allocator: Option<&CFAllocator>,
ti: CFTimeInterval,
) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCreateWithTimeIntervalFromGMT(
allocator: Option<&CFAllocator>,
ti: CFTimeInterval,
) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCreateWithTimeIntervalFromGMT(allocator, ti) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::with_name`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCreateWithName(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
try_abbrev: bool,
) -> Option<CFRetained<CFTimeZone>> {
extern "C-unwind" {
fn CFTimeZoneCreateWithName(
allocator: Option<&CFAllocator>,
name: Option<&CFString>,
try_abbrev: Boolean,
) -> Option<NonNull<CFTimeZone>>;
}
let ret = unsafe { CFTimeZoneCreateWithName(allocator, name, try_abbrev as _) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::name`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneGetName(tz: &CFTimeZone) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFTimeZoneGetName(tz: &CFTimeZone) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFTimeZoneGetName(tz) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[cfg(all(feature = "CFData", feature = "CFDate"))]
#[deprecated = "renamed to `CFTimeZone::data`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneGetData(tz: &CFTimeZone) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFTimeZoneGetData(tz: &CFTimeZone) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFTimeZoneGetData(tz) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::seconds_from_gmt`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneGetSecondsFromGMT(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFTimeInterval {
extern "C-unwind" {
fn CFTimeZoneGetSecondsFromGMT(tz: &CFTimeZone, at: CFAbsoluteTime) -> CFTimeInterval;
}
unsafe { CFTimeZoneGetSecondsFromGMT(tz, at) }
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::abbreviation`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCopyAbbreviation(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFTimeZoneCopyAbbreviation(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFTimeZoneCopyAbbreviation(tz, at) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::is_daylight_saving_time`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneIsDaylightSavingTime(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> bool {
extern "C-unwind" {
fn CFTimeZoneIsDaylightSavingTime(tz: &CFTimeZone, at: CFAbsoluteTime) -> Boolean;
}
let ret = unsafe { CFTimeZoneIsDaylightSavingTime(tz, at) };
ret != 0
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::daylight_saving_time_offset`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneGetDaylightSavingTimeOffset(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFTimeInterval {
extern "C-unwind" {
fn CFTimeZoneGetDaylightSavingTimeOffset(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFTimeInterval;
}
unsafe { CFTimeZoneGetDaylightSavingTimeOffset(tz, at) }
}
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFTimeZone::next_daylight_saving_time_transition`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneGetNextDaylightSavingTimeTransition(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFAbsoluteTime {
extern "C-unwind" {
fn CFTimeZoneGetNextDaylightSavingTimeTransition(
tz: &CFTimeZone,
at: CFAbsoluteTime,
) -> CFAbsoluteTime;
}
unsafe { CFTimeZoneGetNextDaylightSavingTimeTransition(tz, at) }
}
#[cfg(all(feature = "CFDate", feature = "CFLocale"))]
#[deprecated = "renamed to `CFTimeZone::localized_name`"]
#[inline]
pub extern "C-unwind" fn CFTimeZoneCopyLocalizedName(
tz: &CFTimeZone,
style: CFTimeZoneNameStyle,
locale: Option<&CFLocale>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFTimeZoneCopyLocalizedName(
tz: &CFTimeZone,
style: CFTimeZoneNameStyle,
locale: Option<&CFLocale>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFTimeZoneCopyLocalizedName(tz, style, locale) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,602 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// Type of the callback function used to add a retain to the user-specified
/// info parameter. This callback may returns the value to use whenever the
/// info parameter is retained, which is usually the value parameter passed
/// to this callback, but may be a different value if a different value
/// should be used.
///
/// Parameter `info`: A user-supplied info parameter provided in a CFTreeContext.
///
/// Returns: The retained info parameter.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreeretaincallback?language=objc)
pub type CFTreeRetainCallBack = Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>;
/// Type of the callback function used to remove a retain previously
/// added to the user-specified info parameter.
///
/// Parameter `info`: A user-supplied info parameter provided in a CFTreeContext.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreereleasecallback?language=objc)
pub type CFTreeReleaseCallBack = Option<unsafe extern "C-unwind" fn(*const c_void)>;
/// Type of the callback function used to provide a description of the
/// user-specified info parameter.
///
/// Parameter `info`: A user-supplied info parameter provided in a CFTreeContext.
///
/// Returns: A description of the info parameter.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreecopydescriptioncallback?language=objc)
pub type CFTreeCopyDescriptionCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
/// Structure containing user-specified data and callbacks for a CFTree.
/// Field: version The version number of the structure type being passed
/// in as a parameter to the CFTree creation function.
/// This structure is version 0.
/// Field: info A C pointer to a user-specified block of data.
/// Field: retain The callback used to add a retain for the info field.
/// If this parameter is not a pointer to a function of the correct
/// prototype, the behavior is undefined. The value may be NULL.
/// Field: release The calllback used to remove a retain previously added
/// for the info field. If this parameter is not a pointer to a
/// function of the correct prototype, the behavior is undefined.
/// The value may be NULL.
/// Field: copyDescription The callback used to provide a description of
/// the info field.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreecontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFTreeContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: CFTreeRetainCallBack,
pub release: CFTreeReleaseCallBack,
pub copyDescription: CFTreeCopyDescriptionCallBack,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFTreeContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<CFTreeRetainCallBack>::ENCODING,
<CFTreeReleaseCallBack>::ENCODING,
<CFTreeCopyDescriptionCallBack>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFTreeContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Type of the callback function used by the apply functions of
/// CFTree.
///
/// Parameter `value`: The current value from the CFTree
///
/// Parameter `context`: The user-defined context parameter give to the apply
/// function.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreeapplierfunction?language=objc)
pub type CFTreeApplierFunction = Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
/// This is the type of a reference to CFTrees.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftree?language=objc)
#[repr(C)]
pub struct CFTree {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFTree {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFTree"> for CFTree {}
);
unsafe impl ConcreteType for CFTree {
/// Returns the type identifier of all CFTree instances.
#[doc(alias = "CFTreeGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFTreeGetTypeID() -> CFTypeID;
}
unsafe { CFTreeGetTypeID() }
}
}
impl CFTree {
/// Creates a new mutable tree.
///
/// Parameter `allocator`: The CFAllocator which should be used to allocate
/// memory for the tree and storage for its children. This
/// parameter may be NULL in which case the current default
/// CFAllocator is used. If this reference is not a valid
/// CFAllocator, the behavior is undefined.
///
/// Parameter `context`: A C pointer to a CFTreeContext structure to be copied
/// and used as the context of the new tree. The info parameter
/// will be retained by the tree if a retain function is provided.
/// If this value is not a valid C pointer to a CFTreeContext
/// structure-sized block of storage, the result is undefined.
/// If the version number of the storage is not a valid CFTreeContext
/// version number, the result is undefined.
///
/// Returns: A reference to the new CFTree.
#[doc(alias = "CFTreeCreate")]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
context: *const CFTreeContext,
) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeCreate(
allocator: Option<&CFAllocator>,
context: *const CFTreeContext,
) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeCreate(allocator, context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
/// Returns the parent of the specified tree.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Returns: The parent of the tree.
#[doc(alias = "CFTreeGetParent")]
#[inline]
pub unsafe fn parent(self: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetParent(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetParent(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the sibling after the specified tree in the parent tree's list.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Returns: The next sibling of the tree.
#[doc(alias = "CFTreeGetNextSibling")]
#[inline]
pub unsafe fn next_sibling(self: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetNextSibling(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetNextSibling(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the first child of the tree.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Returns: The first child of the tree.
#[doc(alias = "CFTreeGetFirstChild")]
#[inline]
pub unsafe fn first_child(self: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetFirstChild(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetFirstChild(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Returns the context of the specified tree.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Parameter `context`: A C pointer to a CFTreeContext structure to be filled in with
/// the context of the specified tree. If this value is not a valid C
/// pointer to a CFTreeContext structure-sized block of storage, the
/// result is undefined. If the version number of the storage is not
/// a valid CFTreeContext version number, the result is undefined.
#[doc(alias = "CFTreeGetContext")]
#[inline]
pub unsafe fn context(self: &CFTree, context: *mut CFTreeContext) {
extern "C-unwind" {
fn CFTreeGetContext(tree: &CFTree, context: *mut CFTreeContext);
}
unsafe { CFTreeGetContext(self, context) }
}
/// Returns the number of children of the specified tree.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Returns: The number of children.
#[doc(alias = "CFTreeGetChildCount")]
#[inline]
pub unsafe fn child_count(self: &CFTree) -> CFIndex {
extern "C-unwind" {
fn CFTreeGetChildCount(tree: &CFTree) -> CFIndex;
}
unsafe { CFTreeGetChildCount(self) }
}
/// Returns the nth child of the specified tree.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Parameter `idx`: The index of the child tree to be returned. If this parameter
/// is less than zero or greater than the number of children of the
/// tree, the result is undefined.
///
/// Returns: A reference to the specified child tree.
#[doc(alias = "CFTreeGetChildAtIndex")]
#[inline]
pub unsafe fn child_at_index(self: &CFTree, idx: CFIndex) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetChildAtIndex(tree: &CFTree, idx: CFIndex) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetChildAtIndex(self, idx) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Fills the buffer with children from the tree.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Parameter `children`: A C array of pointer-sized values to be filled with
/// children from the tree. If this parameter is not a valid pointer to a
/// C array of at least CFTreeGetChildCount() pointers, the behavior is undefined.
#[doc(alias = "CFTreeGetChildren")]
#[inline]
pub unsafe fn children(self: &CFTree, children: *mut *mut CFTree) {
extern "C-unwind" {
fn CFTreeGetChildren(tree: &CFTree, children: *mut *mut CFTree);
}
unsafe { CFTreeGetChildren(self, children) }
}
/// Calls a function once for each child of the tree. Note that the applier
/// only operates one level deep, and does not operate on descendents further
/// removed than the immediate children of the tree.
///
/// Parameter `tree`: The tree to be operated upon. If this parameter is not a
/// valid CFTree, the behavior is undefined.
///
/// Parameter `applier`: The callback function to call once for each child of
/// the given tree. If this parameter is not a pointer to a
/// function of the correct prototype, the behavior is undefined.
/// If there are values in the tree which the applier function does
/// not expect or cannot properly apply to, the behavior is undefined.
///
/// Parameter `context`: A pointer-sized user-defined value, which is passed
/// as the second parameter to the applier function, but is
/// otherwise unused by this function. If the context is not
/// what is expected by the applier function, the behavior is
/// undefined.
#[doc(alias = "CFTreeApplyFunctionToChildren")]
#[inline]
pub unsafe fn apply_function_to_children(
self: &CFTree,
applier: CFTreeApplierFunction,
context: *mut c_void,
) {
extern "C-unwind" {
fn CFTreeApplyFunctionToChildren(
tree: &CFTree,
applier: CFTreeApplierFunction,
context: *mut c_void,
);
}
unsafe { CFTreeApplyFunctionToChildren(self, applier, context) }
}
/// Returns the root tree of which the specified tree is a descendent.
///
/// Parameter `tree`: The tree to be queried. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Returns: A reference to the root of the tree.
#[doc(alias = "CFTreeFindRoot")]
#[inline]
pub unsafe fn find_root(self: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeFindRoot(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeFindRoot(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
/// Replaces the context of a tree. The tree releases its retain on the
/// info of the previous context, and retains the info of the new context.
///
/// Parameter `tree`: The tree to be operated on. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Parameter `context`: A C pointer to a CFTreeContext structure to be copied
/// and used as the context of the new tree. The info parameter
/// will be retained by the tree if a retain function is provided.
/// If this value is not a valid C pointer to a CFTreeContext
/// structure-sized block of storage, the result is undefined.
/// If the version number of the storage is not a valid CFTreeContext
/// version number, the result is undefined.
#[doc(alias = "CFTreeSetContext")]
#[inline]
pub unsafe fn set_context(self: &CFTree, context: *const CFTreeContext) {
extern "C-unwind" {
fn CFTreeSetContext(tree: &CFTree, context: *const CFTreeContext);
}
unsafe { CFTreeSetContext(self, context) }
}
/// Adds the newChild to the specified tree as the first in its list of children.
///
/// Parameter `tree`: The tree to be operated on. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Parameter `newChild`: The child to be added.
/// If this parameter is not a valid CFTree, the behavior is undefined.
/// If this parameter is a tree which is already a child of any tree,
/// the behavior is undefined.
#[doc(alias = "CFTreePrependChild")]
#[inline]
pub unsafe fn prepend_child(self: &CFTree, new_child: Option<&CFTree>) {
extern "C-unwind" {
fn CFTreePrependChild(tree: &CFTree, new_child: Option<&CFTree>);
}
unsafe { CFTreePrependChild(self, new_child) }
}
/// Adds the newChild to the specified tree as the last in its list of children.
///
/// Parameter `tree`: The tree to be operated on. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Parameter `newChild`: The child to be added.
/// If this parameter is not a valid CFTree, the behavior is undefined.
/// If this parameter is a tree which is already a child of any tree,
/// the behavior is undefined.
#[doc(alias = "CFTreeAppendChild")]
#[inline]
pub unsafe fn append_child(self: &CFTree, new_child: Option<&CFTree>) {
extern "C-unwind" {
fn CFTreeAppendChild(tree: &CFTree, new_child: Option<&CFTree>);
}
unsafe { CFTreeAppendChild(self, new_child) }
}
/// Inserts newSibling into the the parent tree's linked list of children after
/// tree. The newSibling will have the same parent as tree.
///
/// Parameter `tree`: The tree to insert newSibling after. If this parameter is not a valid
/// CFTree, the behavior is undefined. If the tree does not have a
/// parent, the behavior is undefined.
///
/// Parameter `newSibling`: The sibling to be added.
/// If this parameter is not a valid CFTree, the behavior is undefined.
/// If this parameter is a tree which is already a child of any tree,
/// the behavior is undefined.
#[doc(alias = "CFTreeInsertSibling")]
#[inline]
pub unsafe fn insert_sibling(self: &CFTree, new_sibling: Option<&CFTree>) {
extern "C-unwind" {
fn CFTreeInsertSibling(tree: &CFTree, new_sibling: Option<&CFTree>);
}
unsafe { CFTreeInsertSibling(self, new_sibling) }
}
/// Removes the tree from its parent.
///
/// Parameter `tree`: The tree to be removed. If this parameter is not a valid
/// CFTree, the behavior is undefined.
#[doc(alias = "CFTreeRemove")]
#[inline]
pub unsafe fn remove(self: &CFTree) {
extern "C-unwind" {
fn CFTreeRemove(tree: &CFTree);
}
unsafe { CFTreeRemove(self) }
}
/// Removes all the children of the tree.
///
/// Parameter `tree`: The tree to remove all children from. If this parameter is not a valid
/// CFTree, the behavior is undefined.
#[doc(alias = "CFTreeRemoveAllChildren")]
#[inline]
pub unsafe fn remove_all_children(self: &CFTree) {
extern "C-unwind" {
fn CFTreeRemoveAllChildren(tree: &CFTree);
}
unsafe { CFTreeRemoveAllChildren(self) }
}
/// Sorts the children of the specified tree using the specified comparator function.
///
/// Parameter `tree`: The tree to be operated on. If this parameter is not a valid
/// CFTree, the behavior is undefined.
///
/// Parameter `comparator`: The function with the comparator function type
/// signature which is used in the sort operation to compare
/// children of the tree with the given value. If this parameter
/// is not a pointer to a function of the correct prototype, the
/// the behavior is undefined. The children of the tree are sorted
/// from least to greatest according to this function.
///
/// Parameter `context`: A pointer-sized user-defined value, which is passed
/// as the third parameter to the comparator function, but is
/// otherwise unused by this function. If the context is not
/// what is expected by the comparator function, the behavior is
/// undefined.
#[doc(alias = "CFTreeSortChildren")]
#[inline]
pub unsafe fn sort_children(
self: &CFTree,
comparator: CFComparatorFunction,
context: *mut c_void,
) {
extern "C-unwind" {
fn CFTreeSortChildren(
tree: &CFTree,
comparator: CFComparatorFunction,
context: *mut c_void,
);
}
unsafe { CFTreeSortChildren(self, comparator, context) }
}
}
#[deprecated = "renamed to `CFTree::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFTreeCreate(
allocator: Option<&CFAllocator>,
context: *const CFTreeContext,
) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeCreate(
allocator: Option<&CFAllocator>,
context: *const CFTreeContext,
) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeCreate(allocator, context) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFTree::parent`"]
#[inline]
pub unsafe extern "C-unwind" fn CFTreeGetParent(tree: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetParent(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetParent(tree) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFTree::next_sibling`"]
#[inline]
pub unsafe extern "C-unwind" fn CFTreeGetNextSibling(tree: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetNextSibling(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetNextSibling(tree) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFTree::first_child`"]
#[inline]
pub unsafe extern "C-unwind" fn CFTreeGetFirstChild(tree: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetFirstChild(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetFirstChild(tree) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::context`"]
pub fn CFTreeGetContext(tree: &CFTree, context: *mut CFTreeContext);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::child_count`"]
pub fn CFTreeGetChildCount(tree: &CFTree) -> CFIndex;
}
#[deprecated = "renamed to `CFTree::child_at_index`"]
#[inline]
pub unsafe extern "C-unwind" fn CFTreeGetChildAtIndex(
tree: &CFTree,
idx: CFIndex,
) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeGetChildAtIndex(tree: &CFTree, idx: CFIndex) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeGetChildAtIndex(tree, idx) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::children`"]
pub fn CFTreeGetChildren(tree: &CFTree, children: *mut *mut CFTree);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::apply_function_to_children`"]
pub fn CFTreeApplyFunctionToChildren(
tree: &CFTree,
applier: CFTreeApplierFunction,
context: *mut c_void,
);
}
#[deprecated = "renamed to `CFTree::find_root`"]
#[inline]
pub unsafe extern "C-unwind" fn CFTreeFindRoot(tree: &CFTree) -> Option<CFRetained<CFTree>> {
extern "C-unwind" {
fn CFTreeFindRoot(tree: &CFTree) -> Option<NonNull<CFTree>>;
}
let ret = unsafe { CFTreeFindRoot(tree) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::set_context`"]
pub fn CFTreeSetContext(tree: &CFTree, context: *const CFTreeContext);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::prepend_child`"]
pub fn CFTreePrependChild(tree: &CFTree, new_child: Option<&CFTree>);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::append_child`"]
pub fn CFTreeAppendChild(tree: &CFTree, new_child: Option<&CFTree>);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::insert_sibling`"]
pub fn CFTreeInsertSibling(tree: &CFTree, new_sibling: Option<&CFTree>);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::remove`"]
pub fn CFTreeRemove(tree: &CFTree);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::remove_all_children`"]
pub fn CFTreeRemoveAllChildren(tree: &CFTree);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFTree::sort_children`"]
pub fn CFTreeSortChildren(
tree: &CFTree,
comparator: CFComparatorFunction,
context: *mut c_void,
);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,293 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
#[cfg(feature = "CFURL")]
impl CFURL {
#[doc(alias = "CFURLCreateDataAndPropertiesFromResource")]
#[cfg(all(
feature = "CFArray",
feature = "CFData",
feature = "CFDictionary",
feature = "CFURL"
))]
#[deprecated = "For resource data, use the CFReadStream API. For file resource properties, use CFURLCopyResourcePropertiesForKeys."]
#[inline]
pub unsafe fn new_data_and_properties_from_resource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
resource_data: *mut *const CFData,
properties: *mut *const CFDictionary,
desired_properties: Option<&CFArray>,
error_code: *mut i32,
) -> bool {
extern "C-unwind" {
fn CFURLCreateDataAndPropertiesFromResource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
resource_data: *mut *const CFData,
properties: *mut *const CFDictionary,
desired_properties: Option<&CFArray>,
error_code: *mut i32,
) -> Boolean;
}
let ret = unsafe {
CFURLCreateDataAndPropertiesFromResource(
alloc,
url,
resource_data,
properties,
desired_properties,
error_code,
)
};
ret != 0
}
#[doc(alias = "CFURLWriteDataAndPropertiesToResource")]
#[cfg(all(feature = "CFData", feature = "CFDictionary", feature = "CFURL"))]
#[deprecated = "For resource data, use the CFWriteStream API. For file resource properties, use CFURLSetResourcePropertiesForKeys."]
#[inline]
pub unsafe fn write_data_and_properties_to_resource(
self: &CFURL,
data_to_write: Option<&CFData>,
properties_to_write: Option<&CFDictionary>,
error_code: *mut i32,
) -> bool {
extern "C-unwind" {
fn CFURLWriteDataAndPropertiesToResource(
url: &CFURL,
data_to_write: Option<&CFData>,
properties_to_write: Option<&CFDictionary>,
error_code: *mut i32,
) -> Boolean;
}
let ret = unsafe {
CFURLWriteDataAndPropertiesToResource(
self,
data_to_write,
properties_to_write,
error_code,
)
};
ret != 0
}
#[doc(alias = "CFURLDestroyResource")]
#[cfg(feature = "CFURL")]
#[deprecated = "Use CFURLGetFileSystemRepresentation and removefile(3) instead."]
#[inline]
pub unsafe fn destroy_resource(self: &CFURL, error_code: *mut i32) -> bool {
extern "C-unwind" {
fn CFURLDestroyResource(url: &CFURL, error_code: *mut i32) -> Boolean;
}
let ret = unsafe { CFURLDestroyResource(self, error_code) };
ret != 0
}
#[doc(alias = "CFURLCreatePropertyFromResource")]
#[cfg(feature = "CFURL")]
#[deprecated = "For file resource properties, use CFURLCopyResourcePropertyForKey."]
#[inline]
pub unsafe fn new_property_from_resource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
property: Option<&CFString>,
error_code: *mut i32,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFURLCreatePropertyFromResource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
property: Option<&CFString>,
error_code: *mut i32,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFURLCreatePropertyFromResource(alloc, url, property, error_code) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfurlerror?language=objc)
// NS_ENUM
#[deprecated = "Use CFError codes instead"]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFURLError(pub CFIndex);
impl CFURLError {
#[doc(alias = "kCFURLUnknownError")]
#[deprecated = "Use CFError codes instead"]
pub const UnknownError: Self = Self(-10);
#[doc(alias = "kCFURLUnknownSchemeError")]
#[deprecated = "Use CFError codes instead"]
pub const UnknownSchemeError: Self = Self(-11);
#[doc(alias = "kCFURLResourceNotFoundError")]
#[deprecated = "Use CFError codes instead"]
pub const ResourceNotFoundError: Self = Self(-12);
#[doc(alias = "kCFURLResourceAccessViolationError")]
#[deprecated = "Use CFError codes instead"]
pub const ResourceAccessViolationError: Self = Self(-13);
#[doc(alias = "kCFURLRemoteHostUnavailableError")]
#[deprecated = "Use CFError codes instead"]
pub const RemoteHostUnavailableError: Self = Self(-14);
#[doc(alias = "kCFURLImproperArgumentsError")]
#[deprecated = "Use CFError codes instead"]
pub const ImproperArgumentsError: Self = Self(-15);
#[doc(alias = "kCFURLUnknownPropertyKeyError")]
#[deprecated = "Use CFError codes instead"]
pub const UnknownPropertyKeyError: Self = Self(-16);
#[doc(alias = "kCFURLPropertyKeyUnavailableError")]
#[deprecated = "Use CFError codes instead"]
pub const PropertyKeyUnavailableError: Self = Self(-17);
#[doc(alias = "kCFURLTimeoutError")]
#[deprecated = "Use CFError codes instead"]
pub const TimeoutError: Self = Self(-18);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFURLError {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFURLError {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlfileexists?language=objc)
pub static kCFURLFileExists: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlfiledirectorycontents?language=objc)
pub static kCFURLFileDirectoryContents: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlfilelength?language=objc)
pub static kCFURLFileLength: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlfilelastmodificationtime?language=objc)
pub static kCFURLFileLastModificationTime: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlfileposixmode?language=objc)
pub static kCFURLFilePOSIXMode: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlfileownerid?language=objc)
pub static kCFURLFileOwnerID: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlhttpstatuscode?language=objc)
pub static kCFURLHTTPStatusCode: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfurlhttpstatusline?language=objc)
pub static kCFURLHTTPStatusLine: Option<&'static CFString>;
}
#[cfg(all(
feature = "CFArray",
feature = "CFData",
feature = "CFDictionary",
feature = "CFURL"
))]
#[deprecated = "renamed to `CFURL::new_data_and_properties_from_resource`"]
#[inline]
pub unsafe extern "C-unwind" fn CFURLCreateDataAndPropertiesFromResource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
resource_data: *mut *const CFData,
properties: *mut *const CFDictionary,
desired_properties: Option<&CFArray>,
error_code: *mut i32,
) -> bool {
extern "C-unwind" {
fn CFURLCreateDataAndPropertiesFromResource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
resource_data: *mut *const CFData,
properties: *mut *const CFDictionary,
desired_properties: Option<&CFArray>,
error_code: *mut i32,
) -> Boolean;
}
let ret = unsafe {
CFURLCreateDataAndPropertiesFromResource(
alloc,
url,
resource_data,
properties,
desired_properties,
error_code,
)
};
ret != 0
}
#[cfg(all(feature = "CFData", feature = "CFDictionary", feature = "CFURL"))]
#[deprecated = "renamed to `CFURL::write_data_and_properties_to_resource`"]
#[inline]
pub unsafe extern "C-unwind" fn CFURLWriteDataAndPropertiesToResource(
url: &CFURL,
data_to_write: Option<&CFData>,
properties_to_write: Option<&CFDictionary>,
error_code: *mut i32,
) -> bool {
extern "C-unwind" {
fn CFURLWriteDataAndPropertiesToResource(
url: &CFURL,
data_to_write: Option<&CFData>,
properties_to_write: Option<&CFDictionary>,
error_code: *mut i32,
) -> Boolean;
}
let ret = unsafe {
CFURLWriteDataAndPropertiesToResource(url, data_to_write, properties_to_write, error_code)
};
ret != 0
}
#[cfg(feature = "CFURL")]
#[deprecated = "renamed to `CFURL::destroy_resource`"]
#[inline]
pub unsafe extern "C-unwind" fn CFURLDestroyResource(url: &CFURL, error_code: *mut i32) -> bool {
extern "C-unwind" {
fn CFURLDestroyResource(url: &CFURL, error_code: *mut i32) -> Boolean;
}
let ret = unsafe { CFURLDestroyResource(url, error_code) };
ret != 0
}
#[cfg(feature = "CFURL")]
#[deprecated = "renamed to `CFURL::new_property_from_resource`"]
#[inline]
pub unsafe extern "C-unwind" fn CFURLCreatePropertyFromResource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
property: Option<&CFString>,
error_code: *mut i32,
) -> Option<CFRetained<CFType>> {
extern "C-unwind" {
fn CFURLCreatePropertyFromResource(
alloc: Option<&CFAllocator>,
url: Option<&CFURL>,
property: Option<&CFString>,
error_code: *mut i32,
) -> Option<NonNull<CFType>>;
}
let ret = unsafe { CFURLCreatePropertyFromResource(alloc, url, property, error_code) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,265 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfurlenumerator?language=objc)
#[repr(C)]
pub struct CFURLEnumerator {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFURLEnumerator {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFURLEnumerator"> for CFURLEnumerator {}
);
unsafe impl ConcreteType for CFURLEnumerator {
#[doc(alias = "CFURLEnumeratorGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFURLEnumeratorGetTypeID() -> CFTypeID;
}
unsafe { CFURLEnumeratorGetTypeID() }
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfurlenumeratoroptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFURLEnumeratorOptions(pub CFOptionFlags);
bitflags::bitflags! {
impl CFURLEnumeratorOptions: CFOptionFlags {
#[doc(alias = "kCFURLEnumeratorDefaultBehavior")]
const DefaultBehavior = 0;
#[doc(alias = "kCFURLEnumeratorDescendRecursively")]
const DescendRecursively = 1<<0;
#[doc(alias = "kCFURLEnumeratorSkipInvisibles")]
const SkipInvisibles = 1<<1;
#[doc(alias = "kCFURLEnumeratorGenerateFileReferenceURLs")]
const GenerateFileReferenceURLs = 1<<2;
#[doc(alias = "kCFURLEnumeratorSkipPackageContents")]
const SkipPackageContents = 1<<3;
#[doc(alias = "kCFURLEnumeratorIncludeDirectoriesPreOrder")]
const IncludeDirectoriesPreOrder = 1<<4;
#[doc(alias = "kCFURLEnumeratorIncludeDirectoriesPostOrder")]
const IncludeDirectoriesPostOrder = 1<<5;
#[doc(alias = "kCFURLEnumeratorGenerateRelativePathURLs")]
const GenerateRelativePathURLs = 1<<6;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFURLEnumeratorOptions {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFURLEnumeratorOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFURLEnumerator {
#[doc(alias = "CFURLEnumeratorCreateForDirectoryURL")]
#[cfg(all(feature = "CFArray", feature = "CFURL"))]
#[inline]
pub unsafe fn new_for_directory_url(
alloc: Option<&CFAllocator>,
directory_url: Option<&CFURL>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<CFRetained<CFURLEnumerator>> {
extern "C-unwind" {
fn CFURLEnumeratorCreateForDirectoryURL(
alloc: Option<&CFAllocator>,
directory_url: Option<&CFURL>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<NonNull<CFURLEnumerator>>;
}
let ret = unsafe {
CFURLEnumeratorCreateForDirectoryURL(alloc, directory_url, option, property_keys)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFURLEnumeratorCreateForMountedVolumes")]
#[cfg(feature = "CFArray")]
#[inline]
pub unsafe fn new_for_mounted_volumes(
alloc: Option<&CFAllocator>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<CFRetained<CFURLEnumerator>> {
extern "C-unwind" {
fn CFURLEnumeratorCreateForMountedVolumes(
alloc: Option<&CFAllocator>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<NonNull<CFURLEnumerator>>;
}
let ret = unsafe { CFURLEnumeratorCreateForMountedVolumes(alloc, option, property_keys) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfurlenumeratorresult?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFURLEnumeratorResult(pub CFIndex);
impl CFURLEnumeratorResult {
#[doc(alias = "kCFURLEnumeratorSuccess")]
pub const Success: Self = Self(1);
#[doc(alias = "kCFURLEnumeratorEnd")]
pub const End: Self = Self(2);
#[doc(alias = "kCFURLEnumeratorError")]
pub const Error: Self = Self(3);
#[doc(alias = "kCFURLEnumeratorDirectoryPostOrderSuccess")]
pub const DirectoryPostOrderSuccess: Self = Self(4);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFURLEnumeratorResult {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFURLEnumeratorResult {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CFURLEnumerator {
#[doc(alias = "CFURLEnumeratorGetNextURL")]
#[cfg(all(feature = "CFError", feature = "CFURL"))]
#[inline]
pub unsafe fn next_url(
self: &CFURLEnumerator,
url: *mut *const CFURL,
error: *mut *mut CFError,
) -> CFURLEnumeratorResult {
extern "C-unwind" {
fn CFURLEnumeratorGetNextURL(
enumerator: &CFURLEnumerator,
url: *mut *const CFURL,
error: *mut *mut CFError,
) -> CFURLEnumeratorResult;
}
unsafe { CFURLEnumeratorGetNextURL(self, url, error) }
}
#[doc(alias = "CFURLEnumeratorSkipDescendents")]
#[inline]
pub unsafe fn skip_descendents(self: &CFURLEnumerator) {
extern "C-unwind" {
fn CFURLEnumeratorSkipDescendents(enumerator: &CFURLEnumerator);
}
unsafe { CFURLEnumeratorSkipDescendents(self) }
}
#[doc(alias = "CFURLEnumeratorGetDescendentLevel")]
#[inline]
pub unsafe fn descendent_level(self: &CFURLEnumerator) -> CFIndex {
extern "C-unwind" {
fn CFURLEnumeratorGetDescendentLevel(enumerator: &CFURLEnumerator) -> CFIndex;
}
unsafe { CFURLEnumeratorGetDescendentLevel(self) }
}
#[doc(alias = "CFURLEnumeratorGetSourceDidChange")]
#[deprecated = "Use File System Events API instead"]
#[inline]
pub unsafe fn source_did_change(self: &CFURLEnumerator) -> bool {
extern "C-unwind" {
fn CFURLEnumeratorGetSourceDidChange(enumerator: &CFURLEnumerator) -> Boolean;
}
let ret = unsafe { CFURLEnumeratorGetSourceDidChange(self) };
ret != 0
}
}
#[cfg(all(feature = "CFArray", feature = "CFURL"))]
#[deprecated = "renamed to `CFURLEnumerator::new_for_directory_url`"]
#[inline]
pub unsafe extern "C-unwind" fn CFURLEnumeratorCreateForDirectoryURL(
alloc: Option<&CFAllocator>,
directory_url: Option<&CFURL>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<CFRetained<CFURLEnumerator>> {
extern "C-unwind" {
fn CFURLEnumeratorCreateForDirectoryURL(
alloc: Option<&CFAllocator>,
directory_url: Option<&CFURL>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<NonNull<CFURLEnumerator>>;
}
let ret = unsafe {
CFURLEnumeratorCreateForDirectoryURL(alloc, directory_url, option, property_keys)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFArray")]
#[deprecated = "renamed to `CFURLEnumerator::new_for_mounted_volumes`"]
#[inline]
pub unsafe extern "C-unwind" fn CFURLEnumeratorCreateForMountedVolumes(
alloc: Option<&CFAllocator>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<CFRetained<CFURLEnumerator>> {
extern "C-unwind" {
fn CFURLEnumeratorCreateForMountedVolumes(
alloc: Option<&CFAllocator>,
option: CFURLEnumeratorOptions,
property_keys: Option<&CFArray>,
) -> Option<NonNull<CFURLEnumerator>>;
}
let ret = unsafe { CFURLEnumeratorCreateForMountedVolumes(alloc, option, property_keys) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[cfg(all(feature = "CFError", feature = "CFURL"))]
#[deprecated = "renamed to `CFURLEnumerator::next_url`"]
pub fn CFURLEnumeratorGetNextURL(
enumerator: &CFURLEnumerator,
url: *mut *const CFURL,
error: *mut *mut CFError,
) -> CFURLEnumeratorResult;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFURLEnumerator::skip_descendents`"]
pub fn CFURLEnumeratorSkipDescendents(enumerator: &CFURLEnumerator);
}
extern "C-unwind" {
#[deprecated = "renamed to `CFURLEnumerator::descendent_level`"]
pub fn CFURLEnumeratorGetDescendentLevel(enumerator: &CFURLEnumerator) -> CFIndex;
}
#[deprecated = "renamed to `CFURLEnumerator::source_did_change`"]
#[inline]
pub unsafe extern "C-unwind" fn CFURLEnumeratorGetSourceDidChange(
enumerator: &CFURLEnumerator,
) -> bool {
extern "C-unwind" {
fn CFURLEnumeratorGetSourceDidChange(enumerator: &CFURLEnumerator) -> Boolean;
}
let ret = unsafe { CFURLEnumeratorGetSourceDidChange(enumerator) };
ret != 0
}

View File

@@ -0,0 +1,427 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfuuid?language=objc)
#[repr(C)]
pub struct CFUUID {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFUUID {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFUUID"> for CFUUID {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfuuidbytes?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFUUIDBytes {
pub byte0: u8,
pub byte1: u8,
pub byte2: u8,
pub byte3: u8,
pub byte4: u8,
pub byte5: u8,
pub byte6: u8,
pub byte7: u8,
pub byte8: u8,
pub byte9: u8,
pub byte10: u8,
pub byte11: u8,
pub byte12: u8,
pub byte13: u8,
pub byte14: u8,
pub byte15: u8,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFUUIDBytes {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
<u8>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFUUIDBytes {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFUUID {
#[doc(alias = "CFUUIDGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFUUIDGetTypeID() -> CFTypeID;
}
unsafe { CFUUIDGetTypeID() }
}
}
impl CFUUID {
#[doc(alias = "CFUUIDCreate")]
#[inline]
pub fn new(alloc: Option<&CFAllocator>) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreate(alloc: Option<&CFAllocator>) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe { CFUUIDCreate(alloc) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFUUIDCreateWithBytes")]
#[inline]
pub fn with_bytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreateWithBytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe {
CFUUIDCreateWithBytes(
alloc, byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8, byte9,
byte10, byte11, byte12, byte13, byte14, byte15,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFUUIDCreateFromString")]
#[inline]
pub fn from_string(
alloc: Option<&CFAllocator>,
uuid_str: Option<&CFString>,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreateFromString(
alloc: Option<&CFAllocator>,
uuid_str: Option<&CFString>,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe { CFUUIDCreateFromString(alloc, uuid_str) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFUUIDCreateString")]
#[inline]
pub fn new_string(
alloc: Option<&CFAllocator>,
uuid: Option<&CFUUID>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFUUIDCreateString(
alloc: Option<&CFAllocator>,
uuid: Option<&CFUUID>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFUUIDCreateString(alloc, uuid) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFUUIDGetConstantUUIDWithBytes")]
#[inline]
pub fn constant_uuid_with_bytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDGetConstantUUIDWithBytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe {
CFUUIDGetConstantUUIDWithBytes(
alloc, byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8, byte9,
byte10, byte11, byte12, byte13, byte14, byte15,
)
};
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFUUIDGetUUIDBytes")]
#[inline]
pub fn uuid_bytes(self: &CFUUID) -> CFUUIDBytes {
extern "C-unwind" {
fn CFUUIDGetUUIDBytes(uuid: &CFUUID) -> CFUUIDBytes;
}
unsafe { CFUUIDGetUUIDBytes(self) }
}
#[doc(alias = "CFUUIDCreateFromUUIDBytes")]
#[inline]
pub fn from_uuid_bytes(
alloc: Option<&CFAllocator>,
bytes: CFUUIDBytes,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreateFromUUIDBytes(
alloc: Option<&CFAllocator>,
bytes: CFUUIDBytes,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe { CFUUIDCreateFromUUIDBytes(alloc, bytes) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
#[deprecated = "renamed to `CFUUID::new`"]
#[inline]
pub extern "C-unwind" fn CFUUIDCreate(alloc: Option<&CFAllocator>) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreate(alloc: Option<&CFAllocator>) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe { CFUUIDCreate(alloc) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFUUID::with_bytes`"]
#[inline]
pub extern "C-unwind" fn CFUUIDCreateWithBytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreateWithBytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe {
CFUUIDCreateWithBytes(
alloc, byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8, byte9, byte10,
byte11, byte12, byte13, byte14, byte15,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFUUID::from_string`"]
#[inline]
pub extern "C-unwind" fn CFUUIDCreateFromString(
alloc: Option<&CFAllocator>,
uuid_str: Option<&CFString>,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreateFromString(
alloc: Option<&CFAllocator>,
uuid_str: Option<&CFString>,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe { CFUUIDCreateFromString(alloc, uuid_str) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFUUID::new_string`"]
#[inline]
pub extern "C-unwind" fn CFUUIDCreateString(
alloc: Option<&CFAllocator>,
uuid: Option<&CFUUID>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFUUIDCreateString(
alloc: Option<&CFAllocator>,
uuid: Option<&CFUUID>,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFUUIDCreateString(alloc, uuid) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFUUID::constant_uuid_with_bytes`"]
#[inline]
pub extern "C-unwind" fn CFUUIDGetConstantUUIDWithBytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDGetConstantUUIDWithBytes(
alloc: Option<&CFAllocator>,
byte0: u8,
byte1: u8,
byte2: u8,
byte3: u8,
byte4: u8,
byte5: u8,
byte6: u8,
byte7: u8,
byte8: u8,
byte9: u8,
byte10: u8,
byte11: u8,
byte12: u8,
byte13: u8,
byte14: u8,
byte15: u8,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe {
CFUUIDGetConstantUUIDWithBytes(
alloc, byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8, byte9, byte10,
byte11, byte12, byte13, byte14, byte15,
)
};
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFUUID::uuid_bytes`"]
#[inline]
pub extern "C-unwind" fn CFUUIDGetUUIDBytes(uuid: &CFUUID) -> CFUUIDBytes {
extern "C-unwind" {
fn CFUUIDGetUUIDBytes(uuid: &CFUUID) -> CFUUIDBytes;
}
unsafe { CFUUIDGetUUIDBytes(uuid) }
}
#[deprecated = "renamed to `CFUUID::from_uuid_bytes`"]
#[inline]
pub extern "C-unwind" fn CFUUIDCreateFromUUIDBytes(
alloc: Option<&CFAllocator>,
bytes: CFUUIDBytes,
) -> Option<CFRetained<CFUUID>> {
extern "C-unwind" {
fn CFUUIDCreateFromUUIDBytes(
alloc: Option<&CFAllocator>,
bytes: CFUUIDBytes,
) -> Option<NonNull<CFUUID>>;
}
let ret = unsafe { CFUUIDCreateFromUUIDBytes(alloc, bytes) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,522 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfusernotification?language=objc)
#[repr(C)]
pub struct CFUserNotification {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFUserNotification {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFUserNotification"> for CFUserNotification {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfusernotificationcallback?language=objc)
pub type CFUserNotificationCallBack =
Option<unsafe extern "C-unwind" fn(*mut CFUserNotification, CFOptionFlags)>;
unsafe impl ConcreteType for CFUserNotification {
#[doc(alias = "CFUserNotificationGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFUserNotificationGetTypeID() -> CFTypeID;
}
unsafe { CFUserNotificationGetTypeID() }
}
}
impl CFUserNotification {
#[doc(alias = "CFUserNotificationCreate")]
#[cfg(all(feature = "CFDate", feature = "CFDictionary"))]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
timeout: CFTimeInterval,
flags: CFOptionFlags,
error: *mut i32,
dictionary: Option<&CFDictionary>,
) -> Option<CFRetained<CFUserNotification>> {
extern "C-unwind" {
fn CFUserNotificationCreate(
allocator: Option<&CFAllocator>,
timeout: CFTimeInterval,
flags: CFOptionFlags,
error: *mut i32,
dictionary: Option<&CFDictionary>,
) -> Option<NonNull<CFUserNotification>>;
}
let ret = unsafe { CFUserNotificationCreate(allocator, timeout, flags, error, dictionary) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFUserNotificationReceiveResponse")]
#[cfg(feature = "CFDate")]
#[inline]
pub unsafe fn receive_response(
self: &CFUserNotification,
timeout: CFTimeInterval,
response_flags: *mut CFOptionFlags,
) -> i32 {
extern "C-unwind" {
fn CFUserNotificationReceiveResponse(
user_notification: &CFUserNotification,
timeout: CFTimeInterval,
response_flags: *mut CFOptionFlags,
) -> i32;
}
unsafe { CFUserNotificationReceiveResponse(self, timeout, response_flags) }
}
#[doc(alias = "CFUserNotificationGetResponseValue")]
#[inline]
pub unsafe fn response_value(
self: &CFUserNotification,
key: Option<&CFString>,
idx: CFIndex,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFUserNotificationGetResponseValue(
user_notification: &CFUserNotification,
key: Option<&CFString>,
idx: CFIndex,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFUserNotificationGetResponseValue(self, key, idx) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFUserNotificationGetResponseDictionary")]
#[cfg(feature = "CFDictionary")]
#[inline]
pub fn response_dictionary(self: &CFUserNotification) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFUserNotificationGetResponseDictionary(
user_notification: &CFUserNotification,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFUserNotificationGetResponseDictionary(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFUserNotificationUpdate")]
#[cfg(all(feature = "CFDate", feature = "CFDictionary"))]
#[inline]
pub unsafe fn update(
self: &CFUserNotification,
timeout: CFTimeInterval,
flags: CFOptionFlags,
dictionary: Option<&CFDictionary>,
) -> i32 {
extern "C-unwind" {
fn CFUserNotificationUpdate(
user_notification: &CFUserNotification,
timeout: CFTimeInterval,
flags: CFOptionFlags,
dictionary: Option<&CFDictionary>,
) -> i32;
}
unsafe { CFUserNotificationUpdate(self, timeout, flags, dictionary) }
}
#[doc(alias = "CFUserNotificationCancel")]
#[inline]
pub fn cancel(self: &CFUserNotification) -> i32 {
extern "C-unwind" {
fn CFUserNotificationCancel(user_notification: &CFUserNotification) -> i32;
}
unsafe { CFUserNotificationCancel(self) }
}
#[doc(alias = "CFUserNotificationCreateRunLoopSource")]
#[cfg(feature = "CFRunLoop")]
#[inline]
pub unsafe fn new_run_loop_source(
allocator: Option<&CFAllocator>,
user_notification: Option<&CFUserNotification>,
callout: CFUserNotificationCallBack,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFUserNotificationCreateRunLoopSource(
allocator: Option<&CFAllocator>,
user_notification: Option<&CFUserNotification>,
callout: CFUserNotificationCallBack,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe {
CFUserNotificationCreateRunLoopSource(allocator, user_notification, callout, order)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFUserNotificationDisplayNotice")]
#[cfg(all(feature = "CFDate", feature = "CFURL"))]
#[inline]
pub fn display_notice(
timeout: CFTimeInterval,
flags: CFOptionFlags,
icon_url: Option<&CFURL>,
sound_url: Option<&CFURL>,
localization_url: Option<&CFURL>,
alert_header: Option<&CFString>,
alert_message: Option<&CFString>,
default_button_title: Option<&CFString>,
) -> i32 {
extern "C-unwind" {
fn CFUserNotificationDisplayNotice(
timeout: CFTimeInterval,
flags: CFOptionFlags,
icon_url: Option<&CFURL>,
sound_url: Option<&CFURL>,
localization_url: Option<&CFURL>,
alert_header: Option<&CFString>,
alert_message: Option<&CFString>,
default_button_title: Option<&CFString>,
) -> i32;
}
unsafe {
CFUserNotificationDisplayNotice(
timeout,
flags,
icon_url,
sound_url,
localization_url,
alert_header,
alert_message,
default_button_title,
)
}
}
#[doc(alias = "CFUserNotificationDisplayAlert")]
#[cfg(all(feature = "CFDate", feature = "CFURL"))]
#[inline]
pub unsafe fn display_alert(
timeout: CFTimeInterval,
flags: CFOptionFlags,
icon_url: Option<&CFURL>,
sound_url: Option<&CFURL>,
localization_url: Option<&CFURL>,
alert_header: Option<&CFString>,
alert_message: Option<&CFString>,
default_button_title: Option<&CFString>,
alternate_button_title: Option<&CFString>,
other_button_title: Option<&CFString>,
response_flags: *mut CFOptionFlags,
) -> i32 {
extern "C-unwind" {
fn CFUserNotificationDisplayAlert(
timeout: CFTimeInterval,
flags: CFOptionFlags,
icon_url: Option<&CFURL>,
sound_url: Option<&CFURL>,
localization_url: Option<&CFURL>,
alert_header: Option<&CFString>,
alert_message: Option<&CFString>,
default_button_title: Option<&CFString>,
alternate_button_title: Option<&CFString>,
other_button_title: Option<&CFString>,
response_flags: *mut CFOptionFlags,
) -> i32;
}
unsafe {
CFUserNotificationDisplayAlert(
timeout,
flags,
icon_url,
sound_url,
localization_url,
alert_header,
alert_message,
default_button_title,
alternate_button_title,
other_button_title,
response_flags,
)
}
}
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationstopalertlevel?language=objc)
pub const kCFUserNotificationStopAlertLevel: CFOptionFlags = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationnotealertlevel?language=objc)
pub const kCFUserNotificationNoteAlertLevel: CFOptionFlags = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationcautionalertlevel?language=objc)
pub const kCFUserNotificationCautionAlertLevel: CFOptionFlags = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationplainalertlevel?language=objc)
pub const kCFUserNotificationPlainAlertLevel: CFOptionFlags = 3;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationdefaultresponse?language=objc)
pub const kCFUserNotificationDefaultResponse: CFOptionFlags = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationalternateresponse?language=objc)
pub const kCFUserNotificationAlternateResponse: CFOptionFlags = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationotherresponse?language=objc)
pub const kCFUserNotificationOtherResponse: CFOptionFlags = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationcancelresponse?language=objc)
pub const kCFUserNotificationCancelResponse: CFOptionFlags = 3;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationnodefaultbuttonflag?language=objc)
pub const kCFUserNotificationNoDefaultButtonFlag: CFOptionFlags = 1 << 5;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationuseradiobuttonsflag?language=objc)
pub const kCFUserNotificationUseRadioButtonsFlag: CFOptionFlags = 1 << 6;
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationiconurlkey?language=objc)
pub static kCFUserNotificationIconURLKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationsoundurlkey?language=objc)
pub static kCFUserNotificationSoundURLKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationlocalizationurlkey?language=objc)
pub static kCFUserNotificationLocalizationURLKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationalertheaderkey?language=objc)
pub static kCFUserNotificationAlertHeaderKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationalertmessagekey?language=objc)
pub static kCFUserNotificationAlertMessageKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationdefaultbuttontitlekey?language=objc)
pub static kCFUserNotificationDefaultButtonTitleKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationalternatebuttontitlekey?language=objc)
pub static kCFUserNotificationAlternateButtonTitleKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationotherbuttontitlekey?language=objc)
pub static kCFUserNotificationOtherButtonTitleKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationprogressindicatorvaluekey?language=objc)
pub static kCFUserNotificationProgressIndicatorValueKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationpopuptitleskey?language=objc)
pub static kCFUserNotificationPopUpTitlesKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationtextfieldtitleskey?language=objc)
pub static kCFUserNotificationTextFieldTitlesKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationcheckboxtitleskey?language=objc)
pub static kCFUserNotificationCheckBoxTitlesKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationtextfieldvalueskey?language=objc)
pub static kCFUserNotificationTextFieldValuesKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationpopupselectionkey?language=objc)
pub static kCFUserNotificationPopUpSelectionKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationalerttopmostkey?language=objc)
pub static kCFUserNotificationAlertTopMostKey: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfusernotificationkeyboardtypeskey?language=objc)
pub static kCFUserNotificationKeyboardTypesKey: Option<&'static CFString>;
}
#[cfg(all(feature = "CFDate", feature = "CFDictionary"))]
#[deprecated = "renamed to `CFUserNotification::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFUserNotificationCreate(
allocator: Option<&CFAllocator>,
timeout: CFTimeInterval,
flags: CFOptionFlags,
error: *mut i32,
dictionary: Option<&CFDictionary>,
) -> Option<CFRetained<CFUserNotification>> {
extern "C-unwind" {
fn CFUserNotificationCreate(
allocator: Option<&CFAllocator>,
timeout: CFTimeInterval,
flags: CFOptionFlags,
error: *mut i32,
dictionary: Option<&CFDictionary>,
) -> Option<NonNull<CFUserNotification>>;
}
let ret = unsafe { CFUserNotificationCreate(allocator, timeout, flags, error, dictionary) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[cfg(feature = "CFDate")]
#[deprecated = "renamed to `CFUserNotification::receive_response`"]
pub fn CFUserNotificationReceiveResponse(
user_notification: &CFUserNotification,
timeout: CFTimeInterval,
response_flags: *mut CFOptionFlags,
) -> i32;
}
#[deprecated = "renamed to `CFUserNotification::response_value`"]
#[inline]
pub unsafe extern "C-unwind" fn CFUserNotificationGetResponseValue(
user_notification: &CFUserNotification,
key: Option<&CFString>,
idx: CFIndex,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFUserNotificationGetResponseValue(
user_notification: &CFUserNotification,
key: Option<&CFString>,
idx: CFIndex,
) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFUserNotificationGetResponseValue(user_notification, key, idx) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[cfg(feature = "CFDictionary")]
#[deprecated = "renamed to `CFUserNotification::response_dictionary`"]
#[inline]
pub extern "C-unwind" fn CFUserNotificationGetResponseDictionary(
user_notification: &CFUserNotification,
) -> Option<CFRetained<CFDictionary>> {
extern "C-unwind" {
fn CFUserNotificationGetResponseDictionary(
user_notification: &CFUserNotification,
) -> Option<NonNull<CFDictionary>>;
}
let ret = unsafe { CFUserNotificationGetResponseDictionary(user_notification) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[cfg(all(feature = "CFDate", feature = "CFDictionary"))]
#[deprecated = "renamed to `CFUserNotification::update`"]
pub fn CFUserNotificationUpdate(
user_notification: &CFUserNotification,
timeout: CFTimeInterval,
flags: CFOptionFlags,
dictionary: Option<&CFDictionary>,
) -> i32;
}
#[deprecated = "renamed to `CFUserNotification::cancel`"]
#[inline]
pub extern "C-unwind" fn CFUserNotificationCancel(user_notification: &CFUserNotification) -> i32 {
extern "C-unwind" {
fn CFUserNotificationCancel(user_notification: &CFUserNotification) -> i32;
}
unsafe { CFUserNotificationCancel(user_notification) }
}
#[cfg(feature = "CFRunLoop")]
#[deprecated = "renamed to `CFUserNotification::new_run_loop_source`"]
#[inline]
pub unsafe extern "C-unwind" fn CFUserNotificationCreateRunLoopSource(
allocator: Option<&CFAllocator>,
user_notification: Option<&CFUserNotification>,
callout: CFUserNotificationCallBack,
order: CFIndex,
) -> Option<CFRetained<CFRunLoopSource>> {
extern "C-unwind" {
fn CFUserNotificationCreateRunLoopSource(
allocator: Option<&CFAllocator>,
user_notification: Option<&CFUserNotification>,
callout: CFUserNotificationCallBack,
order: CFIndex,
) -> Option<NonNull<CFRunLoopSource>>;
}
let ret = unsafe {
CFUserNotificationCreateRunLoopSource(allocator, user_notification, callout, order)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFDate", feature = "CFURL"))]
#[deprecated = "renamed to `CFUserNotification::display_notice`"]
#[inline]
pub extern "C-unwind" fn CFUserNotificationDisplayNotice(
timeout: CFTimeInterval,
flags: CFOptionFlags,
icon_url: Option<&CFURL>,
sound_url: Option<&CFURL>,
localization_url: Option<&CFURL>,
alert_header: Option<&CFString>,
alert_message: Option<&CFString>,
default_button_title: Option<&CFString>,
) -> i32 {
extern "C-unwind" {
fn CFUserNotificationDisplayNotice(
timeout: CFTimeInterval,
flags: CFOptionFlags,
icon_url: Option<&CFURL>,
sound_url: Option<&CFURL>,
localization_url: Option<&CFURL>,
alert_header: Option<&CFString>,
alert_message: Option<&CFString>,
default_button_title: Option<&CFString>,
) -> i32;
}
unsafe {
CFUserNotificationDisplayNotice(
timeout,
flags,
icon_url,
sound_url,
localization_url,
alert_header,
alert_message,
default_button_title,
)
}
}
extern "C-unwind" {
#[cfg(all(feature = "CFDate", feature = "CFURL"))]
#[deprecated = "renamed to `CFUserNotification::display_alert`"]
pub fn CFUserNotificationDisplayAlert(
timeout: CFTimeInterval,
flags: CFOptionFlags,
icon_url: Option<&CFURL>,
sound_url: Option<&CFURL>,
localization_url: Option<&CFURL>,
alert_header: Option<&CFString>,
alert_message: Option<&CFString>,
default_button_title: Option<&CFString>,
alternate_button_title: Option<&CFString>,
other_button_title: Option<&CFString>,
response_flags: *mut CFOptionFlags,
) -> i32;
}

View File

@@ -0,0 +1,15 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
use crate::*;
#[cfg(feature = "CFURL")]
#[inline]
pub extern "C-unwind" fn CFCopyHomeDirectoryURL() -> Option<CFRetained<CFURL>> {
extern "C-unwind" {
fn CFCopyHomeDirectoryURL() -> Option<NonNull<CFURL>>;
}
let ret = unsafe { CFCopyHomeDirectoryURL() };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

View File

@@ -0,0 +1,538 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfxmlnodecurrentversion?language=objc)
pub const kCFXMLNodeCurrentVersion: CFIndex = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlnode?language=objc)
#[repr(C)]
pub struct CFXMLNode {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFXMLNode {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFXMLNode"> for CFXMLNode {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmltree?language=objc)
#[cfg(feature = "CFTree")]
pub type CFXMLTree = CFTree;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlnodetypecode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFXMLNodeTypeCode(pub CFIndex);
impl CFXMLNodeTypeCode {
#[doc(alias = "kCFXMLNodeTypeDocument")]
pub const Document: Self = Self(1);
#[doc(alias = "kCFXMLNodeTypeElement")]
pub const Element: Self = Self(2);
#[doc(alias = "kCFXMLNodeTypeAttribute")]
pub const Attribute: Self = Self(3);
#[doc(alias = "kCFXMLNodeTypeProcessingInstruction")]
pub const ProcessingInstruction: Self = Self(4);
#[doc(alias = "kCFXMLNodeTypeComment")]
pub const Comment: Self = Self(5);
#[doc(alias = "kCFXMLNodeTypeText")]
pub const Text: Self = Self(6);
#[doc(alias = "kCFXMLNodeTypeCDATASection")]
pub const CDATASection: Self = Self(7);
#[doc(alias = "kCFXMLNodeTypeDocumentFragment")]
pub const DocumentFragment: Self = Self(8);
#[doc(alias = "kCFXMLNodeTypeEntity")]
pub const Entity: Self = Self(9);
#[doc(alias = "kCFXMLNodeTypeEntityReference")]
pub const EntityReference: Self = Self(10);
#[doc(alias = "kCFXMLNodeTypeDocumentType")]
pub const DocumentType: Self = Self(11);
#[doc(alias = "kCFXMLNodeTypeWhitespace")]
pub const Whitespace: Self = Self(12);
#[doc(alias = "kCFXMLNodeTypeNotation")]
pub const Notation: Self = Self(13);
#[doc(alias = "kCFXMLNodeTypeElementTypeDeclaration")]
pub const ElementTypeDeclaration: Self = Self(14);
#[doc(alias = "kCFXMLNodeTypeAttributeListDeclaration")]
pub const AttributeListDeclaration: Self = Self(15);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLNodeTypeCode {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLNodeTypeCode {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlelementinfo?language=objc)
#[cfg(all(feature = "CFArray", feature = "CFDictionary"))]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLElementInfo {
pub attributes: *const CFDictionary,
pub attributeOrder: *const CFArray,
pub isEmpty: Boolean,
pub(crate) _reserved: [c_char; 3],
}
#[cfg(all(feature = "CFArray", feature = "CFDictionary", feature = "objc2"))]
unsafe impl Encode for CFXMLElementInfo {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<*const CFDictionary>::ENCODING,
<*const CFArray>::ENCODING,
<Boolean>::ENCODING,
<[c_char; 3]>::ENCODING,
],
);
}
#[cfg(all(feature = "CFArray", feature = "CFDictionary", feature = "objc2"))]
unsafe impl RefEncode for CFXMLElementInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlprocessinginstructioninfo?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLProcessingInstructionInfo {
pub dataString: *const CFString,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLProcessingInstructionInfo {
const ENCODING: Encoding = Encoding::Struct("?", &[<*const CFString>::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLProcessingInstructionInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmldocumentinfo?language=objc)
#[cfg(all(feature = "CFString", feature = "CFURL"))]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLDocumentInfo {
pub sourceURL: *const CFURL,
pub encoding: CFStringEncoding,
}
#[cfg(all(feature = "CFString", feature = "CFURL", feature = "objc2"))]
unsafe impl Encode for CFXMLDocumentInfo {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[<*const CFURL>::ENCODING, <CFStringEncoding>::ENCODING],
);
}
#[cfg(all(feature = "CFString", feature = "CFURL", feature = "objc2"))]
unsafe impl RefEncode for CFXMLDocumentInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlexternalid?language=objc)
#[cfg(feature = "CFURL")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLExternalID {
pub systemID: *const CFURL,
pub publicID: *const CFString,
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl Encode for CFXMLExternalID {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[<*const CFURL>::ENCODING, <*const CFString>::ENCODING],
);
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl RefEncode for CFXMLExternalID {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmldocumenttypeinfo?language=objc)
#[cfg(feature = "CFURL")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLDocumentTypeInfo {
pub externalID: CFXMLExternalID,
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl Encode for CFXMLDocumentTypeInfo {
const ENCODING: Encoding = Encoding::Struct("?", &[<CFXMLExternalID>::ENCODING]);
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl RefEncode for CFXMLDocumentTypeInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlnotationinfo?language=objc)
#[cfg(feature = "CFURL")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLNotationInfo {
pub externalID: CFXMLExternalID,
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl Encode for CFXMLNotationInfo {
const ENCODING: Encoding = Encoding::Struct("?", &[<CFXMLExternalID>::ENCODING]);
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl RefEncode for CFXMLNotationInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlelementtypedeclarationinfo?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLElementTypeDeclarationInfo {
pub contentDescription: *const CFString,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLElementTypeDeclarationInfo {
const ENCODING: Encoding = Encoding::Struct("?", &[<*const CFString>::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLElementTypeDeclarationInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlattributedeclarationinfo?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLAttributeDeclarationInfo {
pub attributeName: *const CFString,
pub typeString: *const CFString,
pub defaultString: *const CFString,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLAttributeDeclarationInfo {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<*const CFString>::ENCODING,
<*const CFString>::ENCODING,
<*const CFString>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLAttributeDeclarationInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlattributelistdeclarationinfo?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLAttributeListDeclarationInfo {
pub numberOfAttributes: CFIndex,
pub attributes: *mut CFXMLAttributeDeclarationInfo,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLAttributeListDeclarationInfo {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut CFXMLAttributeDeclarationInfo>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLAttributeListDeclarationInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlentitytypecode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFXMLEntityTypeCode(pub CFIndex);
impl CFXMLEntityTypeCode {
#[doc(alias = "kCFXMLEntityTypeParameter")]
pub const Parameter: Self = Self(0);
#[doc(alias = "kCFXMLEntityTypeParsedInternal")]
pub const ParsedInternal: Self = Self(1);
#[doc(alias = "kCFXMLEntityTypeParsedExternal")]
pub const ParsedExternal: Self = Self(2);
#[doc(alias = "kCFXMLEntityTypeUnparsed")]
pub const Unparsed: Self = Self(3);
#[doc(alias = "kCFXMLEntityTypeCharacter")]
pub const Character: Self = Self(4);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLEntityTypeCode {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLEntityTypeCode {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlentityinfo?language=objc)
#[cfg(feature = "CFURL")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLEntityInfo {
pub entityType: CFXMLEntityTypeCode,
pub replacementText: *const CFString,
pub entityID: CFXMLExternalID,
pub notationName: *const CFString,
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl Encode for CFXMLEntityInfo {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFXMLEntityTypeCode>::ENCODING,
<*const CFString>::ENCODING,
<CFXMLExternalID>::ENCODING,
<*const CFString>::ENCODING,
],
);
}
#[cfg(all(feature = "CFURL", feature = "objc2"))]
unsafe impl RefEncode for CFXMLEntityInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlentityreferenceinfo?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLEntityReferenceInfo {
pub entityType: CFXMLEntityTypeCode,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLEntityReferenceInfo {
const ENCODING: Encoding = Encoding::Struct("?", &[<CFXMLEntityTypeCode>::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLEntityReferenceInfo {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFXMLNode {
#[doc(alias = "CFXMLNodeGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFXMLNodeGetTypeID() -> CFTypeID;
}
unsafe { CFXMLNodeGetTypeID() }
}
}
impl CFXMLNode {
#[doc(alias = "CFXMLNodeCreate")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn new(
alloc: Option<&CFAllocator>,
xml_type: CFXMLNodeTypeCode,
data_string: Option<&CFString>,
additional_info_ptr: *const c_void,
version: CFIndex,
) -> Option<CFRetained<CFXMLNode>> {
extern "C-unwind" {
fn CFXMLNodeCreate(
alloc: Option<&CFAllocator>,
xml_type: CFXMLNodeTypeCode,
data_string: Option<&CFString>,
additional_info_ptr: *const c_void,
version: CFIndex,
) -> Option<NonNull<CFXMLNode>>;
}
let ret =
unsafe { CFXMLNodeCreate(alloc, xml_type, data_string, additional_info_ptr, version) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFXMLNodeCreateCopy")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn new_copy(
alloc: Option<&CFAllocator>,
orig_node: Option<&CFXMLNode>,
) -> Option<CFRetained<CFXMLNode>> {
extern "C-unwind" {
fn CFXMLNodeCreateCopy(
alloc: Option<&CFAllocator>,
orig_node: Option<&CFXMLNode>,
) -> Option<NonNull<CFXMLNode>>;
}
let ret = unsafe { CFXMLNodeCreateCopy(alloc, orig_node) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFXMLNodeGetTypeCode")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn type_code(self: &CFXMLNode) -> CFXMLNodeTypeCode {
extern "C-unwind" {
fn CFXMLNodeGetTypeCode(node: &CFXMLNode) -> CFXMLNodeTypeCode;
}
unsafe { CFXMLNodeGetTypeCode(self) }
}
#[doc(alias = "CFXMLNodeGetString")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn string(self: &CFXMLNode) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFXMLNodeGetString(node: &CFXMLNode) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFXMLNodeGetString(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFXMLNodeGetInfoPtr")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn info_ptr(self: &CFXMLNode) -> *const c_void {
extern "C-unwind" {
fn CFXMLNodeGetInfoPtr(node: &CFXMLNode) -> *const c_void;
}
unsafe { CFXMLNodeGetInfoPtr(self) }
}
#[doc(alias = "CFXMLNodeGetVersion")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn version(self: &CFXMLNode) -> CFIndex {
extern "C-unwind" {
fn CFXMLNodeGetVersion(node: &CFXMLNode) -> CFIndex;
}
unsafe { CFXMLNodeGetVersion(self) }
}
}
#[cfg(feature = "CFTree")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLTreeCreateWithNode(
allocator: Option<&CFAllocator>,
node: Option<&CFXMLNode>,
) -> Option<CFRetained<CFXMLTree>> {
extern "C-unwind" {
fn CFXMLTreeCreateWithNode(
allocator: Option<&CFAllocator>,
node: Option<&CFXMLNode>,
) -> Option<NonNull<CFXMLTree>>;
}
let ret = unsafe { CFXMLTreeCreateWithNode(allocator, node) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFTree")]
#[deprecated = "CFXMLNode is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLTreeGetNode(
xml_tree: &CFXMLTree,
) -> Option<CFRetained<CFXMLNode>> {
extern "C-unwind" {
fn CFXMLTreeGetNode(xml_tree: &CFXMLTree) -> Option<NonNull<CFXMLNode>>;
}
let ret = unsafe { CFXMLTreeGetNode(xml_tree) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[deprecated = "renamed to `CFXMLNode::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLNodeCreate(
alloc: Option<&CFAllocator>,
xml_type: CFXMLNodeTypeCode,
data_string: Option<&CFString>,
additional_info_ptr: *const c_void,
version: CFIndex,
) -> Option<CFRetained<CFXMLNode>> {
extern "C-unwind" {
fn CFXMLNodeCreate(
alloc: Option<&CFAllocator>,
xml_type: CFXMLNodeTypeCode,
data_string: Option<&CFString>,
additional_info_ptr: *const c_void,
version: CFIndex,
) -> Option<NonNull<CFXMLNode>>;
}
let ret =
unsafe { CFXMLNodeCreate(alloc, xml_type, data_string, additional_info_ptr, version) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CFXMLNode::new_copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLNodeCreateCopy(
alloc: Option<&CFAllocator>,
orig_node: Option<&CFXMLNode>,
) -> Option<CFRetained<CFXMLNode>> {
extern "C-unwind" {
fn CFXMLNodeCreateCopy(
alloc: Option<&CFAllocator>,
orig_node: Option<&CFXMLNode>,
) -> Option<NonNull<CFXMLNode>>;
}
let ret = unsafe { CFXMLNodeCreateCopy(alloc, orig_node) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLNode::type_code`"]
pub fn CFXMLNodeGetTypeCode(node: &CFXMLNode) -> CFXMLNodeTypeCode;
}
#[deprecated = "renamed to `CFXMLNode::string`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLNodeGetString(
node: &CFXMLNode,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFXMLNodeGetString(node: &CFXMLNode) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFXMLNodeGetString(node) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLNode::info_ptr`"]
pub fn CFXMLNodeGetInfoPtr(node: &CFXMLNode) -> *const c_void;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLNode::version`"]
pub fn CFXMLNodeGetVersion(node: &CFXMLNode) -> CFIndex;
}

View File

@@ -0,0 +1,749 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparser?language=objc)
#[repr(C)]
pub struct CFXMLParser {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CFXMLParser {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CFXMLParser"> for CFXMLParser {}
);
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparseroptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFXMLParserOptions(pub CFOptionFlags);
bitflags::bitflags! {
impl CFXMLParserOptions: CFOptionFlags {
#[doc(alias = "kCFXMLParserValidateDocument")]
const ValidateDocument = 1<<0;
#[doc(alias = "kCFXMLParserSkipMetaData")]
const SkipMetaData = 1<<1;
#[doc(alias = "kCFXMLParserReplacePhysicalEntities")]
const ReplacePhysicalEntities = 1<<2;
#[doc(alias = "kCFXMLParserSkipWhitespace")]
const SkipWhitespace = 1<<3;
#[doc(alias = "kCFXMLParserResolveExternalEntities")]
const ResolveExternalEntities = 1<<4;
#[doc(alias = "kCFXMLParserAddImpliedAttributes")]
const AddImpliedAttributes = 1<<5;
#[doc(alias = "kCFXMLParserAllOptions")]
const AllOptions = 0x00FFFFFF;
#[doc(alias = "kCFXMLParserNoOptions")]
const NoOptions = 0;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLParserOptions {
const ENCODING: Encoding = CFOptionFlags::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLParserOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparserstatuscode?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CFXMLParserStatusCode(pub CFIndex);
bitflags::bitflags! {
impl CFXMLParserStatusCode: CFIndex {
#[doc(alias = "kCFXMLStatusParseNotBegun")]
const StatusParseNotBegun = -2;
#[doc(alias = "kCFXMLStatusParseInProgress")]
const StatusParseInProgress = -1;
#[doc(alias = "kCFXMLStatusParseSuccessful")]
const StatusParseSuccessful = 0;
#[doc(alias = "kCFXMLErrorUnexpectedEOF")]
const ErrorUnexpectedEOF = 1;
#[doc(alias = "kCFXMLErrorUnknownEncoding")]
const ErrorUnknownEncoding = 2;
#[doc(alias = "kCFXMLErrorEncodingConversionFailure")]
const ErrorEncodingConversionFailure = 3;
#[doc(alias = "kCFXMLErrorMalformedProcessingInstruction")]
const ErrorMalformedProcessingInstruction = 4;
#[doc(alias = "kCFXMLErrorMalformedDTD")]
const ErrorMalformedDTD = 5;
#[doc(alias = "kCFXMLErrorMalformedName")]
const ErrorMalformedName = 6;
#[doc(alias = "kCFXMLErrorMalformedCDSect")]
const ErrorMalformedCDSect = 7;
#[doc(alias = "kCFXMLErrorMalformedCloseTag")]
const ErrorMalformedCloseTag = 8;
#[doc(alias = "kCFXMLErrorMalformedStartTag")]
const ErrorMalformedStartTag = 9;
#[doc(alias = "kCFXMLErrorMalformedDocument")]
const ErrorMalformedDocument = 10;
#[doc(alias = "kCFXMLErrorElementlessDocument")]
const ErrorElementlessDocument = 11;
#[doc(alias = "kCFXMLErrorMalformedComment")]
const ErrorMalformedComment = 12;
#[doc(alias = "kCFXMLErrorMalformedCharacterReference")]
const ErrorMalformedCharacterReference = 13;
#[doc(alias = "kCFXMLErrorMalformedParsedCharacterData")]
const ErrorMalformedParsedCharacterData = 14;
#[doc(alias = "kCFXMLErrorNoData")]
const ErrorNoData = 15;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLParserStatusCode {
const ENCODING: Encoding = CFIndex::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLParserStatusCode {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparsercreatexmlstructurecallback?language=objc)
#[cfg(feature = "CFXMLNode")]
pub type CFXMLParserCreateXMLStructureCallBack = Option<
unsafe extern "C-unwind" fn(*mut CFXMLParser, *const CFXMLNode, *mut c_void) -> *mut c_void,
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparseraddchildcallback?language=objc)
pub type CFXMLParserAddChildCallBack =
Option<unsafe extern "C-unwind" fn(*mut CFXMLParser, *mut c_void, *mut c_void, *mut c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparserendxmlstructurecallback?language=objc)
pub type CFXMLParserEndXMLStructureCallBack =
Option<unsafe extern "C-unwind" fn(*mut CFXMLParser, *mut c_void, *mut c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparserresolveexternalentitycallback?language=objc)
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
pub type CFXMLParserResolveExternalEntityCallBack = Option<
unsafe extern "C-unwind" fn(
*mut CFXMLParser,
*mut CFXMLExternalID,
*mut c_void,
) -> *const CFData,
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparserhandleerrorcallback?language=objc)
pub type CFXMLParserHandleErrorCallBack = Option<
unsafe extern "C-unwind" fn(*mut CFXMLParser, CFXMLParserStatusCode, *mut c_void) -> Boolean,
>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparsercallbacks?language=objc)
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLParserCallBacks {
pub version: CFIndex,
pub createXMLStructure: CFXMLParserCreateXMLStructureCallBack,
pub addChild: CFXMLParserAddChildCallBack,
pub endXMLStructure: CFXMLParserEndXMLStructureCallBack,
pub resolveExternalEntity: CFXMLParserResolveExternalEntityCallBack,
pub handleError: CFXMLParserHandleErrorCallBack,
}
#[cfg(all(
feature = "CFData",
feature = "CFURL",
feature = "CFXMLNode",
feature = "objc2"
))]
unsafe impl Encode for CFXMLParserCallBacks {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<CFXMLParserCreateXMLStructureCallBack>::ENCODING,
<CFXMLParserAddChildCallBack>::ENCODING,
<CFXMLParserEndXMLStructureCallBack>::ENCODING,
<CFXMLParserResolveExternalEntityCallBack>::ENCODING,
<CFXMLParserHandleErrorCallBack>::ENCODING,
],
);
}
#[cfg(all(
feature = "CFData",
feature = "CFURL",
feature = "CFXMLNode",
feature = "objc2"
))]
unsafe impl RefEncode for CFXMLParserCallBacks {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparserretaincallback?language=objc)
pub type CFXMLParserRetainCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparserreleasecallback?language=objc)
pub type CFXMLParserReleaseCallBack = Option<unsafe extern "C-unwind" fn(*const c_void)>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparsercopydescriptioncallback?language=objc)
pub type CFXMLParserCopyDescriptionCallBack =
Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfxmlparsercontext?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFXMLParserContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: CFXMLParserRetainCallBack,
pub release: CFXMLParserReleaseCallBack,
pub copyDescription: CFXMLParserCopyDescriptionCallBack,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CFXMLParserContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<CFXMLParserRetainCallBack>::ENCODING,
<CFXMLParserReleaseCallBack>::ENCODING,
<CFXMLParserCopyDescriptionCallBack>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CFXMLParserContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
unsafe impl ConcreteType for CFXMLParser {
#[doc(alias = "CFXMLParserGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CFXMLParserGetTypeID() -> CFTypeID;
}
unsafe { CFXMLParserGetTypeID() }
}
}
impl CFXMLParser {
#[doc(alias = "CFXMLParserCreate")]
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn new(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<CFRetained<CFXMLParser>> {
extern "C-unwind" {
fn CFXMLParserCreate(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<NonNull<CFXMLParser>>;
}
let ret = unsafe {
CFXMLParserCreate(
allocator,
xml_data,
data_source,
parse_options,
version_of_nodes,
call_backs,
context,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFXMLParserCreateWithDataFromURL")]
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn with_data_from_url(
allocator: Option<&CFAllocator>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<CFRetained<CFXMLParser>> {
extern "C-unwind" {
fn CFXMLParserCreateWithDataFromURL(
allocator: Option<&CFAllocator>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<NonNull<CFXMLParser>>;
}
let ret = unsafe {
CFXMLParserCreateWithDataFromURL(
allocator,
data_source,
parse_options,
version_of_nodes,
call_backs,
context,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFXMLParserGetContext")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn context(self: &CFXMLParser, context: *mut CFXMLParserContext) {
extern "C-unwind" {
fn CFXMLParserGetContext(parser: &CFXMLParser, context: *mut CFXMLParserContext);
}
unsafe { CFXMLParserGetContext(self, context) }
}
#[doc(alias = "CFXMLParserGetCallBacks")]
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn call_backs(self: &CFXMLParser, call_backs: *mut CFXMLParserCallBacks) {
extern "C-unwind" {
fn CFXMLParserGetCallBacks(parser: &CFXMLParser, call_backs: *mut CFXMLParserCallBacks);
}
unsafe { CFXMLParserGetCallBacks(self, call_backs) }
}
#[doc(alias = "CFXMLParserGetSourceURL")]
#[cfg(feature = "CFURL")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn source_url(self: &CFXMLParser) -> Option<CFRetained<CFURL>> {
extern "C-unwind" {
fn CFXMLParserGetSourceURL(parser: &CFXMLParser) -> Option<NonNull<CFURL>>;
}
let ret = unsafe { CFXMLParserGetSourceURL(self) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
#[doc(alias = "CFXMLParserGetLocation")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn location(self: &CFXMLParser) -> CFIndex {
extern "C-unwind" {
fn CFXMLParserGetLocation(parser: &CFXMLParser) -> CFIndex;
}
unsafe { CFXMLParserGetLocation(self) }
}
#[doc(alias = "CFXMLParserGetLineNumber")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn line_number(self: &CFXMLParser) -> CFIndex {
extern "C-unwind" {
fn CFXMLParserGetLineNumber(parser: &CFXMLParser) -> CFIndex;
}
unsafe { CFXMLParserGetLineNumber(self) }
}
#[doc(alias = "CFXMLParserGetDocument")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn document(self: &CFXMLParser) -> *mut c_void {
extern "C-unwind" {
fn CFXMLParserGetDocument(parser: &CFXMLParser) -> *mut c_void;
}
unsafe { CFXMLParserGetDocument(self) }
}
#[doc(alias = "CFXMLParserGetStatusCode")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn status_code(self: &CFXMLParser) -> CFXMLParserStatusCode {
extern "C-unwind" {
fn CFXMLParserGetStatusCode(parser: &CFXMLParser) -> CFXMLParserStatusCode;
}
unsafe { CFXMLParserGetStatusCode(self) }
}
#[doc(alias = "CFXMLParserCopyErrorDescription")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn error_description(self: &CFXMLParser) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFXMLParserCopyErrorDescription(parser: &CFXMLParser) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFXMLParserCopyErrorDescription(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CFXMLParserAbort")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn abort(
self: &CFXMLParser,
error_code: CFXMLParserStatusCode,
error_description: Option<&CFString>,
) {
extern "C-unwind" {
fn CFXMLParserAbort(
parser: &CFXMLParser,
error_code: CFXMLParserStatusCode,
error_description: Option<&CFString>,
);
}
unsafe { CFXMLParserAbort(self, error_code, error_description) }
}
#[doc(alias = "CFXMLParserParse")]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe fn parse(self: &CFXMLParser) -> bool {
extern "C-unwind" {
fn CFXMLParserParse(parser: &CFXMLParser) -> Boolean;
}
let ret = unsafe { CFXMLParserParse(self) };
ret != 0
}
}
#[cfg(all(
feature = "CFData",
feature = "CFTree",
feature = "CFURL",
feature = "CFXMLNode"
))]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLTreeCreateFromData(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
) -> Option<CFRetained<CFXMLTree>> {
extern "C-unwind" {
fn CFXMLTreeCreateFromData(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
) -> Option<NonNull<CFXMLTree>>;
}
let ret = unsafe {
CFXMLTreeCreateFromData(
allocator,
xml_data,
data_source,
parse_options,
version_of_nodes,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(
feature = "CFData",
feature = "CFDictionary",
feature = "CFTree",
feature = "CFURL",
feature = "CFXMLNode"
))]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLTreeCreateFromDataWithError(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
error_dict: *mut *const CFDictionary,
) -> Option<CFRetained<CFXMLTree>> {
extern "C-unwind" {
fn CFXMLTreeCreateFromDataWithError(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
error_dict: *mut *const CFDictionary,
) -> Option<NonNull<CFXMLTree>>;
}
let ret = unsafe {
CFXMLTreeCreateFromDataWithError(
allocator,
xml_data,
data_source,
parse_options,
version_of_nodes,
error_dict,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFTree", feature = "CFURL", feature = "CFXMLNode"))]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLTreeCreateWithDataFromURL(
allocator: Option<&CFAllocator>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
) -> Option<CFRetained<CFXMLTree>> {
extern "C-unwind" {
fn CFXMLTreeCreateWithDataFromURL(
allocator: Option<&CFAllocator>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
) -> Option<NonNull<CFXMLTree>>;
}
let ret = unsafe {
CFXMLTreeCreateWithDataFromURL(allocator, data_source, parse_options, version_of_nodes)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFData", feature = "CFTree", feature = "CFXMLNode"))]
#[deprecated = "CFXMLParser is deprecated, use NSXMLParser, NSXMLDocument or libxml2 library instead"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLTreeCreateXMLData(
allocator: Option<&CFAllocator>,
xml_tree: Option<&CFXMLTree>,
) -> Option<CFRetained<CFData>> {
extern "C-unwind" {
fn CFXMLTreeCreateXMLData(
allocator: Option<&CFAllocator>,
xml_tree: Option<&CFXMLTree>,
) -> Option<NonNull<CFData>>;
}
let ret = unsafe { CFXMLTreeCreateXMLData(allocator, xml_tree) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLCreateStringByEscapingEntities(
allocator: Option<&CFAllocator>,
string: Option<&CFString>,
entities_dictionary: Option<&CFDictionary>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFXMLCreateStringByEscapingEntities(
allocator: Option<&CFAllocator>,
string: Option<&CFString>,
entities_dictionary: Option<&CFDictionary>,
) -> Option<NonNull<CFString>>;
}
let ret =
unsafe { CFXMLCreateStringByEscapingEntities(allocator, string, entities_dictionary) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "CFDictionary")]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLCreateStringByUnescapingEntities(
allocator: Option<&CFAllocator>,
string: Option<&CFString>,
entities_dictionary: Option<&CFDictionary>,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFXMLCreateStringByUnescapingEntities(
allocator: Option<&CFAllocator>,
string: Option<&CFString>,
entities_dictionary: Option<&CFDictionary>,
) -> Option<NonNull<CFString>>;
}
let ret =
unsafe { CFXMLCreateStringByUnescapingEntities(allocator, string, entities_dictionary) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfxmltreeerrordescription?language=objc)
pub static kCFXMLTreeErrorDescription: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfxmltreeerrorlinenumber?language=objc)
pub static kCFXMLTreeErrorLineNumber: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfxmltreeerrorlocation?language=objc)
pub static kCFXMLTreeErrorLocation: Option<&'static CFString>;
}
extern "C" {
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfxmltreeerrorstatuscode?language=objc)
pub static kCFXMLTreeErrorStatusCode: Option<&'static CFString>;
}
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
#[deprecated = "renamed to `CFXMLParser::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLParserCreate(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<CFRetained<CFXMLParser>> {
extern "C-unwind" {
fn CFXMLParserCreate(
allocator: Option<&CFAllocator>,
xml_data: Option<&CFData>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<NonNull<CFXMLParser>>;
}
let ret = unsafe {
CFXMLParserCreate(
allocator,
xml_data,
data_source,
parse_options,
version_of_nodes,
call_backs,
context,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
#[deprecated = "renamed to `CFXMLParser::with_data_from_url`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLParserCreateWithDataFromURL(
allocator: Option<&CFAllocator>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<CFRetained<CFXMLParser>> {
extern "C-unwind" {
fn CFXMLParserCreateWithDataFromURL(
allocator: Option<&CFAllocator>,
data_source: Option<&CFURL>,
parse_options: CFOptionFlags,
version_of_nodes: CFIndex,
call_backs: *mut CFXMLParserCallBacks,
context: *mut CFXMLParserContext,
) -> Option<NonNull<CFXMLParser>>;
}
let ret = unsafe {
CFXMLParserCreateWithDataFromURL(
allocator,
data_source,
parse_options,
version_of_nodes,
call_backs,
context,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLParser::context`"]
pub fn CFXMLParserGetContext(parser: &CFXMLParser, context: *mut CFXMLParserContext);
}
extern "C-unwind" {
#[cfg(all(feature = "CFData", feature = "CFURL", feature = "CFXMLNode"))]
#[deprecated = "renamed to `CFXMLParser::call_backs`"]
pub fn CFXMLParserGetCallBacks(parser: &CFXMLParser, call_backs: *mut CFXMLParserCallBacks);
}
#[cfg(feature = "CFURL")]
#[deprecated = "renamed to `CFXMLParser::source_url`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLParserGetSourceURL(
parser: &CFXMLParser,
) -> Option<CFRetained<CFURL>> {
extern "C-unwind" {
fn CFXMLParserGetSourceURL(parser: &CFXMLParser) -> Option<NonNull<CFURL>>;
}
let ret = unsafe { CFXMLParserGetSourceURL(parser) };
ret.map(|ret| unsafe { CFRetained::retain(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLParser::location`"]
pub fn CFXMLParserGetLocation(parser: &CFXMLParser) -> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLParser::line_number`"]
pub fn CFXMLParserGetLineNumber(parser: &CFXMLParser) -> CFIndex;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLParser::document`"]
pub fn CFXMLParserGetDocument(parser: &CFXMLParser) -> *mut c_void;
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLParser::status_code`"]
pub fn CFXMLParserGetStatusCode(parser: &CFXMLParser) -> CFXMLParserStatusCode;
}
#[deprecated = "renamed to `CFXMLParser::error_description`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLParserCopyErrorDescription(
parser: &CFXMLParser,
) -> Option<CFRetained<CFString>> {
extern "C-unwind" {
fn CFXMLParserCopyErrorDescription(parser: &CFXMLParser) -> Option<NonNull<CFString>>;
}
let ret = unsafe { CFXMLParserCopyErrorDescription(parser) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `CFXMLParser::abort`"]
pub fn CFXMLParserAbort(
parser: &CFXMLParser,
error_code: CFXMLParserStatusCode,
error_description: Option<&CFString>,
);
}
#[deprecated = "renamed to `CFXMLParser::parse`"]
#[inline]
pub unsafe extern "C-unwind" fn CFXMLParserParse(parser: &CFXMLParser) -> bool {
extern "C-unwind" {
fn CFXMLParserParse(parser: &CFXMLParser) -> Boolean;
}
let ret = unsafe { CFXMLParserParse(parser) };
ret != 0
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,388 @@
#[cfg(feature = "objc2")]
use objc2::encode::{Encode, Encoding, RefEncode};
use crate::{CGAffineTransform, CGVector};
#[cfg(target_pointer_width = "64")]
type InnerFloat = f64;
#[cfg(not(target_pointer_width = "64"))]
type InnerFloat = f32;
/// The basic type for all floating-point values.
///
/// This is [`f32`] on 32-bit platforms and [`f64`] on 64-bit platforms.
///
/// See [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgfloat?language=objc).
// Defined in CoreGraphics/CGBase.h and CoreFoundation/CFCGTypes.h
// TODO: Use a newtype here?
pub type CGFloat = InnerFloat;
// NSGeometry types are aliases to CGGeometry types on iOS, tvOS, watchOS and
// macOS 64bit (and hence their Objective-C encodings are different).
//
// TODO: Adjust `objc2-encode` so that this is handled there, and so that we
// can effectively forget about it and use `NS` and `CG` types equally.
#[cfg(not(any(
not(target_vendor = "apple"),
all(target_os = "macos", target_pointer_width = "32")
)))]
#[cfg(feature = "objc2")]
mod names {
pub(super) const POINT: &str = "CGPoint";
pub(super) const SIZE: &str = "CGSize";
pub(super) const RECT: &str = "CGRect";
}
#[cfg(any(
not(target_vendor = "apple"),
all(target_os = "macos", target_pointer_width = "32")
))]
#[cfg(feature = "objc2")]
mod names {
pub(super) const POINT: &str = "_NSPoint";
pub(super) const SIZE: &str = "_NSSize";
pub(super) const RECT: &str = "_NSRect";
}
/// A point in a two-dimensional coordinate system.
///
/// See [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgpoint?language=objc).
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct CGPoint {
/// The x-coordinate of the point.
pub x: CGFloat,
/// The y-coordinate of the point.
pub y: CGFloat,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CGPoint {
const ENCODING: Encoding =
Encoding::Struct(names::POINT, &[CGFloat::ENCODING, CGFloat::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGPoint {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CGPoint {
/// Create a new point with the given coordinates.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::CGPoint;
/// assert_eq!(CGPoint::new(10.0, -2.3), CGPoint { x: 10.0, y: -2.3 });
/// ```
#[inline]
#[doc(alias = "NSMakePoint")]
#[doc(alias = "CGPointMake")]
pub const fn new(x: CGFloat, y: CGFloat) -> Self {
Self { x, y }
}
/// A point with both coordinates set to `0.0`.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::CGPoint;
/// assert_eq!(CGPoint::ZERO, CGPoint { x: 0.0, y: 0.0 });
/// ```
#[doc(alias = "NSZeroPoint")]
#[doc(alias = "CGPointZero")]
#[doc(alias = "ORIGIN")]
pub const ZERO: Self = Self::new(0.0, 0.0);
}
/// A two-dimensional size.
///
/// As this is sometimes used to represent a distance vector, rather than a
/// physical size, the width and height are _not_ guaranteed to be
/// non-negative! Methods that expect that must use one of [`CGSize::abs`] or
/// [`CGRect::standardize`].
///
/// See [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgsize?language=objc).
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct CGSize {
/// The dimensions along the x-axis.
pub width: CGFloat,
/// The dimensions along the y-axis.
pub height: CGFloat,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CGSize {
const ENCODING: Encoding =
Encoding::Struct(names::SIZE, &[CGFloat::ENCODING, CGFloat::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGSize {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CGSize {
/// Create a new size with the given dimensions.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::CGSize;
/// let size = CGSize::new(10.0, 2.3);
/// assert_eq!(size.width, 10.0);
/// assert_eq!(size.height, 2.3);
/// ```
///
/// Negative values are allowed (though often undesired).
///
/// ```
/// use objc2_core_foundation::CGSize;
/// let size = CGSize::new(-1.0, 0.0);
/// assert_eq!(size.width, -1.0);
/// ```
#[inline]
#[doc(alias = "NSMakeSize")]
#[doc(alias = "CGSizeMake")]
pub const fn new(width: CGFloat, height: CGFloat) -> Self {
// The documentation for NSSize explicitly says:
// > If the value of width or height is negative, however, the
// > behavior of some methods may be undefined.
//
// But since this type can come from FFI, we'll leave it up to the
// user to ensure that it is used safely.
Self { width, height }
}
/// Convert the size to a non-negative size.
///
/// This can be used to convert the size to a safe value.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::CGSize;
/// assert_eq!(CGSize::new(-1.0, 1.0).abs(), CGSize::new(1.0, 1.0));
/// ```
#[inline]
#[cfg(feature = "std")] // Only available in core since Rust 1.85
pub fn abs(self) -> Self {
Self::new(self.width.abs(), self.height.abs())
}
/// A size that is 0.0 in both dimensions.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::CGSize;
/// assert_eq!(CGSize::ZERO, CGSize { width: 0.0, height: 0.0 });
/// ```
#[doc(alias = "NSZeroSize")]
#[doc(alias = "CGSizeZero")]
pub const ZERO: Self = Self::new(0.0, 0.0);
}
/// The location and dimensions of a rectangle.
///
/// In the default Core Graphics coordinate space (macOS), the origin is
/// located in the lower-left corner of the rectangle and the rectangle
/// extends towards the upper-right corner.
///
/// If the context has a flipped coordinate space (iOS, tvOS, watchOS) the
/// origin is in the upper-left corner and the rectangle extends towards the
/// lower-right corner.
///
/// See [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cgrect?language=objc).
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct CGRect {
/// The coordinates of the rectangles origin.
pub origin: CGPoint,
/// The dimensions of the rectangle.
pub size: CGSize,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CGRect {
const ENCODING: Encoding =
Encoding::Struct(names::RECT, &[CGPoint::ENCODING, CGSize::ENCODING]);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGRect {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl CGRect {
/// Create a new rectangle with the given origin and dimensions.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::{CGPoint, CGRect, CGSize};
/// let origin = CGPoint::new(10.0, -2.3);
/// let size = CGSize::new(5.0, 0.0);
/// let rect = CGRect::new(origin, size);
/// ```
#[inline]
#[doc(alias = "NSMakeRect")]
#[doc(alias = "CGRectMake")]
pub const fn new(origin: CGPoint, size: CGSize) -> Self {
Self { origin, size }
}
/// A rectangle with origin (0.0, 0.0) and zero width and height.
#[doc(alias = "NSZeroRect")]
#[doc(alias = "CGRectZero")]
pub const ZERO: Self = Self::new(CGPoint::ZERO, CGSize::ZERO);
/// Returns a rectangle with a positive width and height.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::{CGPoint, CGRect, CGSize};
/// let origin = CGPoint::new(1.0, 1.0);
/// let size = CGSize::new(-5.0, -2.0);
/// let rect = CGRect::new(origin, size);
/// assert_eq!(rect.standardize().size, CGSize::new(5.0, 2.0));
/// ```
#[inline]
#[doc(alias = "CGRectStandardize")]
#[cfg(feature = "std")] // `abs` only available in core since Rust 1.85
pub fn standardize(self) -> Self {
Self::new(self.origin, self.size.abs())
}
/// The smallest coordinate of the rectangle.
#[inline]
#[doc(alias = "CGRectGetMinX")]
#[doc(alias = "CGRectGetMinY")]
#[doc(alias = "NSMinX")]
#[doc(alias = "NSMinY")]
pub fn min(self) -> CGPoint {
self.origin
}
/// The center point of the rectangle.
#[inline]
#[doc(alias = "CGRectGetMidX")]
#[doc(alias = "CGRectGetMidY")]
#[doc(alias = "NSMidX")]
#[doc(alias = "NSMidY")]
pub fn mid(self) -> CGPoint {
CGPoint::new(
self.origin.x + (self.size.width * 0.5),
self.origin.y + (self.size.height * 0.5),
)
}
/// The largest coordinate of the rectangle.
#[inline]
#[doc(alias = "CGRectGetMaxX")]
#[doc(alias = "CGRectGetMaxY")]
#[doc(alias = "NSMaxX")]
#[doc(alias = "NSMaxY")]
pub fn max(self) -> CGPoint {
CGPoint::new(
self.origin.x + self.size.width,
self.origin.y + self.size.height,
)
}
/// Returns whether a rectangle has zero width or height.
///
///
/// # Examples
///
/// ```
/// use objc2_core_foundation::{CGPoint, CGRect, CGSize};
/// assert!(CGRect::ZERO.is_empty());
/// let point = CGPoint::new(1.0, 2.0);
/// assert!(CGRect::new(point, CGSize::ZERO).is_empty());
/// assert!(!CGRect::new(point, CGSize::new(1.0, 1.0)).is_empty());
/// ```
#[inline]
#[doc(alias = "CGRectIsEmpty")]
pub fn is_empty(self) -> bool {
!(self.size.width > 0.0 && self.size.height > 0.0)
// TODO: NaN handling?
// self.size.width <= 0.0 || self.size.height <= 0.0
}
// TODO: NSContainsRect / CGRectContainsRect
// TODO: NSDivideRect / CGRectDivide
// TODO: NSInsetRect / CGRectInset
// TODO: NSIntegralRect / CGRectIntegral
// TODO: NSIntersectionRect / CGRectIntersection
// TODO: NSUnionRect / CGRectUnion
// TODO: NSIntersectsRect / CGRectIntersectsRect
// TODO: NSMouseInRect
// TODO: NSMouseInRect
// TODO: NSPointInRect / CGRectContainsPoint
// TODO: NSOffsetRect / CGRectOffset
// TODO: CGRectIsNull
// TODO: CGRectIsInfinite
// TODO: CGRectInfinite
// TODO: CGRectNull
// TODO: NSHeight / CGRectGetHeight (standardized)
// TODO: NSWidth / CGRectGetWidth (standardized)
}
// TODO: Derive this
impl Default for CGVector {
fn default() -> Self {
Self { dx: 0.0, dy: 0.0 }
}
}
impl CGVector {
#[inline]
#[doc(alias = "CGVectorMake")]
pub const fn new(dx: CGFloat, dy: CGFloat) -> Self {
Self { dx, dy }
}
}
// TODO: Derive this
impl Default for CGAffineTransform {
fn default() -> Self {
Self {
a: 0.0,
b: 0.0,
c: 0.0,
d: 0.0,
tx: 0.0,
ty: 0.0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cgsize_new() {
CGSize::new(1.0, 1.0);
CGSize::new(0.0, -0.0);
CGSize::new(-0.0, 0.0);
CGSize::new(-0.0, -0.0);
CGSize::new(-1.0, -1.0);
CGSize::new(-1.0, 1.0);
CGSize::new(1.0, -1.0);
}
}

100
vendor/objc2-core-foundation/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,100 @@
//! # Bindings to the `CoreFoundation` framework
//!
//! See [Apple's docs][apple-doc] and [the general docs on framework crates][framework-crates] for more information.
//!
//! [apple-doc]: https://developer.apple.com/documentation/corefoundation/
//! [framework-crates]: https://docs.rs/objc2/latest/objc2/topics/about_generated/index.html
//!
//! ## Examples
//!
//! ```ignore
#![doc = include_str!("../examples/run_loop.rs")]
//! ```
#![no_std]
#![cfg_attr(feature = "unstable-coerce-pointee", feature(derive_coerce_pointee))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
// Update in Cargo.toml as well.
#![doc(html_root_url = "https://docs.rs/objc2-core-foundation/0.3.1")]
#[cfg(any(test, feature = "alloc"))]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
#[doc(hidden)]
pub mod __cf_macro_helpers;
#[cfg(feature = "CFArray")]
mod array;
mod base;
#[cfg(feature = "CFBundle")]
mod bundle;
mod cf_type;
#[cfg(feature = "CFData")]
mod data;
#[cfg(feature = "CFDate")]
mod date;
#[cfg(feature = "CFDictionary")]
mod dictionary;
#[cfg(feature = "CFError")]
mod error;
#[cfg(feature = "CFFileDescriptor")]
mod filedescriptor;
// Allow `default` methods on CFAllocator and CFTimeZone
#[allow(clippy::should_implement_trait)]
mod generated;
#[cfg(feature = "CFCGTypes")]
mod geometry;
#[cfg(feature = "CFNumber")]
mod number;
mod opaque;
mod retained;
#[cfg(feature = "CFString")]
mod string;
mod thread_safety;
#[cfg(feature = "CFTimeZone")]
mod timezone;
mod type_traits;
#[cfg(feature = "CFURL")]
mod url;
#[cfg(feature = "CFUserNotification")]
mod user_notification;
#[cfg(feature = "CFUUID")]
mod uuid;
#[cfg(feature = "CFArray")]
pub use self::array::*;
pub use self::base::*;
#[cfg(feature = "CFBundle")]
pub use self::bundle::CFBundleRefNum;
#[allow(unused_imports, unreachable_pub)]
pub use self::generated::*;
#[cfg(feature = "CFCGTypes")]
pub use self::geometry::*;
pub use self::retained::CFRetained;
pub use self::type_traits::{ConcreteType, Type};
// This is not exposed publicly, so the only way to use this in types with
// generics is to use it through the default type (e.g. the user should write
// `CFArray` instead of `CFArray<Opaque>`).
#[allow(unused_imports)]
pub(crate) use self::opaque::Opaque;
// MacTypes.h
#[allow(dead_code)]
mod mac_types {
pub(crate) type Boolean = u8; // unsigned char
pub(crate) type ConstStr255Param = *const core::ffi::c_char;
pub(crate) type ConstStringPtr = *const core::ffi::c_char;
pub(crate) type FourCharCode = u32;
pub(crate) type LangCode = i16;
pub(crate) type OSType = FourCharCode;
pub(crate) type RegionCode = i16;
pub(crate) type ResType = FourCharCode;
pub(crate) type StringPtr = *mut core::ffi::c_char;
pub(crate) type UniChar = u16;
pub(crate) type UTF32Char = u32; // Or maybe Rust's char?
}
#[allow(unused_imports)]
pub(crate) use self::mac_types::*;

View File

@@ -0,0 +1,161 @@
use core::cmp::Ordering;
use core::ptr;
use crate::{kCFBooleanFalse, kCFBooleanTrue, CFBoolean, CFNumber, CFNumberType, CFRetained};
impl CFBoolean {
pub fn new(value: bool) -> &'static CFBoolean {
if value {
unsafe { kCFBooleanTrue }.unwrap()
} else {
unsafe { kCFBooleanFalse }.unwrap()
}
}
pub fn as_bool(&self) -> bool {
self.value()
}
}
macro_rules! def_new_fn {
{$(
$(#[$($m:meta)*])*
($fn_name:ident($fn_inp:ty); $type:ident),
)*} => {$(
$(#[$($m)*])*
#[inline]
pub fn $fn_name(val: $fn_inp) -> CFRetained<Self> {
let ptr: *const $fn_inp = &val;
unsafe { Self::new(None, CFNumberType::$type, ptr.cast()).expect("failed creating CFNumber") }
}
)*}
}
impl CFNumber {
def_new_fn! {
(new_i8(i8); SInt8Type),
(new_i16(i16); SInt16Type),
(new_i32(i32); SInt32Type),
(new_i64(i64); SInt64Type),
(new_isize(isize); NSIntegerType),
(new_f32(f32); Float32Type),
(new_f64(f64); Float64Type),
}
#[cfg(feature = "CFCGTypes")]
#[inline]
pub fn new_cgfloat(val: crate::CGFloat) -> CFRetained<Self> {
#[cfg(not(target_pointer_width = "64"))]
{
Self::new_f32(val)
}
#[cfg(target_pointer_width = "64")]
{
Self::new_f64(val)
}
}
}
macro_rules! def_get_fn {
{$(
$(#[$($m:meta)*])*
($fn_name:ident -> $fn_ret:ty; $type:ident),
)*} => {$(
$(#[$($m)*])*
#[inline]
pub fn $fn_name(&self) -> Option<$fn_ret> {
let mut value: $fn_ret = <$fn_ret>::default();
let ptr: *mut $fn_ret = &mut value;
let ret = unsafe { self.value(CFNumberType::$type, ptr.cast()) };
if ret {
Some(value)
} else {
None
}
}
)*}
}
impl CFNumber {
def_get_fn! {
(as_i8 -> i8; SInt8Type),
(as_i16 -> i16; SInt16Type),
(as_i32 -> i32; SInt32Type),
(as_i64 -> i64; SInt64Type),
(as_isize -> isize; NSIntegerType),
(as_f32 -> f32; Float32Type),
(as_f64 -> f64; Float64Type),
}
#[cfg(feature = "CFCGTypes")]
#[inline]
pub fn as_cgfloat(&self) -> Option<crate::CGFloat> {
#[cfg(not(target_pointer_width = "64"))]
{
self.as_f32()
}
#[cfg(target_pointer_width = "64")]
{
self.as_f64()
}
}
}
impl PartialOrd for CFNumber {
#[inline]
#[doc(alias = "CFNumberCompare")]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for CFNumber {
#[inline]
#[doc(alias = "CFNumberCompare")]
fn cmp(&self, other: &Self) -> Ordering {
// Documented that one should pass NULL here.
let context = ptr::null_mut();
unsafe { self.compare(Some(other), context) }.into()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn to_from_bool() {
let cffalse = CFBoolean::new(false);
let cftrue = CFBoolean::new(true);
assert_ne!(cffalse, cftrue);
assert_eq!(cftrue, CFBoolean::new(true));
assert_eq!(cffalse, CFBoolean::new(false));
assert!(!cffalse.as_bool());
assert!(cftrue.as_bool());
}
#[test]
fn to_from_number() {
let n = CFNumber::new_i32(442);
if cfg!(all(target_os = "macos", target_arch = "x86")) {
// Seems to return `None` in the old runtime.
assert_eq!(n.as_i8(), None);
} else {
assert_eq!(n.as_i8(), Some(442i32 as i8));
}
assert_eq!(n.as_i16(), Some(442));
assert_eq!(n.as_i32(), Some(442));
assert_eq!(n.as_i64(), Some(442));
assert_eq!(n.as_f32(), Some(442.0));
assert_eq!(n.as_f64(), Some(442.0));
}
#[test]
fn cmp_number() {
assert!(CFNumber::new_i32(2) < CFNumber::new_i32(3));
assert!(CFNumber::new_i32(3) == CFNumber::new_i32(3));
assert!(CFNumber::new_i32(4) > CFNumber::new_i32(3));
}
}

View File

@@ -0,0 +1,17 @@
use core::{
cell::UnsafeCell,
marker::{PhantomData, PhantomPinned},
};
/// An opaque type.
///
/// This is used to avoid problems with e.g. getting references from
/// `CFArray` (we can't use `c_void` as the default type, as `&c_void` would
/// be incorrect).
#[repr(C)]
#[doc(hidden)]
#[allow(dead_code, unreachable_pub)]
pub struct Opaque {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

View File

@@ -0,0 +1,435 @@
use core::ffi::c_void;
use core::fmt;
use core::marker::PhantomData;
use core::mem::ManuallyDrop;
use core::ops::Deref;
use core::panic::{RefUnwindSafe, UnwindSafe};
use core::ptr::NonNull;
use crate::{CFType, CFTypeID, ConcreteType, Type};
// Symlinked to `objc2/src/rc/retained_forwarding_impls.rs`, Cargo will make
// a copy when publishing.
mod forwarding_impls;
// Allow the `use super::Retained;` in `forwarding_impls` to work.
use CFRetained as Retained;
/// A reference counted pointer type for CoreFoundation types.
///
/// [`CFRetained`] strongly references or "retains" the given object `T`, and
/// decrements the retain count or "releases" it again when dropped, thereby
/// ensuring it will be deallocated at the right time.
///
/// The type `T` inside `CFRetained<T>` can be anything that implements
/// [`Type`], i.e. any CoreFoundation-like type.
///
///
/// # Comparison to other types
///
/// `CFRetained<T>` is equivalent to [`objc2::rc::Retained`], and can be
/// converted to/from that when the `"objc2"` feature is enabled. Note though
/// that this uses the underlying CoreFoundation primitives `CFRetain` /
/// `CFRelease` / `CFAutorelease` instead of `objc_retain` / `objc_release` /
/// `objc_autorelease`, to avoid depending on the Objective-C runtime if not
/// needed.
///
/// You can also view `CFRetained<T>` as the CoreFoundation equivalent of
/// [`std::sync::Arc`], that is, it is a thread-safe reference-counting smart
/// pointer that allows cloning by bumping the reference count.
///
/// Unlike `Arc`, objects can be retained directly from a `&T` using
/// [`Type::retain`] (for `Arc` you need `&Arc<T>`).
///
/// Weak references are not supported though without the Objective-C runtime.
///
#[cfg_attr(
not(feature = "objc2"),
doc = "[`objc2::rc::Retained`]: #objc2-not-available"
)]
///
///
/// # Forwarding implementations
///
/// Since `CFRetained<T>` is a smart pointer, it [`Deref`]s to `T`.
///
/// It also forwards the implementation of a bunch of standard library traits
/// such as [`PartialEq`], [`AsRef`], and so on, so that it becomes possible
/// to use e.g. `CFRetained<CFString>` as-if it was `CFString`. Note that
/// having a `CFString` directly is not possible since CoreFoundation objects
/// cannot live on the stack, but instead must reside on the heap, and as such
/// must be accessed behind a pointer or a reference (i.e. `&CFString`).
///
///
/// # Memory layout
///
/// This is guaranteed to have the same size and alignment as a pointer to the
/// object, `*const T`.
///
/// Additionally, it participates in the null-pointer optimization, that is,
/// `Option<CFRetained<T>>` is guaranteed to have the same size as
/// `CFRetained<T>`.
#[repr(transparent)]
#[doc(alias = "id")]
#[doc(alias = "Retained")]
#[doc(alias = "objc2::rc::Retained")]
#[cfg_attr(
feature = "unstable-coerce-pointee",
derive(std::marker::CoercePointee)
)]
// TODO: Add `ptr::Thin` bound on `T` to allow for only extern types
pub struct CFRetained<T: ?Sized> {
/// A pointer to the contained type. The pointer is always retained.
///
/// It is important that this is `NonNull`, since we want to dereference
/// it later, and be able to use the null-pointer optimization.
ptr: NonNull<T>,
/// Necessary for dropck even though we never actually run T's destructor,
/// because it might have a `dealloc` that assumes that contained
/// references outlive the type.
///
/// See <https://doc.rust-lang.org/nightly/nomicon/phantom-data.html>
item: PhantomData<T>,
/// Marks the type as !UnwindSafe. Later on we'll re-enable this.
///
/// See <https://github.com/rust-lang/rust/issues/93367> for why this is
/// required.
notunwindsafe: PhantomData<&'static mut ()>,
}
impl<T: ?Sized + Type> CFRetained<T> {
/// Construct a `CFRetained` from a pointer that already has +1 retain
/// count.
///
/// This is useful when you have been given a pointer to a type from some
/// API that [returns a retained pointer][c-retain] (i.e. follows
/// [the Create rule]).
///
/// [c-retain]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#auditing-of-c-retainable-pointer-interfaces
/// [the Create rule]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029
///
///
/// # Safety
///
/// You must uphold the same requirements as described in
/// [`CFRetained::retain`].
///
/// Additionally, you must ensure the given object pointer has +1 retain
/// count.
#[inline]
pub unsafe fn from_raw(ptr: NonNull<T>) -> Self {
Self {
ptr,
item: PhantomData,
notunwindsafe: PhantomData,
}
}
/// Consumes the `CFRetained`, returning a raw pointer with +1 retain
/// count.
///
/// After calling this function, the caller is responsible for the memory
/// previously managed by the `CFRetained`.
///
/// This is effectively the opposite of [`CFRetained::from_raw`], see that
/// for more details on when this function is useful.
///
/// This is an associated method, and must be called as
/// `CFRetained::into_raw(obj)`.
#[inline]
pub fn into_raw(this: Self) -> NonNull<T> {
ManuallyDrop::new(this).ptr
}
/// Returns a raw pointer to the type.
///
/// The pointer is valid for at least as long as the `CFRetained` is held.
///
/// This is an associated method, and must be called as
/// `CFRetained::as_ptr(&obj)`.
#[inline]
pub fn as_ptr(this: &Self) -> NonNull<T> {
this.ptr
}
/// Unchecked conversion to another CoreFoundation type.
///
/// This is equivalent to an `unsafe` `cast` between two pointers, see
/// [`CFRetained::downcast`] for a safe alternative.
///
/// This is an associated method, and must be called as
/// `CFRetained::cast_unchecked(obj)`.
///
///
/// # Safety
///
/// You must ensure that the type can be reinterpreted as the given type.
///
/// If `T` is not `'static`, you must ensure that `U` ensures that the
/// data contained by `T` is kept alive for as long as `U` lives.
///
/// Additionally, you must ensure that any safety invariants that the new
/// type has are upheld.
#[inline]
// TODO: Add ?Sized bound
pub unsafe fn cast_unchecked<U: Type>(this: Self) -> CFRetained<U> {
let ptr = ManuallyDrop::new(this).ptr.cast();
// SAFETY: The type is forgotten, so we have +1 retain count.
//
// Caller verifies that the returned type is of the correct type.
unsafe { CFRetained::from_raw(ptr) }
}
}
// TODO: Add ?Sized bound
impl<T: Type> CFRetained<T> {
/// Attempt to downcast the type to that of type `U`.
///
/// This is the owned variant. Use [`CFType::downcast_ref`] if you want to
/// convert a reference type. See also [`ConcreteType`] for more details
/// on which types support being converted to.
///
/// See [`CFType::downcast_ref`] for more details.
///
/// [`CFType::downcast_ref`]: crate::CFType::downcast_ref
///
/// # Errors
///
/// If casting failed, this will return the original back as the [`Err`]
/// variant. If you do not care about this, and just want an [`Option`],
/// use `.downcast().ok()`.
//
// NOTE: This is _not_ an associated method, since we want it to be easy
// to call, and it does not conflict with `CFType::downcast_ref`.
#[doc(alias = "CFGetTypeID")]
pub fn downcast<U: ConcreteType>(self) -> Result<CFRetained<U>, Self>
where
T: 'static,
{
extern "C-unwind" {
// `*const c_void` and `Option<&CFType>` are ABI compatible.
#[allow(clashing_extern_declarations)]
fn CFGetTypeID(cf: *const c_void) -> CFTypeID;
}
let ptr: *const c_void = self.ptr.as_ptr().cast();
// SAFETY: The pointer is valid.
if unsafe { CFGetTypeID(ptr) } == U::type_id() {
// SAFETY: Just checked that the object is a class of type `U`,
// and `T` is `'static`. Additionally, `ConcreteType::type_id` is
// guaranteed to uniquely identify the class (including ruling out
// mutable subclasses), so we know for _sure_ that the class is
// actually of that type here.
Ok(unsafe { Self::cast_unchecked::<U>(self) })
} else {
Err(self)
}
}
/// Retain the pointer and construct a [`CFRetained`] from it.
///
/// This is useful when you have been given a pointer to a type from some
/// API that [returns a non-retained reference][c-retain] (i.e. follows
/// [the Get rule]).
///
/// See also [`Type::retain`] for a safe alternative when you already have
/// a reference to the type.
///
/// [c-retain]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#auditing-of-c-retainable-pointer-interfaces
/// [the Get rule]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-SW1
///
///
/// # Safety
///
/// The pointer must be valid as a reference (aligned, dereferenceable and
/// initialized, see the [`std::ptr`] module for more information).
///
/// You must ensure that if `T` is non-`'static` (i.e. has a lifetime
/// parameter), that any data that `T` may reference lives for at least as
/// long as the return value.
///
/// [`std::ptr`]: core::ptr
#[doc(alias = "CFRetain")]
#[inline]
pub unsafe fn retain(ptr: NonNull<T>) -> Self {
extern "C-unwind" {
fn CFRetain(cf: *mut c_void) -> *mut c_void;
}
// SAFETY: The caller upholds that the pointer is valid.
//
// Note that `CFRetain` will abort if given a NULL pointer, but we
// avoid that here by ensuring that the pointer is non-NULL.
let res: *mut T = unsafe { CFRetain(ptr.as_ptr().cast()) }.cast();
// SAFETY: The pointer returned from `CFRetain` is the same as the one
// given, and we gave it a non-NULL pointer.
let res = unsafe { NonNull::new_unchecked(res) };
// SAFETY: We just retained the type, so it has +1 retain count.
//
// The pointer returned from `CFRetain` is the same as the one given,
// and the validity of it is upheld by the caller.
unsafe { Self::from_raw(res) }
}
/// Autoreleases the `CFRetained`, returning a pointer.
///
/// The object is not immediately released, but will be when the innermost
/// / current autorelease pool is drained.
///
/// This is an associated method, and must be called as
/// `CFRetained::autorelease_ptr(obj)`.
///
/// # Safety
///
/// This method is safe to call, but the returned pointer is only
/// guaranteed to be valid until the innermost autorelease pool is
/// drained.
#[doc(alias = "CFAutorelease")]
#[must_use = "if you don't intend to use the object any more, drop it as usual instead"]
#[inline]
pub fn autorelease_ptr(this: Self) -> *mut T {
extern "C-unwind" {
fn CFAutorelease(cf: *mut c_void) -> *mut c_void;
}
let ptr = Self::into_raw(this);
// SAFETY: The `ptr` is valid and has +1 retain count.
unsafe { CFAutorelease(ptr.as_ptr().cast()) }.cast()
}
}
// TODO: Add ?Sized bound
impl<T: Type> Clone for CFRetained<T> {
/// Retain the type, increasing its reference count.
///
/// This calls [`Type::retain`] internally.
#[doc(alias = "CFRetain")]
#[doc(alias = "retain")]
#[inline]
fn clone(&self) -> Self {
self.retain()
}
}
// Same as `objc::rc::Retained`, `#[may_dangle]` does not apply here.
impl<T: ?Sized> Drop for CFRetained<T> {
/// Releases the contained type.
#[doc(alias = "CFRelease")]
#[doc(alias = "release")]
#[inline]
fn drop(&mut self) {
extern "C-unwind" {
fn CFRelease(cf: *mut c_void);
}
// SAFETY: The `ptr` is guaranteed to be valid, and have at least one
// retain count.
//
// Note that `CFRelease` will abort if given a NULL pointer, but we
// avoid that here by ensuring that the pointer is non-NULL.
unsafe { CFRelease(self.ptr.as_ptr().cast()) };
}
}
impl<T: ?Sized> Deref for CFRetained<T> {
type Target = T;
/// Obtain a reference to the type.
// Box doesn't inline, but that's because it's a compiler built-in
#[inline]
fn deref(&self) -> &T {
// SAFETY: The pointer's validity is verified when the type is
// created.
unsafe { self.ptr.as_ref() }
}
}
impl<T: ?Sized> fmt::Pointer for CFRetained<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Pointer::fmt(&self.ptr.as_ptr(), f)
}
}
// Same as what's implemented for `objc2::rc::Retained`.
impl<T: ?Sized + AsRef<U>, U: Type> From<&T> for CFRetained<U> {
/// Cast the type to a superclass or `CFType`, and retain it.
#[inline]
fn from(obj: &T) -> Self {
obj.as_ref().retain()
}
}
// Use `ConcreteType` to avoid the reflexive impl (as CFType does not implement that).
impl<T: ?Sized + ConcreteType + 'static> From<CFRetained<T>> for CFRetained<CFType> {
/// Convert to [`CFType`].
#[inline]
fn from(obj: CFRetained<T>) -> Self {
// SAFETY: All `'static` types can be converted to `CFType` without
// loss of information.
unsafe { CFRetained::cast_unchecked(obj) }
}
}
#[cfg(feature = "objc2")]
impl<T: ?Sized + Type + objc2::Message> From<objc2::rc::Retained<T>> for CFRetained<T> {
/// Convert a [`objc2::rc::Retained`] into a [`CFRetained`].
///
/// This only works if the type is a CoreFoundation type (implements the
/// [`Type`] trait).
///
/// This conversion is cost-free.
#[inline]
fn from(obj: objc2::rc::Retained<T>) -> Self {
let ptr = objc2::rc::Retained::into_raw(obj);
let ptr = NonNull::new(ptr).unwrap();
// SAFETY: `T` is bound by `Type`, so we know that the type is a
// CoreFoundation-like type, and hence we know that it will respond to
// `CFRetain`/`CFRelease`.
//
// Additionally, the pointer is valid and has +1 retain count, since
// we're passing it from `Retained::into_raw`.
unsafe { Self::from_raw(ptr) }
}
}
#[cfg(feature = "objc2")]
impl<T: ?Sized + objc2::Message> From<CFRetained<T>> for objc2::rc::Retained<T> {
/// Convert a [`CFRetained`] into a [`objc2::rc::Retained`].
///
/// This conversion is cost-free, since CoreFoundation types are fully
/// interoperable with Objective-C retain/release message sending.
#[inline]
fn from(obj: CFRetained<T>) -> Self {
let ptr = ManuallyDrop::new(obj).ptr;
// SAFETY: `T` is bound by `Message`, so we know that the type is an
// Objective-C object, and hence we know that it will respond to
// `objc_retain`, `objc_release` etc.
//
// Additionally, the pointer is valid and has +1 retain count, since
// we're passing it from `CFRetained::into_raw`.
unsafe { Self::from_raw(ptr.as_ptr()) }.unwrap()
}
}
/// `CFRetained<T>` is `Send` if `T` is `Send + Sync`.
//
// SAFETY: CFRetain/CFRelease is thread safe, rest is the same as
// `std::sync::Arc` and `objc2::rc::Retained`.
unsafe impl<T: ?Sized + Sync + Send> Send for CFRetained<T> {}
/// `CFRetained<T>` is `Sync` if `T` is `Send + Sync`.
//
// SAFETY: CFRetain/CFRelease is thread safe, rest is the same as
// `std::sync::Arc` and `objc2::rc::Retained`.
unsafe impl<T: ?Sized + Sync + Send> Sync for CFRetained<T> {}
// Same as `std::sync::Arc` and `objc2::rc::Retained`.
impl<T: ?Sized> Unpin for CFRetained<T> {}
// Same as `std::sync::Arc` and `objc2::rc::Retained`.
impl<T: ?Sized + RefUnwindSafe> RefUnwindSafe for CFRetained<T> {}
// Same as `std::sync::Arc` and `objc2::rc::Retained`.
impl<T: ?Sized + RefUnwindSafe> UnwindSafe for CFRetained<T> {}

View File

@@ -0,0 +1,425 @@
//! Trivial forwarding impls on `Retained`-like types.
//!
//! Kept here to keep `retained.rs` free from this boilerplate, and to allow
//! re-use in `objc2-core-foundation` and `dispatch2` (this file is symlinked
//! there as well).
#![forbid(unsafe_code)]
use core::borrow::Borrow;
use core::cmp::Ordering;
use core::fmt;
use core::future::Future;
use core::hash;
use core::pin::Pin;
use core::task::{Context, Poll};
#[cfg(feature = "std")] // TODO: Use core::error::Error once 1.81 is in MSRV
use std::error::Error;
#[cfg(feature = "std")]
use std::io;
use super::Retained;
impl<T: ?Sized + PartialEq<U>, U: ?Sized> PartialEq<Retained<U>> for Retained<T> {
#[inline]
fn eq(&self, other: &Retained<U>) -> bool {
(**self).eq(&**other)
}
#[inline]
#[allow(clippy::partialeq_ne_impl)]
fn ne(&self, other: &Retained<U>) -> bool {
(**self).ne(&**other)
}
}
impl<T: Eq + ?Sized> Eq for Retained<T> {}
impl<T: ?Sized + PartialOrd<U>, U: ?Sized> PartialOrd<Retained<U>> for Retained<T> {
#[inline]
fn partial_cmp(&self, other: &Retained<U>) -> Option<Ordering> {
(**self).partial_cmp(&**other)
}
#[inline]
fn lt(&self, other: &Retained<U>) -> bool {
(**self).lt(&**other)
}
#[inline]
fn le(&self, other: &Retained<U>) -> bool {
(**self).le(&**other)
}
#[inline]
fn ge(&self, other: &Retained<U>) -> bool {
(**self).ge(&**other)
}
#[inline]
fn gt(&self, other: &Retained<U>) -> bool {
(**self).gt(&**other)
}
}
impl<T: Ord + ?Sized> Ord for Retained<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
(**self).cmp(&**other)
}
}
impl<T: hash::Hash + ?Sized> hash::Hash for Retained<T> {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
(**self).hash(state);
}
}
impl<T: ?Sized> hash::Hasher for Retained<T>
where
for<'a> &'a T: hash::Hasher,
{
fn finish(&self) -> u64 {
(&**self).finish()
}
fn write(&mut self, bytes: &[u8]) {
(&**self).write(bytes);
}
fn write_u8(&mut self, i: u8) {
(&**self).write_u8(i);
}
fn write_u16(&mut self, i: u16) {
(&**self).write_u16(i);
}
fn write_u32(&mut self, i: u32) {
(&**self).write_u32(i);
}
fn write_u64(&mut self, i: u64) {
(&**self).write_u64(i);
}
fn write_u128(&mut self, i: u128) {
(&**self).write_u128(i);
}
fn write_usize(&mut self, i: usize) {
(&**self).write_usize(i);
}
fn write_i8(&mut self, i: i8) {
(&**self).write_i8(i);
}
fn write_i16(&mut self, i: i16) {
(&**self).write_i16(i);
}
fn write_i32(&mut self, i: i32) {
(&**self).write_i32(i);
}
fn write_i64(&mut self, i: i64) {
(&**self).write_i64(i);
}
fn write_i128(&mut self, i: i128) {
(&**self).write_i128(i);
}
fn write_isize(&mut self, i: isize) {
(&**self).write_isize(i);
}
}
impl<'a, T: ?Sized> hash::Hasher for &'a Retained<T>
where
&'a T: hash::Hasher,
{
fn finish(&self) -> u64 {
(&***self).finish()
}
fn write(&mut self, bytes: &[u8]) {
(&***self).write(bytes);
}
fn write_u8(&mut self, i: u8) {
(&***self).write_u8(i);
}
fn write_u16(&mut self, i: u16) {
(&***self).write_u16(i);
}
fn write_u32(&mut self, i: u32) {
(&***self).write_u32(i);
}
fn write_u64(&mut self, i: u64) {
(&***self).write_u64(i);
}
fn write_u128(&mut self, i: u128) {
(&***self).write_u128(i);
}
fn write_usize(&mut self, i: usize) {
(&***self).write_usize(i);
}
fn write_i8(&mut self, i: i8) {
(&***self).write_i8(i);
}
fn write_i16(&mut self, i: i16) {
(&***self).write_i16(i);
}
fn write_i32(&mut self, i: i32) {
(&***self).write_i32(i);
}
fn write_i64(&mut self, i: i64) {
(&***self).write_i64(i);
}
fn write_i128(&mut self, i: i128) {
(&***self).write_i128(i);
}
fn write_isize(&mut self, i: isize) {
(&***self).write_isize(i);
}
}
macro_rules! forward_fmt_impl {
($trait:path) => {
impl<T: $trait + ?Sized> $trait for Retained<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(**self).fmt(f)
}
}
};
}
forward_fmt_impl!(fmt::Binary);
forward_fmt_impl!(fmt::Debug);
forward_fmt_impl!(fmt::Display);
forward_fmt_impl!(fmt::LowerExp);
forward_fmt_impl!(fmt::LowerHex);
forward_fmt_impl!(fmt::Octal);
// forward_fmt_impl!(fmt::Pointer);
forward_fmt_impl!(fmt::UpperExp);
forward_fmt_impl!(fmt::UpperHex);
impl<'a, T: ?Sized> fmt::Write for &'a Retained<T>
where
&'a T: fmt::Write,
{
#[inline]
fn write_str(&mut self, s: &str) -> fmt::Result {
(&***self).write_str(s)
}
#[inline]
fn write_char(&mut self, c: char) -> fmt::Result {
(&***self).write_char(c)
}
#[inline]
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> fmt::Result {
(&***self).write_fmt(args)
}
}
impl<T: ?Sized> Borrow<T> for Retained<T> {
fn borrow(&self) -> &T {
// Auto-derefs
self
}
}
// Forward to inner type's `AsRef`.
//
// This is different from what `Box` does, but is desirable in our case, as it
// allows going directly to superclasses.
//
// See also discussion in:
// <https://internals.rust-lang.org/t/semantics-of-asref/17016>
impl<T: ?Sized + AsRef<U>, U: ?Sized> AsRef<U> for Retained<T> {
fn as_ref(&self) -> &U {
(**self).as_ref()
}
}
#[cfg(feature = "std")]
impl<T: ?Sized + Error> Error for Retained<T> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
(**self).source()
}
}
#[cfg(feature = "std")]
impl<T: ?Sized> io::Read for Retained<T>
where
for<'a> &'a T: io::Read,
{
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
(&**self).read(buf)
}
#[inline]
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
(&**self).read_vectored(bufs)
}
#[inline]
fn read_to_end(&mut self, buf: &mut std::vec::Vec<u8>) -> io::Result<usize> {
(&**self).read_to_end(buf)
}
#[inline]
fn read_to_string(&mut self, buf: &mut std::string::String) -> io::Result<usize> {
(&**self).read_to_string(buf)
}
#[inline]
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
(&**self).read_exact(buf)
}
}
#[cfg(feature = "std")]
impl<'a, T: ?Sized> io::Read for &'a Retained<T>
where
&'a T: io::Read,
{
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
(&***self).read(buf)
}
#[inline]
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
(&***self).read_vectored(bufs)
}
#[inline]
fn read_to_end(&mut self, buf: &mut std::vec::Vec<u8>) -> io::Result<usize> {
(&***self).read_to_end(buf)
}
#[inline]
fn read_to_string(&mut self, buf: &mut std::string::String) -> io::Result<usize> {
(&***self).read_to_string(buf)
}
#[inline]
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
(&***self).read_exact(buf)
}
}
#[cfg(feature = "std")]
impl<T: ?Sized> io::Write for Retained<T>
where
for<'a> &'a T: io::Write,
{
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&**self).write(buf)
}
#[inline]
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
(&**self).write_vectored(bufs)
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
(&**self).flush()
}
#[inline]
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
(&**self).write_all(buf)
}
#[inline]
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
(&**self).write_fmt(fmt)
}
}
#[cfg(feature = "std")]
impl<'a, T: ?Sized> io::Write for &'a Retained<T>
where
&'a T: io::Write,
{
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&***self).write(buf)
}
#[inline]
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
(&***self).write_vectored(bufs)
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
(&***self).flush()
}
#[inline]
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
(&***self).write_all(buf)
}
#[inline]
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
(&***self).write_fmt(fmt)
}
}
#[cfg(feature = "std")]
impl<T: ?Sized> io::Seek for Retained<T>
where
for<'a> &'a T: io::Seek,
{
#[inline]
fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> {
(&**self).seek(pos)
}
#[inline]
fn stream_position(&mut self) -> io::Result<u64> {
(&**self).stream_position()
}
}
#[cfg(feature = "std")]
impl<'a, T: ?Sized> io::Seek for &'a Retained<T>
where
&'a T: io::Seek,
{
#[inline]
fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> {
(&***self).seek(pos)
}
#[inline]
fn stream_position(&mut self) -> io::Result<u64> {
(&***self).stream_position()
}
}
impl<'a, T: ?Sized> Future for &'a Retained<T>
where
&'a T: Future,
{
type Output = <&'a T as Future>::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
<&T>::poll(Pin::new(&mut &***self), cx)
}
}
impl<A, T: ?Sized> Extend<A> for Retained<T>
where
for<'a> &'a T: Extend<A>,
{
#[inline]
fn extend<I: IntoIterator<Item = A>>(&mut self, iter: I) {
(&**self).extend(iter)
}
}
impl<'a, A, T: ?Sized> Extend<A> for &'a Retained<T>
where
&'a T: Extend<A>,
{
#[inline]
fn extend<I: IntoIterator<Item = A>>(&mut self, iter: I) {
(&***self).extend(iter)
}
}
// TODO: impl Fn traits, CoerceUnsized, Stream and so on when stabilized

View File

@@ -0,0 +1,380 @@
use core::cmp::Ordering;
use core::ffi::c_char;
use core::fmt::Write;
use core::ptr::NonNull;
use core::{fmt, slice, str};
use crate::{
kCFAllocatorNull, CFIndex, CFRange, CFRetained, CFString, CFStringBuiltInEncodings,
CFStringCompareFlags,
};
#[track_caller]
unsafe fn debug_checked_utf8_unchecked(bytes: &[u8]) -> &str {
if cfg!(debug_assertions) {
match str::from_utf8(bytes) {
Ok(s) => s,
Err(err) => panic!(
"unsafe precondition violated: CF function did not return valid UTF-8: {err}"
),
}
} else {
// SAFETY: Checked by caller
unsafe { str::from_utf8_unchecked(bytes) }
}
}
impl CFString {
/// Creates a new `CFString` from a [`str`][prim@str].
#[inline]
#[doc(alias = "CFStringCreateWithBytes")]
#[allow(clippy::should_implement_trait)] // Not really sure of a better name
pub fn from_str(string: &str) -> CFRetained<Self> {
// Can never happen, allocations in Rust cannot be this large.
debug_assert!(string.len() < CFIndex::MAX as usize);
let len = string.len() as CFIndex;
let s = unsafe {
Self::with_bytes(
None,
string.as_ptr(),
len,
CFStringBuiltInEncodings::EncodingUTF8.0,
false,
)
};
// Should only fail if the string is not UTF-8 (which we know it is)
// or perhaps on allocation error.
s.expect("failed creating CFString")
}
/// Alias for easier transition from the `core-foundation` crate.
#[inline]
#[deprecated = "renamed to CFString::from_str"]
pub fn new(string: &str) -> CFRetained<Self> {
Self::from_str(string)
}
/// Creates a new `CFString` from a `'static` [`str`][prim@str].
///
/// This may be slightly more efficient than [`CFString::from_str`], as it
/// may be able to re-use the existing buffer (since we know it won't be
/// deallocated).
#[inline]
#[doc(alias = "CFStringCreateWithBytesNoCopy")]
pub fn from_static_str(string: &'static str) -> CFRetained<Self> {
debug_assert!(string.len() < CFIndex::MAX as usize);
let len = string.len() as CFIndex;
// SAFETY: The string is used as a backing store, and thus must
// potentially live forever, since we don't know how long the returned
// CFString will be alive for. This is ensured by the `'static`
// requirement.
let s = unsafe {
Self::with_bytes_no_copy(
None,
string.as_ptr(),
len,
CFStringBuiltInEncodings::EncodingUTF8.0,
false,
kCFAllocatorNull,
)
};
s.expect("failed creating CFString")
}
/// Get the [`str`](`prim@str`) representation of this string if it can be
/// done efficiently.
///
/// Returns [`None`] if the internal storage does not allow this to be
/// done efficiently. Use `CFString::to_string` if performance is not an
/// issue.
///
/// # Safety
///
/// The `CFString` must not be mutated for the lifetime of the returned
/// string.
///
/// Warning: This is very difficult to ensure in generic contexts, e.g. it
/// cannot even be used inside `Debug::fmt`, since `Formatter` uses `dyn`
/// internally, and could thus mutate the string inside there.
#[doc(alias = "CFStringGetCStringPtr")]
pub unsafe fn as_str_unchecked(&self) -> Option<&str> {
// NOTE: The encoding is an 8-bit encoding.
let bytes = self.c_string_ptr(CFStringBuiltInEncodings::EncodingASCII.0);
NonNull::new(bytes as *mut c_char).map(|bytes| {
// NOTE: The returned string may contain interior NUL bytes:
// https://github.com/swiftlang/swift-corelibs-foundation/issues/5200
//
// So we have to check the length of the string too. We do that
// using `CFStringGetLength`; Since `CFStringGetCStringPtr`
// returned a pointer, and we picked the encoding to be ASCII
// (which has 1 codepoint per byte), this means that the number of
// codepoints is the same as the number of bytes in the string.
//
// This is also what Swift does:
// https://github.com/swiftlang/swift-corelibs-foundation/commit/8422c1a5e63913613a93523b3b398cb982df6205
let len = self.length() as usize;
// SAFETY: The pointer is valid for as long as the CFString is not
// mutated (which the caller ensures it isn't for the lifetime of
// the reference), and the length is correct (see above).
let bytes = unsafe { slice::from_raw_parts(bytes.as_ptr().cast(), len) };
// SAFETY: `CFStringGetCStringPtr` is (very likely) implemented
// correctly, and we picked the encoding to be ASCII (which is a
// subset of UTF-8).
unsafe { debug_checked_utf8_unchecked(bytes) }
})
}
}
impl fmt::Display for CFString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Copy UTF-8 bytes from the CFString to the formatter in a loop, to
// avoid allocating.
//
// We have to do this instead of using `CFStringGetCStringPtr`, as
// that will be invalidated if the string is mutated while in use, and
// `fmt::Formatter` contains `dyn Write` which may very theoretically
// do exactly that.
// Somewhat reasonably sized stack buffer.
// TODO: Do performance testing, and tweak this value.
//
// Should be at least 4 (as that's the minimum size of `char`).
let mut buf = [0u8; 32];
let mut location_utf16 = 0;
loop {
let len_utf16 = self.length();
let mut read_utf8 = 0;
let read_utf16 = unsafe {
self.bytes(
CFRange {
location: location_utf16,
length: len_utf16 - location_utf16,
},
CFStringBuiltInEncodings::EncodingUTF8.0,
0, // No conversion character
false,
buf.as_mut_ptr(),
buf.len() as _,
&mut read_utf8,
)
};
if read_utf16 <= 0 {
if location_utf16 < len_utf16 {
// We're not done reading the entire string yet; emit
// replacement character, advance one character, and try again.
f.write_char(char::REPLACEMENT_CHARACTER)?;
location_utf16 += 1;
continue;
}
break;
}
location_utf16 += read_utf16;
// SAFETY: `CFStringGetBytes` is (very likely) implemented
// correctly, and won't return non-UTF8 strings.
//
// Even if a string contains an UTF-8 char on a boundary, it won't
// split it up when returning UTF-8.
let s = unsafe { debug_checked_utf8_unchecked(&buf[0..read_utf8 as usize]) };
// NOTE: May unwind, and may invalidate the string contents.
f.write_str(s)?;
}
Ok(())
}
}
impl PartialOrd for CFString {
#[inline]
#[doc(alias = "CFStringCompare")]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for CFString {
#[inline]
#[doc(alias = "CFStringCompare")]
fn cmp(&self, other: &Self) -> Ordering {
// Request standard lexiographical ordering.
let flags = CFStringCompareFlags::empty();
self.compare(Some(other), flags).into()
}
}
#[cfg(test)]
mod tests {
use alloc::string::ToString;
use core::ffi::CStr;
use super::*;
#[test]
fn basic_conversion() {
let s = CFString::from_str("abc");
assert_eq!(s.to_string(), "abc");
let s = CFString::from_str("a♥😀");
assert_eq!(s.to_string(), "a♥😀");
}
#[test]
fn cstr_conversion() {
let table = [
(
b"abc\xf8xyz\0" as &[u8],
CFStringBuiltInEncodings::EncodingISOLatin1,
"abcøxyz",
),
(
b"\x26\x65\0",
CFStringBuiltInEncodings::EncodingUTF16BE,
"",
),
(
b"\x65\x26\0",
CFStringBuiltInEncodings::EncodingUTF16LE,
"",
),
];
for (cstr, encoding, expected) in table {
let cstr = CStr::from_bytes_with_nul(cstr).unwrap();
let s = unsafe { CFString::with_c_string(None, cstr.as_ptr(), encoding.0) }.unwrap();
assert_eq!(s.to_string(), expected);
}
}
#[test]
fn from_incomplete() {
let s = unsafe {
CFString::with_bytes(
None,
b"\xd8\x3d\xde".as_ptr(),
3,
CFStringBuiltInEncodings::EncodingUTF16BE.0,
false,
)
.unwrap()
};
assert_eq!(s.to_string(), "<EFBFBD>"); // Replacement character
assert_eq!(s.length(), 1);
}
#[test]
fn internal_nul_byte() {
let s = CFString::from_str("a\0b\0c\0d");
// Works with `CFStringGetBytes`.
assert_eq!(s.to_string(), "a\0b\0c\0d");
// `CFStringGetCStringPtr` does not seem to work on very short strings.
assert_eq!(unsafe { s.as_str_unchecked() }, None);
// Test `CFStringGetCString`.
let mut buf = [0u8; 10];
assert!(unsafe {
s.c_string(
buf.as_mut_ptr().cast(),
buf.len() as _,
CFStringBuiltInEncodings::EncodingUTF8.0,
)
});
// All the data is copied to the buffer.
assert_eq!(&buf[0..10], b"a\0b\0c\0d\0\0\0");
// But subsequent usage of that as a CStr fails, since it contains
// interior NUL bytes.
let cstr = CStr::from_bytes_until_nul(&buf).unwrap();
assert_eq!(cstr.to_bytes(), b"a");
// Test with a bit longer string, to ensure the same holds for heap-
// allocated CFStrings
let s = CFString::from_str("a\0aaaaaaaaaaaaaaa");
// Works with `CFStringGetBytes`.
assert_eq!(s.to_string(), "a\0aaaaaaaaaaaaaaa");
// `CFStringGetCStringPtr` also allows these without truncation.
assert_eq!(unsafe { s.as_str_unchecked() }, Some("a\0aaaaaaaaaaaaaaa"));
}
#[test]
fn as_str_correct_on_unicode() {
let s = CFString::from_static_str("😀");
assert_eq!(unsafe { s.as_str_unchecked() }, None);
let s = CFString::from_static_str("");
assert_eq!(unsafe { s.as_str_unchecked() }, None);
}
#[test]
fn utf8_on_boundary() {
// Make the emoji lie across the 32 byte buffer size in Display::fmt.
let s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀"; // 29 'a's
assert_eq!(CFString::from_str(s).to_string(), s);
let s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀"; // 30 'a's
assert_eq!(CFString::from_str(s).to_string(), s);
let s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀"; // 31 'a's
assert_eq!(CFString::from_str(s).to_string(), s);
}
#[test]
fn create_with_cstring_broken_on_non_8_bit() {
// A CFString that is supposed to contain a "♥" (the UTF-8 encoding of
// that is the vastly different b"\xE2\x99\xA5").
//
// This line is wrong, because `CFStringCreateWithCString` expects an
// 8-bit encoding.
//
// See also:
// https://github.com/swiftlang/swift-corelibs-foundation/issues/5164
let s = unsafe {
CFString::with_c_string(
None,
b"\x65\x26\0".as_ptr().cast(),
CFStringBuiltInEncodings::EncodingUnicode.0,
)
}
.unwrap();
// `CFStringGetBytes` used in `fmt::Display` converts to UTF-8.
assert_eq!(s.to_string(), "");
// So does `CFStringGetCString`.
let mut buf = [0u8; 20];
assert!(unsafe {
s.c_string(
buf.as_mut_ptr().cast(),
buf.len() as _,
CFStringBuiltInEncodings::EncodingUTF8.0,
)
});
let cstr = CStr::from_bytes_until_nul(&buf).unwrap();
assert_eq!(cstr.to_bytes(), "".as_bytes());
// `CFStringGetCStringPtr` completely ignores the requested UTF-8 conversion.
assert_eq!(unsafe { s.as_str_unchecked() }, Some("e"));
assert_eq!(
unsafe { CStr::from_ptr(s.c_string_ptr(CFStringBuiltInEncodings::EncodingUTF8.0,)) },
CStr::from_bytes_with_nul(b"e&\0").unwrap()
);
}
#[test]
fn test_static() {
let cf = CFString::from_static_str("xyz");
assert_eq!(cf.to_string(), "xyz");
}
#[test]
fn eq() {
assert_eq!(CFString::from_str("abc"), CFString::from_str("abc"));
assert_ne!(CFString::from_str("abc"), CFString::from_str("xyz"));
// Cross-type comparison
assert_ne!(
**CFString::from_str("abc"),
**unsafe { kCFAllocatorNull }.unwrap()
);
}
// TODO: Test mutation while formatting.
}

View File

@@ -0,0 +1,210 @@
//! Thread-safety.
use crate::*;
// SAFETY: CFBundle is immutable, and can be retrieved from any thread.
#[cfg(feature = "CFBundle")]
unsafe impl Send for CFBundle {}
#[cfg(feature = "CFBundle")]
unsafe impl Sync for CFBundle {}
// SAFETY: `NSNotificationCenter` and `NSDistributedNotificationCenter` are
// thread-safe, and those build upon this, so it must be thread-safe too.
//
// Additionally, they can be retrieved from any thread.
//
// NOTE: added notification observers are sent to the main thread, so the
// functions for doing that are not necessarily safe.
#[cfg(feature = "CFNotificationCenter")]
unsafe impl Send for CFNotificationCenter {}
#[cfg(feature = "CFNotificationCenter")]
unsafe impl Sync for CFNotificationCenter {}
// SAFETY: CFUUID is immutable and just stores the 16 bytes.
#[cfg(feature = "CFUUID")]
unsafe impl Send for CFUUID {}
#[cfg(feature = "CFUUID")]
unsafe impl Sync for CFUUID {}
// SAFETY: NSNumber is thread-safe, and this is toll-free bridged to that.
#[cfg(feature = "CFNumber")]
unsafe impl Send for CFBoolean {}
#[cfg(feature = "CFNumber")]
unsafe impl Sync for CFBoolean {}
#[cfg(feature = "CFNumber")]
unsafe impl Send for CFNumber {}
#[cfg(feature = "CFNumber")]
unsafe impl Sync for CFNumber {}
// SAFETY: NSDate is thread-safe, and this is toll-free bridged to that.
#[cfg(feature = "CFDate")]
unsafe impl Send for CFDate {}
#[cfg(feature = "CFDate")]
unsafe impl Sync for CFDate {}
// SAFETY: NSError is thread-safe, and this is toll-free bridged to that.
// Also, Foundation's .swiftinterface adds a `@unchecked Swift.Sendable`
// protocol conformance to CoreFoundation.CFError.
#[cfg(feature = "CFError")]
unsafe impl Send for CFError {}
#[cfg(feature = "CFError")]
unsafe impl Sync for CFError {}
// SAFETY: NSLocale is thread-safe, and this is toll-free bridged to that.
#[cfg(feature = "CFLocale")]
unsafe impl Send for CFLocale {}
#[cfg(feature = "CFLocale")]
unsafe impl Sync for CFLocale {}
// SAFETY: NSNull is thread-safe, and this is toll-free bridged to that.
unsafe impl Send for CFNull {}
unsafe impl Sync for CFNull {}
// SAFETY: NSTimeZone is thread-safe, and this is toll-free bridged to that.
#[cfg(feature = "CFDate")]
unsafe impl Send for CFTimeZone {}
#[cfg(feature = "CFDate")]
unsafe impl Sync for CFTimeZone {}
// SAFETY: NSURL is thread-safe, and this is toll-free bridged to that.
#[cfg(feature = "CFURL")]
unsafe impl Send for CFURL {}
#[cfg(feature = "CFURL")]
unsafe impl Sync for CFURL {}
#[allow(unused_macros)]
#[cfg(test)]
mod tests {
use super::*;
macro_rules! not_thread_safe {
($($ty:ty),*) => {$(
static_assertions::assert_not_impl_any!($ty: Send, Sync);
)?};
}
macro_rules! thread_safe {
($($ty:ty),*) => {$(
// General assumption: Assumes that the allocator this was created
// with is also thread-safe; that's probably a fair assumption,
// otherwise nothing in CF would be thread-safe.
static_assertions::assert_impl_all!($ty: Send, Sync);
)?};
}
#[test]
fn base() {
// CFType can hold thread-unsafe objects.
// Just like AnyObject and NSObject aren't thread-safe.
not_thread_safe!(CFType, CFPropertyList);
// Only the built-ins are thread-safe, other allocators aren't
// guaranteed to be. Usually fine though, since they're placed in
// statics anyhow, and can thus already be accessed from all threads.
not_thread_safe!(CFAllocator);
}
/// Collections, mutable types and immutable types with mutable variants
/// aren't thread-safe:
/// <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-SW9>
///
/// Note that things that are known to be the immutable variant are
/// usually thread-safe (which is why e.g. `CFString` in statics is fine).
#[test]
fn mutable_or_mutable_variant() {
#[cfg(feature = "CFBag")]
not_thread_safe!(CFBag<u32>, CFMutableBag<u32>);
#[cfg(feature = "CFBinaryHeap")]
not_thread_safe!(CFBinaryHeap);
#[cfg(feature = "CFBitVector")]
not_thread_safe!(CFBitVector, CFMutableBitVector);
#[cfg(feature = "CFDateFormatter")]
not_thread_safe!(CFDateFormatter); // Explicitly stated to not be thread-safe
#[cfg(feature = "CFFileDescriptor")]
not_thread_safe!(CFFileDescriptor);
#[cfg(feature = "CFNumberFormatter")]
not_thread_safe!(CFNumberFormatter); // Explicitly stated to not be thread-safe
#[cfg(feature = "CFSocket")]
not_thread_safe!(CFSocket);
#[cfg(feature = "CFStringTokenizer")]
not_thread_safe!(CFStringTokenizer);
#[cfg(feature = "CFTree")]
not_thread_safe!(CFTree);
#[cfg(feature = "CFURLEnumerator")]
not_thread_safe!(CFURLEnumerator);
#[cfg(feature = "CFUserNotification")]
not_thread_safe!(CFUserNotification);
// Types are not marked as thread-safe if their toll-free
// bridged type is not thread safe either.
#[cfg(feature = "CFArray")]
not_thread_safe!(CFArray<u32>, CFMutableArray<u32>);
#[cfg(feature = "CFAttributedString")]
not_thread_safe!(CFAttributedString, CFMutableAttributedString);
#[cfg(feature = "CFCalendar")]
not_thread_safe!(CFCalendar);
#[cfg(feature = "CFCharacterSet")]
not_thread_safe!(CFCharacterSet, CFMutableCharacterSet);
#[cfg(feature = "CFData")]
not_thread_safe!(CFData, CFMutableData);
#[cfg(feature = "CFDictionary")]
not_thread_safe!(CFDictionary<u32, u32>, CFMutableDictionary<u32, u32>);
#[cfg(feature = "CFFileSecurity")]
not_thread_safe!(CFFileSecurity);
#[cfg(feature = "CFMachPort")]
not_thread_safe!(CFMachPort);
#[cfg(feature = "CFMessagePort")]
not_thread_safe!(CFMessagePort);
#[cfg(feature = "CFRunLoop")]
not_thread_safe!(CFRunLoopTimer);
#[cfg(feature = "CFSet")]
not_thread_safe!(CFSet<u32>, CFMutableSet<u32>);
#[cfg(feature = "CFString")]
not_thread_safe!(CFString, CFMutableString);
#[cfg(feature = "CFStream")]
not_thread_safe!(CFReadStream, CFWriteStream);
}
/// Immutable CF types are generally thread-safe.
#[test]
fn immutable() {
#[cfg(feature = "CFBundle")]
thread_safe!(CFBundle);
#[cfg(feature = "CFNotificationCenter")]
thread_safe!(CFNotificationCenter);
#[cfg(feature = "CFUUID")]
thread_safe!(CFUUID);
// Types whose toll-free bridged type is thread-safe are also marked
// as thread-safe.
#[cfg(feature = "CFNumber")]
thread_safe!(CFBoolean, CFNumber);
#[cfg(feature = "CFDate")]
thread_safe!(CFDate);
#[cfg(feature = "CFError")]
thread_safe!(CFError);
#[cfg(feature = "CFLocale")]
thread_safe!(CFLocale);
thread_safe!(CFNull);
#[cfg(feature = "CFDate")]
thread_safe!(CFTimeZone);
#[cfg(feature = "CFURL")]
thread_safe!(CFURL);
}
#[test]
fn uncertain() {
// Uncertain, so marked as thread-unsafe for now.
#[cfg(feature = "CFBundle")]
not_thread_safe!(CFPlugIn);
#[cfg(feature = "CFPlugIn")]
not_thread_safe!(CFPlugInInstance);
// Under discussion in https://github.com/madsmtm/objc2/issues/696.
#[cfg(feature = "CFRunLoop")]
not_thread_safe!(CFRunLoop, CFRunLoopSource, CFRunLoopObserver);
}
}

View File

@@ -0,0 +1,14 @@
#![cfg(feature = "CFDate")]
#[cfg(test)]
mod tests {
use crate::CFTimeZone;
#[test]
fn cmp() {
let system = CFTimeZone::system().unwrap();
let default = CFTimeZone::default().unwrap();
assert_eq!(system, default);
assert_eq!(system.name().unwrap(), default.name().unwrap(),);
}
}

View File

@@ -0,0 +1,142 @@
use core::ptr::NonNull;
use crate::{CFRetained, CFType, CFTypeID};
/// A CoreFoundation-like type.
///
/// This trait is implemented for all CoreFoundation-like types (i.e. both
/// types in this crate like `CFString`, but also types from other frameworks
/// like `CGColor` from CoreGraphics).
///
/// This trait allows the type to be used in [`CFRetained`].
///
/// You should not need to implement this yourself.
///
///
/// # Safety
///
/// - The type must be a CoreFoundation-like type.
/// - The type must be safe to retain/release using `CFRetain` and
/// `CFRelease`.
pub unsafe trait Type {
/// Increment the reference count of the receiver.
///
/// This extends the duration in which the receiver is alive by detaching
/// it from the lifetime information carried by the reference.
///
/// This is similar to using [`Clone` on `CFRetained<Self>`][clone-id],
/// with the addition that it can be used on a plain reference.
///
/// [clone-id]: crate::CFRetained#impl-Clone-for-CFRetained<T>
#[inline]
#[doc(alias = "CFRetain")]
fn retain(&self) -> CFRetained<Self>
where
Self: Sized,
{
let ptr = NonNull::from(self);
// SAFETY: The pointer is valid, since it came from a Rust reference.
unsafe { CFRetained::retain(ptr) }
}
/// Helper for easier transition from the `core-foundation` crate.
#[deprecated = "this is redundant"]
#[inline]
#[allow(non_snake_case)]
fn as_concrete_TypeRef(&self) -> &Self {
self
}
/// Helper for easier transition from the `core-foundation` crate.
///
/// # Safety
///
/// Same as [`CFRetained::retain`].
#[deprecated = "use CFRetained::retain"]
#[inline]
unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>
where
Self: Sized,
{
let ptr = NonNull::new(ptr.cast_mut()).expect("attempted to create a NULL object");
// SAFETY: Upheld by caller.
unsafe { CFRetained::retain(ptr) }
}
/// Helper for easier transition from the `core-foundation` crate.
#[deprecated = "this is redundant (CF types deref to CFType)"]
#[inline]
#[allow(non_snake_case)]
fn as_CFTypeRef(&self) -> &CFType
where
Self: AsRef<CFType>,
{
self.as_ref()
}
/// Helper for easier transition from the `core-foundation` crate.
///
/// # Safety
///
/// Same as [`CFRetained::from_raw`].
#[deprecated = "use CFRetained::from_raw"]
#[inline]
unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>
where
Self: Sized,
{
let ptr = NonNull::new(ptr.cast_mut()).expect("attempted to create a NULL object");
// SAFETY: Upheld by caller.
unsafe { CFRetained::from_raw(ptr) }
}
}
/// A concrete CoreFoundation type.
///
/// This trait is implemented for CoreFoundation types which have a
/// `CFTypeID`, which should be most types except for mutable variants, types
/// with generics, as well as the root `CFType`.
///
///
/// # Mutable types
///
/// Some types have immutable and mutable variants, the prime example being
/// `CFString` and `CFMutableString`. Internally, these are very complex class
/// clusters, but in the simplest case they're sometimes the same type, the
/// only difference being that the mutable variant has a boolean flag set.
/// This means that they also share the same type ID, and thus we cannot
/// (stably) differentiate between them at runtime.
///
/// Therefore, this trait is only implemented for the immutable variant, to
/// prevent it from accidentally being misused (it is unclear whether it would
/// be unsound or not). If you're looking to convert to a mutable type, you'll
/// have to either construct a new one with APIs like
/// `CFStringCreateMutableCopy`, or use an unchecked cast.
///
///
/// # Generic types
///
/// Only the "base" type / the type without generics implements this.
///
/// So for example, `CFArray` implements this trait, but `CFArray<CFString>`
/// does not (as we cannot query the type of the inner element without
/// actually inspecting the element, and since `CFArray`s aren't required to
/// hold CF types).
///
///
/// # Safety
///
/// - The type must not be mutable.
/// - The type must not be generic (e.g. this can only be implemented for the
/// base `CFArray`, not for all `CFArray<T>`).
/// - The [`type_id`][Self::type_id] must be implemented correctly, and must
/// uniquely identify the type.
pub unsafe trait ConcreteType: Type {
/// Get the unique `CFTypeID` identifier for the type.
///
/// For example, this corresponds to `CFStringGetTypeID` for `CFString`
/// and `CGColorGetTypeID` for `CGColor`.
#[doc(alias = "GetTypeID")]
fn type_id() -> CFTypeID;
}

482
vendor/objc2-core-foundation/src/url.rs vendored Normal file
View File

@@ -0,0 +1,482 @@
#[allow(unused_imports)]
use crate::{CFIndex, CFRetained, CFURL};
/// [`Path`][std::path::Path] conversion.
#[cfg(feature = "std")]
#[cfg(unix)] // TODO: Use as_encoded_bytes/from_encoded_bytes_unchecked once in MSRV.
impl CFURL {
#[inline]
fn from_path(
path: &std::path::Path,
is_directory: bool,
base: Option<&CFURL>,
) -> Option<CFRetained<CFURL>> {
use std::os::unix::ffi::OsStrExt;
// CFURL expects to get a string with the system encoding, and will
// internally handle the different encodings, depending on if compiled
// for Apple platforms or Windows (which is very rare, but could
// technically happen).
let bytes = path.as_os_str().as_bytes();
// Never gonna happen, allocations can't be this large in Rust.
debug_assert!(bytes.len() < CFIndex::MAX as usize);
let len = bytes.len() as CFIndex;
if let Some(base) = base {
// The base URL must be a directory URL (have a trailing "/").
// If the path is absolute, this URL is ignored.
//
// TODO: Expose this publicly?
unsafe {
Self::from_file_system_representation_relative_to_base(
None,
bytes.as_ptr(),
len,
is_directory,
Some(base),
)
}
} else {
unsafe {
Self::from_file_system_representation(None, bytes.as_ptr(), len, is_directory)
}
}
}
/// Create a file url from a [`Path`][std::path::Path].
///
/// This is useful because a lot of CoreFoundation APIs use `CFURL` to
/// represent file-system paths as well.
///
/// Non-unicode parts of the URL will be percent-encoded, and the url will
/// have the scheme `file://`.
///
/// If the path is relative, it will be considered relative to the current
/// directory.
///
/// Returns `None` when given an invalid path (such as a path containing
/// interior NUL bytes). The exact checks are not guaranteed.
///
///
/// # Examples
///
/// ```
/// use std::path::Path;
/// use objc2_core_foundation::CFURL;
///
/// // Absolute paths work as you'd expect.
/// let url = CFURL::from_file_path("/tmp/file.txt").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), Path::new("/tmp/file.txt"));
///
/// // Relative paths are relative to the current directory.
/// let url = CFURL::from_file_path("foo.txt").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), std::env::current_dir().unwrap().join("foo.txt"));
///
/// // Some invalid paths return `None`.
/// assert!(CFURL::from_file_path("").is_none());
/// // Another example of an invalid path containing interior NUL bytes.
/// assert!(CFURL::from_file_path("/a/\0a").is_none());
///
/// // Trailing NUL bytes are stripped.
/// // NOTE: This only seems to work on some versions of CoreFoundation.
/// let url = CFURL::from_file_path("/a\0\0").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), Path::new("/a"));
/// ```
#[inline]
#[doc(alias = "CFURLCreateFromFileSystemRepresentation")]
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Option<CFRetained<CFURL>> {
Self::from_path(path.as_ref(), false, None)
}
/// Create a directory url from a [`Path`][std::path::Path].
///
/// This differs from [`from_file_path`][Self::from_file_path] in that the
/// path is treated as a directory, which means that other normalization
/// rules are applied to it (to make it end with a `/`).
///
///
/// # Examples
///
/// ```
/// use std::path::Path;
/// use objc2_core_foundation::CFURL;
///
/// // Directory paths get trailing slashes appended
/// let url = CFURL::from_directory_path("/Library").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/"));
///
/// // Unless they already have them.
/// let url = CFURL::from_directory_path("/Library/").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/"));
///
/// // Similarly for relative paths.
/// let url = CFURL::from_directory_path("foo").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), std::env::current_dir().unwrap().join("foo/"));
///
/// // Various dots may be stripped.
/// let url = CFURL::from_directory_path("/Library/././.").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/"));
///
/// // Though of course not if they have semantic meaning.
/// let url = CFURL::from_directory_path("/Library/..").unwrap();
/// assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/.."));
/// ```
#[inline]
#[doc(alias = "CFURLCreateFromFileSystemRepresentation")]
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Option<CFRetained<CFURL>> {
Self::from_path(path.as_ref(), true, None)
}
/// Extract the path part of the URL as a [`PathBuf`][std::path::PathBuf].
///
/// This will return a path regardless of whether the scheme is `file://`.
/// It is the responsibility of the caller to ensure that the URL is valid
/// to use as a file URL.
///
///
/// # Compatibility note
///
/// This currently does not work for non-unicode paths (which are fairly
/// rare on macOS since HFS+ was been superseded by APFS).
///
/// This also currently always returns absolute paths (it converts
/// relative URL paths to absolute), but that may change in the future.
///
///
/// # Examples
///
/// ```
/// use std::path::Path;
/// use objc2_core_foundation::{CFURL, CFString};
///
/// let url = CFURL::from_string(None, &CFString::from_str("file:///tmp/foo.txt"), None).unwrap();
/// assert_eq!(url.to_file_path().unwrap(), Path::new("/tmp/foo.txt"));
/// ```
///
/// See also the examples in [`from_file_path`][Self::from_file_path].
#[doc(alias = "CFURLGetFileSystemRepresentation")]
pub fn to_file_path(&self) -> Option<std::path::PathBuf> {
use std::os::unix::ffi::OsStrExt;
const PATH_MAX: usize = 1024;
// TODO: if a path is relative with no base, how do we get that
// relative path out again (without adding current dir?).
//
// TODO: Should we do something to handle paths larger than PATH_MAX?
// What can we even do? (since it's impossible for us to tell why the
// conversion failed, so we can't know if we need to allocate, or if
// the URL just cannot be converted).
let mut buf = [0u8; PATH_MAX];
let result = unsafe {
self.file_system_representation(true, buf.as_mut_ptr(), buf.len() as CFIndex)
};
if !result {
return None;
}
// SAFETY: CF is guaranteed to null-terminate the buffer if
// the function succeeded.
let cstr = unsafe { core::ffi::CStr::from_bytes_until_nul(&buf).unwrap_unchecked() };
let path = std::ffi::OsStr::from_bytes(cstr.to_bytes());
Some(path.into())
}
}
/// String conversion.
impl CFURL {
/// Create an URL from a `CFString`.
///
/// Returns `None` if the URL is considered invalid by CoreFoundation. The
/// exact details of which strings are invalid URLs are considered an
/// implementation detail.
///
/// Note in particular that not all strings that the URL spec considers
/// invalid are considered invalid by CoreFoundation too. If you need
/// spec-compliant parsing, consider the [`url`] crate instead.
///
/// [`url`]: https://docs.rs/url/
///
/// # Examples
///
/// Construct and inspect a `CFURL`.
///
/// ```
/// use objc2_core_foundation::{
/// CFString, CFURL, CFURLCopyHostName, CFURLCopyScheme, CFURLCopyPath,
/// };
///
/// let url = CFURL::from_string(None, &CFString::from_str("http://example.com/foo"), None).unwrap();
/// assert_eq!(url.string().to_string(), "http://example.com/foo");
/// assert_eq!(CFURLCopyScheme(&url).unwrap().to_string(), "http");
/// assert_eq!(CFURLCopyHostName(&url).unwrap().to_string(), "example.com");
/// assert_eq!(CFURLCopyPath(&url).unwrap().to_string(), "/foo");
/// ```
///
/// Fail parsing certain strings.
///
/// ```
/// use objc2_core_foundation::{CFString, CFURL};
///
/// // Percent-encoding needs two characters.
/// assert_eq!(CFURL::from_string(None, &CFString::from_str("http://example.com/%A"), None), None);
///
/// // Two hash-characters is disallowed.
/// assert_eq!(CFURL::from_string(None, &CFString::from_str("http://example.com/abc#a#b"), None), None);
/// ```
#[inline]
#[doc(alias = "CFURLCreateWithString")]
pub fn from_string(
allocator: Option<&crate::CFAllocator>,
url_string: &crate::CFString,
base_url: Option<&CFURL>,
) -> Option<CFRetained<Self>> {
Self::__from_string(allocator, Some(url_string), base_url)
}
/// Create an URL from a string without checking it for validity.
///
/// Returns `None` on some OS versions when the string contains interior
/// NUL bytes.
///
/// # Safety
///
/// The URL must be valid.
///
/// Note that it is unclear whether this is actually a safety requirement,
/// or simply a correctness requirement. So we conservatively mark this
/// function as `unsafe`.
#[inline]
#[cfg(feature = "CFString")]
#[doc(alias = "CFURLCreateWithBytes")]
pub unsafe fn from_str_unchecked(s: &str) -> Option<CFRetained<Self>> {
let ptr = s.as_ptr();
// Never gonna happen, allocations can't be this large in Rust.
debug_assert!(s.len() < CFIndex::MAX as usize);
let len = s.len() as CFIndex;
let encoding = crate::CFStringBuiltInEncodings::EncodingUTF8;
// SAFETY: The pointer and length are valid, and the encoding is a
// superset of ASCII.
//
// Unlike `CFURLCreateWithString`, this does _not_ verify the URL at
// all, and thus we propagate the validity checks to the user. See
// also the source code for the checks:
// https://github.com/apple-oss-distributions/CF/blob/CF-1153.18/CFURL.c#L1882-L1970
unsafe { Self::with_bytes(None, ptr, len, encoding.0, None) }
}
/// Get the string-representation of the URL.
///
/// The string may be overly sanitized (percent-encoded), do not rely on
/// this returning exactly the same string as was passed in
/// [`from_string`][Self::from_string].
#[doc(alias = "CFURLGetString")]
pub fn string(&self) -> CFRetained<crate::CFString> {
// URLs contain valid UTF-8, so this should only fail on allocation
// error.
self.__string().expect("failed getting string from CFURL")
}
}
#[cfg(unix)]
#[cfg(test)]
#[cfg(feature = "CFString")]
#[cfg(feature = "std")]
mod tests {
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
use std::path::Path;
use std::{env::current_dir, string::ToString};
use crate::{CFString, CFURLPathStyle};
use super::*;
#[test]
fn from_string() {
let url =
CFURL::from_string(None, &CFString::from_str("https://example.com/xyz"), None).unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/xyz"));
assert_eq!(url.string().to_string(), "https://example.com/xyz");
// Invalid.
let url = CFURL::from_string(None, &CFString::from_str("\0"), None);
assert_eq!(url, None);
// Also invalid.
let url = CFURL::from_string(None, &CFString::from_str("http://example.com/%a"), None);
assert_eq!(url, None);
// Though using `from_str_unchecked` succeeds.
let url = unsafe { CFURL::from_str_unchecked("http://example.com/%a") }.unwrap();
assert_eq!(url.string().to_string(), "http://example.com/%25a");
assert_eq!(url.to_file_path().unwrap(), Path::new("/%a"));
let url = unsafe { CFURL::from_str_unchecked("/\0a\0") }.unwrap();
assert_eq!(url.string().to_string(), "/%00a%00");
assert_eq!(url.to_file_path(), None);
}
#[test]
fn to_string_may_extra_percent_encode() {
let url = CFURL::from_string(None, &CFString::from_str("["), None).unwrap();
assert_eq!(url.string().to_string(), "%5B");
}
#[test]
#[cfg(feature = "objc2")]
fn invalid_with_nul_bytes() {
// This is a bug in newer CF versions:
// https://github.com/swiftlang/swift-corelibs-foundation/issues/5200
let url = unsafe { CFURL::from_str_unchecked("a\0aaaaaa") };
if objc2::available!(macos = 12.0, ios = 15.0, watchos = 8.0, tvos = 15.0, ..) {
assert_eq!(url, None);
} else {
assert_eq!(url.unwrap().string().to_string(), "a%00aaaaaa");
}
}
#[test]
fn to_from_path() {
let url = CFURL::from_file_path("/").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/"));
let url = CFURL::from_file_path("/abc/def").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/abc/def"));
let url = CFURL::from_directory_path("/abc/def").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/abc/def/"));
let url = CFURL::from_file_path("relative.txt").unwrap();
assert_eq!(
url.to_file_path(),
Some(current_dir().unwrap().join("relative.txt"))
);
assert_eq!(
url.absolute_url().unwrap().to_file_path(),
Some(current_dir().unwrap().join("relative.txt"))
);
let str = "/with space and wéird UTF-8 chars: 😀";
let url = CFURL::from_file_path(str).unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new(str));
}
#[test]
fn invalid_path() {
assert_eq!(CFURL::from_file_path(""), None);
assert_eq!(CFURL::from_file_path("/\0/a"), None);
}
#[test]
fn from_dir_strips_dot() {
let url = CFURL::from_directory_path("/Library/.").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/"));
}
/// Ensure that trailing NULs are completely stripped.
#[test]
#[cfg_attr(
not(target_os = "macos"),
ignore = "seems to work differently in the simulator"
)]
fn path_with_trailing_nul() {
let url = CFURL::from_file_path("/abc/def\0\0\0").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/abc/def"));
let path = url
.file_system_path(CFURLPathStyle::CFURLPOSIXPathStyle)
.unwrap();
assert_eq!(path.to_string(), "/abc/def");
#[allow(deprecated)]
let path = url
.file_system_path(CFURLPathStyle::CFURLHFSPathStyle)
.unwrap();
assert!(path.to_string().ends_with(":abc:def")); // $DISK_NAME:abc:def
let path = url
.file_system_path(CFURLPathStyle::CFURLWindowsPathStyle)
.unwrap();
assert_eq!(path.to_string(), "\\abc\\def");
}
#[test]
fn path_with_base() {
let base = CFURL::from_directory_path("/abc/").unwrap();
let url = CFURL::from_path(Path::new("def"), false, Some(&base)).unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/abc/def"));
let url = CFURL::from_path(Path::new("def/"), false, Some(&base)).unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/abc/def/"));
let url = CFURL::from_path(Path::new("/def"), false, Some(&base)).unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/def"));
}
#[test]
fn path_invalid_utf8() {
// Non-root path.
let url = CFURL::from_file_path(OsStr::from_bytes(b"abc\xd4def/xyz")).unwrap();
assert_eq!(url.to_file_path().unwrap(), current_dir().unwrap()); // Huh?
assert!(url
.file_system_path(CFURLPathStyle::CFURLPOSIXPathStyle)
.is_none());
assert_eq!(url.string().to_string(), "abc%D4def/xyz");
assert_eq!(url.path().unwrap().to_string(), "abc%D4def/xyz");
// Root path.
// lone continuation byte (128) (invalid utf8)
let url = CFURL::from_file_path(OsStr::from_bytes(b"/\xf8a/b/c")).unwrap();
assert_eq!(
url.to_file_path().unwrap(),
OsStr::from_bytes(b"/\xf8a/b/c")
);
assert_eq!(url.string().to_string(), "file:///%F8a/b/c");
assert_eq!(url.path().unwrap().to_string(), "/%F8a/b/c");
// Joined paths
let url = CFURL::from_path(
Path::new(OsStr::from_bytes(b"sub\xd4/%D4")),
false,
Some(&url),
)
.unwrap();
assert_eq!(url.to_file_path(), None);
assert_eq!(url.string().to_string(), "sub%D4/%25D4");
assert_eq!(url.path().unwrap().to_string(), "sub%D4/%25D4");
let abs = url.absolute_url().unwrap();
assert_eq!(abs.to_file_path(), None);
assert_eq!(abs.string().to_string(), "file:///%F8a/b/sub%D4/%25D4");
assert_eq!(abs.path().unwrap().to_string(), "/%F8a/b/sub%D4/%25D4");
}
#[test]
fn path_percent_encoded() {
let url = CFURL::from_file_path("/%D4").unwrap();
assert_eq!(url.path().unwrap().to_string(), "/%25D4");
assert_eq!(url.to_file_path().unwrap(), Path::new("/%D4"));
let url = CFURL::from_file_path("/%invalid").unwrap();
assert_eq!(url.path().unwrap().to_string(), "/%25invalid");
assert_eq!(url.to_file_path().unwrap(), Path::new("/%invalid"));
}
#[test]
fn path_percent_encoded_eq() {
let normal = CFURL::from_file_path(OsStr::from_bytes(b"\xf8")).unwrap();
let percent = CFURL::from_file_path("%F8").unwrap();
// Not equal, even though the filesystem may consider these paths equal.
assert_ne!(normal, percent);
}
#[test]
#[allow(deprecated)]
#[ignore = "TODO: Crashes - is this unsound?"]
fn hfs_invalid_utf8() {
let url = CFURL::from_file_path(OsStr::from_bytes(b"\xd4")).unwrap();
assert!(url
.file_system_path(CFURLPathStyle::CFURLHFSPathStyle)
.is_none());
}
}

View File

@@ -0,0 +1,19 @@
#![allow(non_snake_case)]
use crate::{CFIndex, CFOptionFlags, CFUserNotification};
impl CFUserNotification {
#[doc(alias = "CFUserNotificationCheckBoxChecked")]
pub extern "C" fn check_box_checked(i: CFIndex) -> CFOptionFlags {
(1usize << (8 + i)) as CFOptionFlags
}
#[doc(alias = "CFUserNotificationSecureTextField")]
pub extern "C" fn secure_text_field(i: CFIndex) -> CFOptionFlags {
(1usize << (16 + i)) as CFOptionFlags
}
#[doc(alias = "CFUserNotificationPopUpSelection")]
pub fn pop_up_selection(n: CFIndex) -> CFOptionFlags {
(n << 24) as CFOptionFlags
}
}

View File

@@ -0,0 +1,72 @@
use crate::CFUUIDBytes;
impl From<[u8; 16]> for CFUUIDBytes {
#[inline]
fn from(value: [u8; 16]) -> Self {
Self {
byte0: value[0],
byte1: value[1],
byte2: value[2],
byte3: value[3],
byte4: value[4],
byte5: value[5],
byte6: value[6],
byte7: value[7],
byte8: value[8],
byte9: value[9],
byte10: value[10],
byte11: value[11],
byte12: value[12],
byte13: value[13],
byte14: value[14],
byte15: value[15],
}
}
}
impl From<CFUUIDBytes> for [u8; 16] {
#[inline]
fn from(value: CFUUIDBytes) -> Self {
[
value.byte0,
value.byte1,
value.byte2,
value.byte3,
value.byte4,
value.byte5,
value.byte6,
value.byte7,
value.byte8,
value.byte9,
value.byte10,
value.byte11,
value.byte12,
value.byte13,
value.byte14,
value.byte15,
]
}
}
#[cfg(test)]
mod tests {
use crate::CFUUID;
#[test]
fn eq() {
let uuid0 = CFUUID::from_uuid_bytes(None, [0; 16].into()).unwrap();
let uuid1 = CFUUID::from_uuid_bytes(None, [1; 16].into()).unwrap();
assert_eq!(uuid0, uuid0);
assert_ne!(uuid0, uuid1);
}
#[test]
fn roundtrip() {
let uuid = CFUUID::new(None).unwrap();
assert_eq!(uuid, uuid);
let bytes = uuid.uuid_bytes();
let same_uuid = CFUUID::from_uuid_bytes(None, bytes).unwrap();
assert_eq!(uuid, same_uuid);
}
}