IOUSBHostInterface

Struct IOUSBHostInterface 

Source
pub struct IOUSBHostInterface { /* private fields */ }
Available on crate features IOUSBHostInterface and IOUSBHostObject only.
Expand description

The IOUSBHostObject representing a USB interface

This class provides functionality to send control requests to the default control endpoint, as well as create IOUSBHostPipe objects to transfer data.

See also Apple’s documentation

Implementations§

Source§

impl IOUSBHostInterface

Source

pub unsafe fn createMatchingDictionaryWithVendorID_productID_bcdDevice_interfaceNumber_configurationValue_interfaceClass_interfaceSubclass_interfaceProtocol_speed_productIDArray( vendor_id: Option<&NSNumber>, product_id: Option<&NSNumber>, bcd_device: Option<&NSNumber>, interface_number: Option<&NSNumber>, configuration_value: Option<&NSNumber>, interface_class: Option<&NSNumber>, interface_subclass: Option<&NSNumber>, interface_protocol: Option<&NSNumber>, speed: Option<&NSNumber>, product_id_array: Option<&NSArray>, ) -> Retained<CFMutableDictionary>

Available on crate feature objc2-core-foundation only.

Creates a matching dictionary for an IOUSBHostInterface to be passed into IOServiceGetMatchingService

Parameter vendorID: NSNumber representation of device vendorID

Parameter productID: NSNumber representation of device productID

Parameter bcdDevice: NSNumber representation of device release number

Parameter interfaceNumber: NSNumber representation of interface number

Parameter configurationValue: NSNumber representation of the device’s configurationValue

Parameter interfaceClass: NSNumber representation of interface class

Parameter interfaceSubclass: NSNumber representation of interface subclass

Parameter interfaceProtocol: NSNumber representation of interface protocol

Parameter speed: NSNumber representation of device speed

Parameter productIDArray: NSArray of NSNumbers representing all productIDs interested in. If used do not specify the NSNumber productID field

Returns: CFMutableDictionaryRef to be used with IOService matching methods. To be released by caller.

§Safety
  • product_id_array generic should be of the correct type.
  • The returned generics must be of the correct type.
Source

pub unsafe fn initWithIOService_options_queue_error_interestHandler( this: Allocated<Self>, io_service: io_service_t, options: IOUSBHostObjectInitOptions, queue: Option<&DispatchQueue>, error: Option<&mut Option<Retained<NSError>>>, interest_handler: IOUSBHostInterestHandler, ) -> Option<Retained<Self>>

Available on crate features IOUSBHostDefinitions and block2 and dispatch2 and objc2-io-kit only.

Initializes IOUSBHostInterface object along with user client

See IOUSBHostObject for documentation.

§Safety
  • queue possibly has additional threading requirements.
  • interest_handler must be a valid pointer or null.
Source

pub unsafe fn idleTimeout(&self) -> NSTimeInterval

Retrieve the current idle suspend timeout. See

 setIdleTimeout

Returns: The amount of time after all pipes are idle to wait before suspending the device,

Source

pub unsafe fn setIdleTimeout_error( &self, idle_timeout: NSTimeInterval, ) -> Result<(), Retained<NSError>>

Sets the desired idle suspend timeout for the interface

Once the interface is considered idle, it will defer electrical suspend of the device for the specified duration.

Parameter idleTimeout: The amount of time after all pipes are idle to wait before suspending the device.

Returns: YES on success. An IOReturn error code will be reported on failure.

Source

pub unsafe fn configurationDescriptor( &self, ) -> NonNull<IOUSBConfigurationDescriptor>

Available on crate feature objc2-io-kit only.

Retrieve the configuration descriptor associated with this interface

Returns: IOUSBConfigurationDescriptor pointer

Source

pub unsafe fn interfaceDescriptor(&self) -> NonNull<IOUSBInterfaceDescriptor>

Available on crate feature objc2-io-kit only.

Retrieve the interface descriptor associated with this interface.

Returns: IOUSBInterfaceDescriptor pointer

