#[repr(C)]pub struct CFURL { /* private fields */ }
CFURL
only.Expand description
Implementations§
Source§impl CFURL
impl CFURL
pub unsafe fn with_bytes( allocator: Option<&CFAllocator>, url_bytes: *const u8, length: CFIndex, encoding: CFStringEncoding, base_url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>
CFString
only.pub fn new_data( allocator: Option<&CFAllocator>, url: Option<&CFURL>, encoding: CFStringEncoding, escape_whitespace: bool, ) -> Option<CFRetained<CFData>>
CFData
and CFString
only.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>>
CFString
only.pub fn with_file_system_path( allocator: Option<&CFAllocator>, file_path: Option<&CFString>, path_style: CFURLPathStyle, is_directory: bool, ) -> Option<CFRetained<CFURL>>
pub unsafe fn from_file_system_representation( allocator: Option<&CFAllocator>, buffer: *const u8, buf_len: CFIndex, is_directory: bool, ) -> Option<CFRetained<CFURL>>
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>>
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>>
pub unsafe fn file_system_representation( self: &CFURL, resolve_against_base: bool, buffer: *mut u8, max_buf_len: CFIndex, ) -> bool
pub fn absolute_url(self: &CFURL) -> Option<CFRetained<CFURL>>
pub fn base_url(self: &CFURL) -> Option<CFRetained<CFURL>>
pub fn can_be_decomposed(self: &CFURL) -> bool
pub fn scheme(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn net_location(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn path(self: &CFURL) -> Option<CFRetained<CFString>>
pub unsafe fn strict_path( self: &CFURL, is_absolute: *mut u8, ) -> Option<CFRetained<CFString>>
pub fn file_system_path( self: &CFURL, path_style: CFURLPathStyle, ) -> Option<CFRetained<CFString>>
pub fn has_directory_path(self: &CFURL) -> bool
pub fn resource_specifier(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn host_name(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn port_number(self: &CFURL) -> i32
pub fn user_name(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn password(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn parameter_string( self: &CFURL, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>
pub fn query_string( self: &CFURL, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>
pub fn fragment( self: &CFURL, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>
pub fn last_path_component(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn path_extension(self: &CFURL) -> Option<CFRetained<CFString>>
pub fn new_copy_appending_path_component( allocator: Option<&CFAllocator>, url: Option<&CFURL>, path_component: Option<&CFString>, is_directory: bool, ) -> Option<CFRetained<CFURL>>
pub fn new_copy_deleting_last_path_component( allocator: Option<&CFAllocator>, url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>
pub fn new_copy_appending_path_extension( allocator: Option<&CFAllocator>, url: Option<&CFURL>, extension: Option<&CFString>, ) -> Option<CFRetained<CFURL>>
pub fn new_copy_deleting_path_extension( allocator: Option<&CFAllocator>, url: Option<&CFURL>, ) -> Option<CFRetained<CFURL>>
pub unsafe fn bytes( self: &CFURL, buffer: *mut u8, buffer_length: CFIndex, ) -> CFIndex
Source§impl CFURL
impl CFURL
pub unsafe fn byte_range_for_component( self: &CFURL, component: CFURLComponentType, range_including_separators: *mut CFRange, ) -> CFRange
pub fn new_string_by_replacing_percent_escapes( allocator: Option<&CFAllocator>, original_string: Option<&CFString>, characters_to_leave_escaped: Option<&CFString>, ) -> Option<CFRetained<CFString>>
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>>
CFString
only.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>>
CFString
only.pub fn is_file_reference_url(self: &CFURL) -> bool
pub unsafe fn new_file_reference_url( allocator: Option<&CFAllocator>, url: Option<&CFURL>, error: *mut *mut CFError, ) -> Option<CFRetained<CFURL>>
CFError
only.pub unsafe fn new_file_path_url( allocator: Option<&CFAllocator>, url: Option<&CFURL>, error: *mut *mut CFError, ) -> Option<CFRetained<CFURL>>
CFError
only.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
CFError
only.pub unsafe fn resource_properties_for_keys( self: &CFURL, keys: Option<&CFArray>, error: *mut *mut CFError, ) -> Option<CFRetained<CFDictionary>>
CFArray
and CFDictionary
and CFError
only.pub unsafe fn set_resource_property_for_key( self: &CFURL, key: Option<&CFString>, property_value: Option<&CFType>, error: *mut *mut CFError, ) -> bool
CFError
only.pub unsafe fn set_resource_properties_for_keys( self: &CFURL, keyed_property_values: Option<&CFDictionary>, error: *mut *mut CFError, ) -> bool
CFDictionary
and CFError
only.Source§impl CFURL
impl CFURL
pub fn clear_resource_property_cache_for_key( self: &CFURL, key: Option<&CFString>, )
pub fn clear_resource_property_cache(self: &CFURL)
pub fn set_temporary_resource_property_for_key( self: &CFURL, key: Option<&CFString>, property_value: Option<&CFType>, )
pub unsafe fn resource_is_reachable( self: &CFURL, error: *mut *mut CFError, ) -> bool
CFError
only.Source§impl CFURL
impl CFURL
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>>
CFArray
and CFData
and CFError
only.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>>
CFArray
and CFData
and CFError
only.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>>
CFArray
and CFData
and CFDictionary
only.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>>
CFData
only.pub unsafe fn new_bookmark_data_from_file( allocator: Option<&CFAllocator>, file_url: Option<&CFURL>, error_ref: *mut *mut CFError, ) -> Option<CFRetained<CFData>>
CFData
and CFError
only.pub unsafe fn write_bookmark_data_to_file( bookmark_ref: Option<&CFData>, file_url: Option<&CFURL>, options: CFURLBookmarkFileCreationOptions, error_ref: *mut *mut CFError, ) -> bool
CFData
and CFError
only.pub unsafe fn new_bookmark_data_from_alias_record( allocator_ref: Option<&CFAllocator>, alias_record_data_ref: Option<&CFData>, ) -> Option<CFRetained<CFData>>
CFData
only.pub unsafe fn start_accessing_security_scoped_resource(self: &CFURL) -> bool
pub unsafe fn stop_accessing_security_scoped_resource(self: &CFURL)
Source§impl CFURL
impl CFURL
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
CFURLAccess
and CFArray
and CFData
and CFDictionary
only.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
CFURLAccess
and CFData
and CFDictionary
only.pub unsafe fn destroy_resource(self: &CFURL, error_code: *mut i32) -> bool
CFURLAccess
only.pub unsafe fn new_property_from_resource( alloc: Option<&CFAllocator>, url: Option<&CFURL>, property: Option<&CFString>, error_code: *mut i32, ) -> Option<CFRetained<CFType>>
CFURLAccess
only.Source§impl CFURL
Path
conversion.
impl CFURL
Path
conversion.
Sourcepub fn from_file_path<P: AsRef<Path>>(path: P) -> Option<CFRetained<CFURL>>
Available on crate feature std
and Unix only.
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Option<CFRetained<CFURL>>
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"));
Sourcepub fn from_directory_path<P: AsRef<Path>>(path: P) -> Option<CFRetained<CFURL>>
Available on crate feature std
and Unix only.
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Option<CFRetained<CFURL>>
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/.."));
Sourcepub fn to_file_path(&self) -> Option<PathBuf>
Available on crate feature std
and Unix only.
pub fn to_file_path(&self) -> Option<PathBuf>
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.
impl CFURL
String conversion.
Sourcepub fn from_string(
allocator: Option<&CFAllocator>,
url_string: &CFString,
base_url: Option<&CFURL>,
) -> Option<CFRetained<Self>>
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);
Sourcepub unsafe fn from_str_unchecked(s: &str) -> Option<CFRetained<Self>>
Available on crate feature CFString
only.
pub unsafe fn from_str_unchecked(s: &str) -> Option<CFRetained<Self>>
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
.
Sourcepub fn string(&self) -> CFRetained<CFString> ⓘ
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>§
Sourcepub fn downcast_ref<T: ConcreteType>(&self) -> Option<&T>
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.
Sourcepub fn retain_count(&self) -> usize
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 CFNumber
s, small CFString
s etc.) may
not have a normal retain count for optimization purposes, and can
return usize::MAX
in that case.
Trait Implementations§
Source§impl ConcreteType for CFURL
impl ConcreteType for CFURL
Source§impl RefEncode for CFURL
impl RefEncode for CFURL
Source§const ENCODING_REF: Encoding
const ENCODING_REF: Encoding
Source§impl Type for CFURL
impl Type for CFURL
Source§fn retain(&self) -> CFRetained<Self> ⓘwhere
Self: Sized,
fn retain(&self) -> CFRetained<Self> ⓘwhere
Self: Sized,
Source§fn as_concrete_TypeRef(&self) -> &Self
fn as_concrete_TypeRef(&self) -> &Self
core-foundation
crate.Source§unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self> ⓘwhere
Self: Sized,
unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self> ⓘwhere
Self: Sized,
core-foundation
crate. Read moreSource§fn as_CFTypeRef(&self) -> &CFType
fn as_CFTypeRef(&self) -> &CFType
core-foundation
crate.Source§unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self> ⓘwhere
Self: Sized,
unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self> ⓘwhere
Self: Sized,
core-foundation
crate. Read more