CFURL

Struct CFURL 

Source
#[repr(C)]
pub struct CFURL { /* private fields */ }
Available on crate feature CFURL only.
Expand description

Implementations§

Source§

impl CFURL

Source

pub unsafe fn with_bytes( allocator: Option<&CFAllocator>, url_bytes: *const u8, length: CFIndex, encoding: CFStringEncoding, base_url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>

Available on crate feature CFString only.
Source

pub fn new_data( allocator: Option<&CFAllocator>, url: Option<&CFURL>, encoding: CFStringEncoding, escape_whitespace: bool, ) -> Option<CFRetained<CFData>>

Available on crate features CFData and CFString only.
Source

pub unsafe fn new_absolute_url_with_bytes( alloc: Option<&CFAllocator>, relative_url_bytes: *const u8, length: CFIndex, encoding: CFStringEncoding, base_url: Option<&CFURL>, use_compatibility_mode: bool, ) -> Option<CFRetained<CFURL>>

Available on crate feature CFString only.
Source

pub fn with_file_system_path( allocator: Option<&CFAllocator>, file_path: Option<&CFString>, path_style: CFURLPathStyle, is_directory: bool, ) -> Option<CFRetained<CFURL>>

Source

pub unsafe fn from_file_system_representation( allocator: Option<&CFAllocator>, buffer: *const u8, buf_len: CFIndex, is_directory: bool, ) -> Option<CFRetained<CFURL>>

Source

pub fn with_file_system_path_relative_to_base( allocator: Option<&CFAllocator>, file_path: Option<&CFString>, path_style: CFURLPathStyle, is_directory: bool, base_url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>

Source

pub unsafe fn from_file_system_representation_relative_to_base( allocator: Option<&CFAllocator>, buffer: *const u8, buf_len: CFIndex, is_directory: bool, base_url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>

Source

pub unsafe fn file_system_representation( self: &CFURL, resolve_against_base: bool, buffer: *mut u8, max_buf_len: CFIndex, ) -> bool

Source

pub fn absolute_url(self: &CFURL) -> Option<CFRetained<CFURL>>

Source

pub fn base_url(self: &CFURL) -> Option<CFRetained<CFURL>>

Source

pub fn can_be_decomposed(self: &CFURL) -> bool

Source

pub fn scheme(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn net_location(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn path(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub unsafe fn strict_path( self: &CFURL, is_absolute: *mut u8, ) -> Option<CFRetained<CFString>>

Source

pub fn file_system_path( self: &CFURL, path_style: CFURLPathStyle, ) -> Option<CFRetained<CFString>>

Source

pub fn has_directory_path(self: &CFURL) -> bool

Source

pub fn resource_specifier(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn host_name(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn port_number(self: &CFURL) -> i32

Source

pub fn user_name(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn password(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn parameter_string( self: &CFURL, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>

👎Deprecated: The CFURLCopyParameterString function is deprecated. Post deprecation for applications linked with or after the macOS 10.15, and for all iOS, watchOS, and tvOS applications, CFURLCopyParameterString will always return NULL, and the CFURLCopyPath(), CFURLCopyStrictPath(), and CFURLCopyFileSystemPath() functions will return the complete path including the semicolon separator and params component if the URL string contains them.
Source

pub fn query_string( self: &CFURL, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>

Source

pub fn fragment( self: &CFURL, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>

Source

pub fn last_path_component(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn path_extension(self: &CFURL) -> Option<CFRetained<CFString>>

Source

pub fn new_copy_appending_path_component( allocator: Option<&CFAllocator>, url: Option<&CFURL>, path_component: Option<&CFString>, is_directory: bool, ) -> Option<CFRetained<CFURL>>

Source

pub fn new_copy_deleting_last_path_component( allocator: Option<&CFAllocator>, url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>

Source

pub fn new_copy_appending_path_extension( allocator: Option<&CFAllocator>, url: Option<&CFURL>, extension: Option<&CFString>, ) -> Option<CFRetained<CFURL>>

Source

pub fn new_copy_deleting_path_extension( allocator: Option<&CFAllocator>, url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>

Source

pub unsafe fn bytes( self: &CFURL, buffer: *mut u8, buffer_length: CFIndex, ) -> CFIndex

Source§

impl CFURL

Source

pub unsafe fn byte_range_for_component( self: &CFURL, component: CFURLComponentType, range_including_separators: *mut CFRange, ) -> CFRange

Source

pub fn new_string_by_replacing_percent_escapes( allocator: Option<&CFAllocator>, original_string: Option<&CFString>, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>

Source

pub unsafe fn new_string_by_replacing_percent_escapes_using_encoding( allocator: Option<&CFAllocator>, orig_string: Option<&CFString>, chars_to_leave_escaped: Option<&CFString>, encoding: CFStringEncoding, ) -> Option<CFRetained<CFString>>

👎Deprecated: Use [NSString stringByRemovingPercentEncoding] or CFURLCreateStringByReplacingPercentEscapes() instead, which always uses the recommended UTF-8 encoding.
Available on crate feature CFString only.
Source

pub unsafe fn new_string_by_adding_percent_escapes( allocator: Option<&CFAllocator>, original_string: Option<&CFString>, characters_to_leave_unescaped: Option<&CFString>, legal_url_characters_to_be_escaped: Option<&CFString>, encoding: CFStringEncoding, ) -> Option<CFRetained<CFString>>

👎Deprecated: Use [NSString stringByAddingPercentEncodingWithAllowedCharacters:] instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent (since each URL component or subcomponent has different rules for what characters are valid).
Available on crate feature CFString only.
Source

pub fn is_file_reference_url(self: &CFURL) -> bool

Source

pub unsafe fn new_file_reference_url( allocator: Option<&CFAllocator>, url: Option<&CFURL>, error: *mut *mut CFError, ) -> Option<CFRetained<CFURL>>

Available on crate feature CFError only.
Source

pub unsafe fn new_file_path_url( allocator: Option<&CFAllocator>, url: Option<&CFURL>, error: *mut *mut CFError, ) -> Option<CFRetained<CFURL>>

Available on crate feature CFError only.
Source

pub unsafe fn resource_property_for_key( self: &CFURL, key: Option<&CFString>, property_value_type_ref_ptr: *mut c_void, error: *mut *mut CFError, ) -> bool

Available on crate feature CFError only.
Source

pub unsafe fn resource_properties_for_keys( self: &CFURL, keys: Option<&CFArray>, error: *mut *mut CFError, ) -> Option<CFRetained<CFDictionary>>

Available on crate features CFArray and CFDictionary and CFError only.
Source

pub unsafe fn set_resource_property_for_key( self: &CFURL, key: Option<&CFString>, property_value: Option<&CFType>, error: *mut *mut CFError, ) -> bool

Available on crate feature CFError only.
Source

pub unsafe fn set_resource_properties_for_keys( self: &CFURL, keyed_property_values: Option<&CFDictionary>, error: *mut *mut CFError, ) -> bool

Available on crate features CFDictionary and CFError only.
Source§

impl CFURL

Source

pub fn clear_resource_property_cache_for_key( self: &CFURL, key: Option<&CFString>, )

Source

pub fn clear_resource_property_cache(self: &CFURL)

Source

pub fn set_temporary_resource_property_for_key( self: &CFURL, key: Option<&CFString>, property_value: Option<&CFType>, )

Source

pub unsafe fn resource_is_reachable( self: &CFURL, error: *mut *mut CFError, ) -> bool

Available on crate feature CFError only.
Source§

impl CFURL

Source

pub unsafe fn new_bookmark_data( allocator: Option<&CFAllocator>, url: Option<&CFURL>, options: CFURLBookmarkCreationOptions, resource_properties_to_include: Option<&CFArray>, relative_to_url: Option<&CFURL>, error: *mut *mut CFError, ) -> Option<CFRetained<CFData>>

Available on crate features CFArray and CFData and CFError only.
Source

pub unsafe fn new_by_resolving_bookmark_data( allocator: Option<&CFAllocator>, bookmark: Option<&CFData>, options: CFURLBookmarkResolutionOptions, relative_to_url: Option<&CFURL>, resource_properties_to_include: Option<&CFArray>, is_stale: *mut u8, error: *mut *mut CFError, ) -> Option<CFRetained<CFURL>>

Available on crate features CFArray and CFData and CFError only.
Source

pub unsafe fn new_resource_properties_for_keys_from_bookmark_data( allocator: Option<&CFAllocator>, resource_properties_to_return: Option<&CFArray>, bookmark: Option<&CFData>, ) -> Option<CFRetained<CFDictionary>>

Available on crate features CFArray and CFData and CFDictionary only.
Source

pub unsafe fn new_resource_property_for_key_from_bookmark_data( allocator: Option<&CFAllocator>, resource_property_key: Option<&CFString>, bookmark: Option<&CFData>, ) -> Option<CFRetained<CFType>>

Available on crate feature CFData only.
Source

pub unsafe fn new_bookmark_data_from_file( allocator: Option<&CFAllocator>, file_url: Option<&CFURL>, error_ref: *mut *mut CFError, ) -> Option<CFRetained<CFData>>

Available on crate features CFData and CFError only.
Source

pub unsafe fn write_bookmark_data_to_file( bookmark_ref: Option<&CFData>, file_url: Option<&CFURL>, options: CFURLBookmarkFileCreationOptions, error_ref: *mut *mut CFError, ) -> bool

Available on crate features CFData and CFError only.
Source

pub unsafe fn new_bookmark_data_from_alias_record( allocator_ref: Option<&CFAllocator>, alias_record_data_ref: Option<&CFData>, ) -> Option<CFRetained<CFData>>

👎Deprecated: The Carbon Alias Manager is deprecated. This function should only be used to convert Carbon AliasRecords to bookmark data.
Available on crate feature CFData only.
Source

pub unsafe fn start_accessing_security_scoped_resource(self: &CFURL) -> bool

Source

pub unsafe fn stop_accessing_security_scoped_resource(self: &CFURL)

Source§

impl CFURL

Source

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

👎Deprecated: For resource data, use the CFReadStream API. For file resource properties, use CFURLCopyResourcePropertiesForKeys.
Available on crate features CFURLAccess and CFArray and CFData and CFDictionary only.
Source

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

👎Deprecated: For resource data, use the CFWriteStream API. For file resource properties, use CFURLSetResourcePropertiesForKeys.
Available on crate features CFURLAccess and CFData and CFDictionary only.
Source

pub unsafe fn destroy_resource(self: &CFURL, error_code: *mut i32) -> bool

👎Deprecated: Use CFURLGetFileSystemRepresentation and removefile(3) instead.
Available on crate feature CFURLAccess only.
Source

pub unsafe fn new_property_from_resource( alloc: Option<&CFAllocator>, url: Option<&CFURL>, property: Option<&CFString>, error_code: *mut i32, ) -> Option<CFRetained<CFType>>

👎Deprecated: For file resource properties, use CFURLCopyResourcePropertyForKey.
Available on crate feature CFURLAccess only.
Source§

impl CFURL

Path conversion.

Source

pub fn from_file_path<P: AsRef<Path>>(path: P) -> Option<CFRetained<CFURL>>

Available on crate feature std and Unix only.

Create a file url from a 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"));
Source

pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Option<CFRetained<CFURL>>

Available on crate feature std and Unix only.

Create a directory url from a Path.

This differs from 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/.."));
Source

pub fn to_file_path(&self) -> Option<PathBuf>

Available on crate feature std and Unix only.

Extract the path part of the URL as a 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.

Source§

impl CFURL

String conversion.

Source

pub fn from_string( allocator: Option<&CFAllocator>, url_string: &CFString, base_url: Option<&CFURL>, ) -> Option<CFRetained<Self>>

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.

§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);
Source

pub unsafe fn from_str_unchecked(s: &str) -> Option<CFRetained<Self>>

Available on crate feature CFString only.

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.

Source

pub fn string(&self) -> CFRetained<CFString>

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.

Methods from Deref<Target = CFType>§

Source

pub fn downcast_ref<T: ConcreteType>(&self) -> Option<&T>

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.

Source

pub fn retain_count(&self) -> usize

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 CFNumbers, small CFStrings etc.) may not have a normal retain count for optimization purposes, and can return usize::MAX in that case.

Trait Implementations§

Source§

impl AsRef<AnyObject> for CFURL

Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<CFType> for CFURL

Source§

fn as_ref(&self) -> &CFType

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<CFURL> for CFURL

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<AnyObject> for CFURL

Source§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<CFType> for CFURL

Source§

fn borrow(&self) -> &CFType

Immutably borrows from an owned value. Read more
Source§

impl ConcreteType for CFURL

Source§

fn type_id() -> CFTypeID

Get the unique CFTypeID identifier for the type. Read more
Source§

impl Debug for CFURL

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for CFURL

Source§

type Target = CFType

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Hash for CFURL

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Message for CFURL

Source§

fn retain(&self) -> Retained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

impl PartialEq for CFURL

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RefEncode for CFURL

Source§

const ENCODING_REF: Encoding

The Objective-C type-encoding for a reference of this type. Read more
Source§

impl Type for CFURL

Source§

fn retain(&self) -> CFRetained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

fn as_concrete_TypeRef(&self) -> &Self

👎Deprecated: this is redundant
Helper for easier transition from the core-foundation crate.
Source§

unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>
where Self: Sized,

👎Deprecated: use CFRetained::retain
Helper for easier transition from the core-foundation crate. Read more
Source§

fn as_CFTypeRef(&self) -> &CFType
where Self: AsRef<CFType>,

👎Deprecated: this is redundant (CF types deref to CFType)
Helper for easier transition from the core-foundation crate.
Source§

unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>
where Self: Sized,

👎Deprecated: use CFRetained::from_raw
Helper for easier transition from the core-foundation crate. Read more
Source§

impl Eq for CFURL

Source§

impl Send for CFURL

Source§

impl Sync for CFURL

Auto Trait Implementations§

§

impl !Freeze for CFURL

§

impl !RefUnwindSafe for CFURL

§

impl !Unpin for CFURL

§

impl !UnwindSafe for CFURL

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,