Source

pub unsafe fn selectAlternateSetting_error( &self, alternate_setting: NSUInteger, ) -> Result<(), Retained<NSError>>

Select an alternate setting for this interface

This method is used to select an alternate setting for the interface. All pending IO on the interface’s pipes will be aborted, and the open pipes will be closed. The IOUSBHostPipe objects already created will no longer be valid. The new alternate setting will be selected via SET_INTERFACE control request (USB 2.0 9.4.10).

Parameter alternateSetting: Alternate interface number to activate

Returns: YES on success, an IOReturn error code will be reported on failure.

Source

pub unsafe fn copyPipeWithAddress_error( &self, address: NSUInteger, ) -> Result<Retained<IOUSBHostPipe>, Retained<NSError>>

Available on crate features IOUSBHostIOSource and IOUSBHostPipe only.

Return the pipe whose bEndpointAddress matches address

This method will return the pipe whose bEndpointAddress matches address . If the pipe is returned successfully, it will maintain a reference to the IOUSBHostInterface.

Parameter address: Endpoint address of the pipe

Returns: Pointer to an IOUSBHostPipe object or nil. The IOUSBHostPipe is to be released by the caller. An IOReturn error code will be reported on failure.

Source§

impl IOUSBHostInterface

Methods declared on superclass IOUSBHostObject.

Source

pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>

Source

pub unsafe fn initWithIOService_queue_error_interestHandler( this: Allocated<Self>, io_service: io_service_t, queue: Option<&DispatchQueue>, error: Option<&mut Option<Retained<NSError>>>, interest_handler: IOUSBHostInterestHandler, ) -> Option<Retained<Self>>

Available on crate features block2 and dispatch2 and objc2-io-kit only.

Initializes IOUSBHostObject object along with user client

This method should be called from either IOUSBHostDevice or IOUSBHostInterface. If the io_service_t is not found nil will be returned. If an IOUSBHostDevice or IOUSBHostInterface user client is already created, nil will be returned. Upon creation, exclusive ownership of the IOService will be established. When done using the object destroy must be called on the object.

Parameter ioService: io_service_t of the IOUSBHostDevice or IOUSBHostInterface the user client is for. The IOUSBHostObject will keep a reference to the io_service_t and release it after the IOUSBHostObject has been released.

Parameter queue: A serial queue that all asynchronous io will be serviced. By default a serial queue will be created on behalf of the client. Setting a queue will create a dispatch source event handler for the target queue to service all underlying io.

Parameter interestHandler: IOUSBHostInterestHandler a generalInterest IOService handler. This is to handle underlying service state changes such as termination. See IOServiceAddInterestNotification in IOKitLib for more details. All notifications will be serviced on an internal serial queue separate from the IO queue.

Returns: An IOUSBHostDevice or IOUSBHostInterface. The object is to be released by the caller. An IOReturn error code will be reported on failure.

§Safety
  • queue possibly has additional threading requirements.
  • interest_handler must be a valid pointer or null.
Source§

impl IOUSBHostInterface

Methods declared on superclass NSObject.

Source

pub unsafe fn new() -> Retained<Self>

Methods from Deref<Target = IOUSBHostObject>§

Source

pub unsafe fn destroy(&self)

Removes underlying allocations of the IOUSBHostObject object along with user client

When the IOUSBHostObject is no longer needed, destroy must be called. This will destroy the connection with the user client and de-register interest on the service. If the object is free’d destroy will be called automatically. Calling destroy multiple times has no effect.

Source

pub unsafe fn destroyWithOptions(&self, options: IOUSBHostObjectDestroyOptions)

Available on crate feature IOUSBHostDefinitions only.

Removes underlying allocations of the IOUSBHostObject object along with user client

Extends destroy to take an options to modify the destroy behavior. Currently only the IOUSBHostObjectDestroyOptionsDeviceSurrender is defined to support surrendering ownersip of the kernel service. To be used when accepting the kUSBHostMessageDeviceIsRequestingClose message.

Source

pub unsafe fn ioService(&self) -> io_service_t

Available on crate feature objc2-io-kit only.

Retrieve the IOUSBHostObject’s io_service_t.

Source

pub unsafe fn queue(&self) -> Retained<DispatchQueue>

Available on crate feature dispatch2 only.

The dispatch queue that all asynchronous io will be serviced.

Source

pub unsafe fn sendDeviceRequest_data_bytesTransferred_completionTimeout_error( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, bytes_transferred: *mut NSUInteger, completion_timeout: NSTimeInterval, ) -> Result<(), Retained<NSError>>

Available on crate feature objc2-io-kit only.

Send a request on the default control endpoint

This method will send a synchronous request on the default control endpoint, and will not return until the request is complete.

Parameter request: IOUSBDeviceRequest structure.

Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.

Parameter bytesTransferred: Optional NSUInteger reference which will be updated with the byte count of the completed data phase.

Parameter completionTimeout: Timeout of the request. If 0, the request will never timeout. By default this value is IOUSBHostDefaultControlCompletionTimeout.

Returns: YES on success, an IOReturn error code will be reported on failure.

§Safety

bytes_transferred must be a valid pointer or null.

Source

pub unsafe fn sendDeviceRequest_data_bytesTransferred_error( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, bytes_transferred: *mut NSUInteger, ) -> Result<(), Retained<NSError>>

Available on crate feature objc2-io-kit only.

Send a request on the default control endpoint

This method will send a synchronous request on the default control endpoint, and will not return until the request is complete.

Parameter request: IOUSBDeviceRequest structure.

Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.

Parameter bytesTransferred: Optional NSUInteger reference which will be updated with the byte count of the completed data phase.

Returns: YES on success, an IOReturn error code will be reported on failure.

§Safety

bytes_transferred must be a valid pointer or null.

Source

pub unsafe fn sendDeviceRequest_error( &self, request: IOUSBDeviceRequest, ) -> Result<(), Retained<NSError>>

Available on crate feature objc2-io-kit only.

Send a request on the default control endpoint

This method will send a synchronous request on the default control endpoint, and will not return until the request is complete.

Parameter request: IOUSBDeviceRequest structure.

Returns: YES on success, an IOReturn error code will be reported on failure.

Source

pub unsafe fn enqueueDeviceRequest_data_completionTimeout_error_completionHandler( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, completion_timeout: NSTimeInterval, error: Option<&mut Option<Retained<NSError>>>, completion_handler: IOUSBHostCompletionHandler, ) -> bool

Available on crate features IOUSBHostDefinitions and block2 and objc2-io-kit only.

Enqueue a request on the default control endpoint

This method will enqueue an asynchronous request on the default control endpoint. If successful, the provided completionHandler will be called to report the status of the completed IO.

Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.

Parameter completionTimeout: Timeout of the request. If 0, the request will never timeout. By default this value is IOUSBHostDefaultControlCompletionTimeout

Parameter completionHandler: an IOUSBHostCompletionHandler

Returns: YES on success, an IOReturn error code will be reported on failure

§Safety

completion_handler must be a valid pointer or null.

Source

pub unsafe fn enqueueDeviceRequest_data_error_completionHandler( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, error: Option<&mut Option<Retained<NSError>>>, completion_handler: IOUSBHostCompletionHandler, ) -> bool

Available on crate features IOUSBHostDefinitions and block2 and objc2-io-kit only.

Enqueue a request on the default control endpoint

This method will enqueue an asynchronous request on the default control endpoint. If successful, the provided completionHandler will be called to report the status of the completed IO.

Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.

Parameter completionHandler: an IOUSBHostCompletionHandler

Returns: YES on success, an IOReturn error code will be reported on failure

§Safety

completion_handler must be a valid pointer or null.

Source

pub unsafe fn enqueueDeviceRequest_error_completionHandler( &self, request: IOUSBDeviceRequest, error: Option<&mut Option<Retained<NSError>>>, completion_handler: IOUSBHostCompletionHandler, ) -> bool

Available on crate features IOUSBHostDefinitions and block2 and objc2-io-kit only.

Enqueue a request on the default control endpoint

This method will enqueue an asynchronous request on the default control endpoint. If successful, the provided completionHandler will be called to report the status of the completed IO. default this value is IOUSBHostDefaultControlCompletionTimeout

Parameter completionHandler: an IOUSBHostCompletionHandler

Returns: YES on success, an IOReturn error code will be reported on failure

§Safety

completion_handler must be a valid pointer or null.

Source

pub unsafe fn abortDeviceRequestsWithOption_error( &self, option: IOUSBHostAbortOption, ) -> Result<(), Retained<NSError>>

Available on crate feature IOUSBHostDefinitions only.

Abort device requests

This method will abort any requests made via the

 sendDeviceRequest

and

 enqueueDeviceRequest

methods.

Parameter option: IOUSBHostAbortOption by default IOUSBHostAbortOptionSynchronous is used

Returns: YES on success, an IOReturn error code will be reported on failure

Source

pub unsafe fn abortDeviceRequestsWithError( &self, ) -> Result<(), Retained<NSError>>

Abort device requests

This method will abort any requests made via the

 sendDeviceRequest

and

 enqueueDeviceRequest

methods.

Returns: YES on success, an IOReturn error code will be reported on failure

Source

pub unsafe fn descriptorWithType_length_index_languageID_requestType_requestRecipient_error( &self, type: tIOUSBDescriptorType, length: NonNull<NSUInteger>, index: NSUInteger, language_id: NSUInteger, request_type: tIOUSBDeviceRequestTypeValue, request_recipient: tIOUSBDeviceRequestRecipientValue, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBDescriptor

Available on crate feature objc2-io-kit only.

Retrieve a descriptor from the cache or the device

This method will search the descriptor cache for the descriptor that matches the input arguments. If the descriptor is not in the cache, a GET_DESCRIPTOR control request (USB 2.0 9.4.3) will be issued to retrieve the descriptor from the device. If the device request is successful, the retrieved descriptor will be added to the cache.

Parameter type: bDescriptorType of the descriptor to find.

Parameter length: Reference to a NSUInteger which will be updated with the length of the descriptor. As input, used as wLength when fetching variable-length configuration or BOS descriptors, or when fetching nonstandard descriptor types.

Parameter index: Descriptor index value. Low byte of wValue of the SET_DESCRIPTOR control request (USB 2.0 9.4.8). By default the value is 0

Parameter languageID: Descriptor language ID. wIndex of the SET_DESCRIPTOR control request (USB 2.0 9.4.8). By default the value is 0

Parameter requestType: tDeviceRequestType to be used for a GET_DESCRIPTOR control request. By default the value is IOUSBRequestTypeStandard

Parameter requestRecipient: tDeviceRequestRecipient to be used for a GET_DESCRIPTOR control request. By default the value is IOUSBRequestRecipientDevice

Returns: Pointer to the cached descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.

§Safety

length must be a valid pointer.

Source

pub unsafe fn descriptorWithType_length_index_languageID_error( &self, type: tIOUSBDescriptorType, length: NonNull<NSUInteger>, index: NSUInteger, language_id: NSUInteger, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBDescriptor

Available on crate feature objc2-io-kit only.

Retrieve a descriptor from the cache or the device

This method will search the descriptor cache for the descriptor that matches the input arguments. If the descriptor is not in the cache, a GET_DESCRIPTOR control request (USB 2.0 9.4.3) will be issued to retrieve the descriptor from the device. If the device request is successful, the retrieved descriptor will be added to the cache.

Parameter type: bDescriptorType of the descriptor to find.

Parameter length: Reference to a NSUInteger which will be updated with the length of the descriptor. As input, used as wLength when fetching variable-length configuration or BOS descriptors, or when fetching nonstandard descriptor types.

Parameter index: Descriptor index value. Low byte of wValue of the SET_DESCRIPTOR control request (USB 2.0 9.4.8). By default the value is 0

Parameter languageID: Descriptor language ID. wIndex of the SET_DESCRIPTOR control request (USB 2.0 9.4.8). By default the value is 0

Returns: Pointer to the cached descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.

§Safety

length must be a valid pointer.

Source

pub unsafe fn descriptorWithType_length_error( &self, type: tIOUSBDescriptorType, length: NonNull<NSUInteger>, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBDescriptor

Available on crate feature objc2-io-kit only.

Retrieve a descriptor from the cache or the device

This method will search the descriptor cache for the descriptor that matches the input arguments. If the descriptor is not in the cache, a GET_DESCRIPTOR control request (USB 2.0 9.4.3) will be issued to retrieve the descriptor from the device. If the device request is successful, the retrieved descriptor will be added to the cache.

Parameter type: bDescriptorType of the descriptor to find.

Parameter length: Reference to a NSUInteger which will be updated with the length of the descriptor. As input, used as wLength when fetching variable-length configuration or BOS descriptors, or when fetching nonstandard descriptor types. By default the value is 0

Returns: Pointer to the cached descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.

§Safety

length must be a valid pointer.

Source

pub unsafe fn deviceDescriptor(&self) -> *const IOUSBDeviceDescriptor

Available on crate feature objc2-io-kit only.

Return the device descriptor

This method uses descriptorWithType to retrieve the device descriptor.

Returns: Pointer to the device descriptor.

Source

pub unsafe fn capabilityDescriptors(&self) -> *const IOUSBBOSDescriptor

Available on crate feature objc2-io-kit only.

Return the capability descriptors of the device

This method uses descriptorWithType to return the device’s BOS descriptors

Returns: Pointer to the BOS descriptor if found, otherwise nil.

Source

pub unsafe fn configurationDescriptorWithIndex_error( &self, index: NSUInteger, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBConfigurationDescriptor

Available on crate feature objc2-io-kit only.

Return the configuration descriptor at a specified index

This method uses descriptorWithType to retrieve the configuration descriptor.

Parameter index: Descriptor index value

Returns: Pointer of the configuration descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.

Source

pub unsafe fn configurationDescriptorWithConfigurationValue_error( &self, configuration_value: NSUInteger, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBConfigurationDescriptor

Available on crate feature objc2-io-kit only.

Return the configuration descriptor with a specified value

This method uses descriptorWithType to search for a configuration descriptor with a specific bConfigurationValue field.

Parameter configurationValue: Value to match

Returns: Pointer of the configuration descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.

Source

pub unsafe fn stringWithIndex_languageID_error( &self, index: NSUInteger, language_id: NSUInteger, ) -> Result<Retained<NSString>, Retained<NSError>>

Returns the string from a string descriptor

This method uses descriptorWithType to retrieve the string descriptor.

Parameter index: Descriptor index value. Low byte of wValue of the SET_DESCRIPTOR control request (USB 2.0 9.4.8).

Parameter languageID: Descriptor language ID. wIndex of the SET_DESCRIPTOR control request (USB 2.0 9.4.8). By default this value is kLanguageIDEnglishUS

Returns: NSString reference to string from descriptor, an IOReturn error code will be reported on failure.

Source

pub unsafe fn stringWithIndex_error( &self, index: NSUInteger, ) -> Result<Retained<NSString>, Retained<NSError>>

Returns the string from a string descriptor

This method uses descriptorWithType to retrieve the string descriptor.

Parameter index: Descriptor index value. Low byte of wValue of the SET_DESCRIPTOR control request (USB 2.0 9.4.8).

Returns: NSString reference to string from descriptor, an IOReturn error code will be reported on failure.

Source

pub unsafe fn deviceAddress(&self) -> NSUInteger

Retrieve the current address of the device.

Source

pub unsafe fn frameNumberWithTime(&self, time: *mut IOUSBHostTime) -> u64

Available on crate feature IOUSBHostDefinitions only.

Return the current frame number of the USB controller

This method will return the current frame number of the USB controller, omitting micro frame. This is most useful for scheduling future isochronous requests.

Parameter time: If not nil, this will be updated with the current system time

Returns: The current frame number

§Safety

time must be a valid pointer or null.

Source

pub unsafe fn currentMicroframeWithTime_error( &self, time: *mut IOUSBHostTime, error: Option<&mut Option<Retained<NSError>>>, ) -> u64

Available on crate feature IOUSBHostDefinitions only.

Return the current microframe number of the USB controller

This method will return the current microframe number of the USB controller. This is most useful for scheduling future isochronous requests.

Parameter time: If not nil, this will be updated with system time associated with the microframe.

Returns: The current microframe number. Returns 0 on failure, with NSError populated with the IOReturn error code.

§Safety

time must be a valid pointer or null.

Source

pub unsafe fn referenceMicroframeWithTime_error( &self, time: *mut IOUSBHostTime, error: Option<&mut Option<Retained<NSError>>>, ) -> u64

Available on crate feature IOUSBHostDefinitions only.

Return a recent microframe number of the USB controller

This method will return a recent microframe number of the USB controller. This is most useful for scheduling future isochronous requests.

Parameter time: If not nil, this will be updated with system time associated with the microframe.

Returns: A recent microframe number. Returns 0 on failure, with NSError populated with the IOReturn error code.

§Safety

time must be a valid pointer or null.

Source

pub unsafe fn ioDataWithCapacity_error( &self, capacity: NSUInteger, ) -> Result<Retained<NSMutableData>, Retained<NSError>>

Allocate a buffer to be used for I/O

This method will allocate and map an IOBufferMemoryDescriptor optimized for use by the underlying controller hardware. A buffer allocated by this method will not be bounced to perform DMA operations. Because the NSMutableData is backed by kernel memory, the length and capacity are not mutable. Any changes to the length or capacity will cause an exception to be thrown.

Parameter capacity: Size of the buffer to allocate

Returns: NSMutableData of memory mapped to user space of an IOBufferMemoryDescriptor if successful, otherwise nil. An IOReturn error code will be reported on failure. The result is to be released by the caller

Methods from Deref<Target = NSObject>§

Source

pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !

Handle messages the object doesn’t recognize.

See Apple’s documentation for details.

Methods from Deref<Target = AnyObject>§

Source

pub fn class(&self) -> &'static AnyClass

Dynamically find the class of this object.

§Panics

May panic if the object is invalid (which may be the case for objects returned from unavailable init/new methods).

§Example

Check that an instance of NSObject has the precise class NSObject.

use objc2::ClassType;
use objc2::runtime::NSObject;

let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Source

pub unsafe fn get_ivar<T>(&self, name: &str) -> &T
where T: Encode,

👎Deprecated: this is difficult to use correctly, use Ivar::load instead.

Use Ivar::load instead.

§Safety

The object must have an instance variable with the given name, and it must be of type T.

See Ivar::load_ptr for details surrounding this.

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: DowncastTarget,

Attempt to downcast the object to a class of type T.

This is the reference-variant. Use Retained::downcast if you want to convert a retained object to another type.

§Mutable classes

Some classes have immutable and mutable variants, such as NSString and NSMutableString.

When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.

So using this method to convert a NSString to a NSMutableString, while not unsound, is generally frowned upon unless you created the string yourself, or the API explicitly documents the string to be mutable.

See Apple’s documentation on mutability and on isKindOfClass: for more details.

§Generic classes

Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.

You can, however, safely downcast to generic collections where all the type-parameters are AnyObject.

§Panics

This works internally by calling isKindOfClass:. That means that the object must have the instance method of that name, and an exception will be thrown (if CoreFoundation is linked) or the process will abort if that is not the case. In the vast majority of cases, you don’t need to worry about this, since both root objects NSObject and NSProxy implement this method.

§Examples

Cast an NSString back and forth from NSObject.

use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};

let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();

Try (and fail) to cast an NSObject to an NSString.

use objc2_foundation::{NSObject, NSString};

let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());

Try to cast to an array of strings.

use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();

This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.

Downcast when processing each element instead.

use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);

for elem in arr {
    if let Some(data) = elem.downcast_ref::<NSString>() {
        // handle `data`
    }
}

Trait Implementations§

Source§

impl AsRef<AnyObject> for IOUSBHostInterface

Source§

fn as_ref(&self) -> &AnyObject

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

impl AsRef<IOUSBHostInterface> for IOUSBHostInterface

Source§

fn as_ref(&self) -> &Self

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

impl AsRef<IOUSBHostObject> for IOUSBHostInterface

Source§

fn as_ref(&self) -> &IOUSBHostObject

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

impl AsRef<NSObject> for IOUSBHostInterface

Source§

fn as_ref(&self) -> &NSObject

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

impl Borrow<AnyObject> for IOUSBHostInterface

Source§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<IOUSBHostObject> for IOUSBHostInterface

Source§

fn borrow(&self) -> &IOUSBHostObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<NSObject> for IOUSBHostInterface

Source§

fn borrow(&self) -> &NSObject

Immutably borrows from an owned value. Read more
Source§

impl ClassType for IOUSBHostInterface

Source§

const NAME: &'static str = "IOUSBHostInterface"

The name of the Objective-C class that this type represents. Read more
Source§

type Super = IOUSBHostObject

The superclass of this class. Read more
Source§

type ThreadKind = <<IOUSBHostInterface as ClassType>::Super as ClassType>::ThreadKind

Whether the type can be used from any thread, or from only the main thread. Read more
Source§

fn class() -> &'static AnyClass

Get a reference to the Objective-C class that this type represents. Read more
Source§

fn as_super(&self) -> &Self::Super

Get an immutable reference to the superclass.
Source§

impl Debug for IOUSBHostInterface

Source§

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

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

impl Deref for IOUSBHostInterface

Source§

type Target = IOUSBHostObject

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl Hash for IOUSBHostInterface

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 IOUSBHostInterface

Source§

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

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

impl NSObjectProtocol for IOUSBHostInterface

Source§

fn isEqual(&self, other: Option<&AnyObject>) -> bool
where Self: Sized + Message,

Check whether the object is equal to an arbitrary other object. Read more
Source§

fn hash(&self) -> usize
where Self: Sized + Message,

An integer that can be used as a table address in a hash table structure. Read more
Source§

fn isKindOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of the class, or one of its subclasses. Read more
Source§

fn is_kind_of<T>(&self) -> bool
where T: ClassType, Self: Sized + Message,

👎Deprecated: use isKindOfClass directly, or cast your objects with AnyObject::downcast_ref
Check if the object is an instance of the class type, or one of its subclasses. Read more
Source§

fn isMemberOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of a specific class, without checking subclasses. Read more
Source§

fn respondsToSelector(&self, aSelector: Sel) -> bool
where Self: Sized + Message,

Check whether the object implements or inherits a method with the given selector. Read more
Source§

fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
where Self: Sized + Message,

Check whether the object conforms to a given protocol. Read more
Source§

fn description(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object. Read more
Source§

fn debugDescription(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object to use when debugging. Read more
Source§

fn isProxy(&self) -> bool
where Self: Sized + Message,

Check whether the receiver is a subclass of the NSProxy root class instead of the usual NSObject. Read more
Source§

fn retainCount(&self) -> usize
where Self: Sized + Message,

The reference count of the object. Read more
Source§

impl PartialEq for IOUSBHostInterface

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 IOUSBHostInterface

Source§

const ENCODING_REF: Encoding = <IOUSBHostObject as ::objc2::RefEncode>::ENCODING_REF

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

impl DowncastTarget for IOUSBHostInterface

Source§

impl Eq for IOUSBHostInterface

Auto Trait Implementations§

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<'a, T> AnyThread for T
where T: ClassType<ThreadKind = dyn AnyThread + 'a> + ?Sized,

Source§

fn alloc() -> Allocated<Self>
where Self: Sized + ClassType,

Allocate a new instance of the class. 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,