DispatchData

Struct DispatchData 

Source
#[repr(C)]
pub struct DispatchData { /* private fields */ }
Expand description

Dispatch data.

Implementations§

Source§

impl DispatchData

Source

pub fn empty() -> &'static Self

Get an empty DispatchData.

Source

pub fn from_bytes(data: &[u8]) -> DispatchRetained<Self>

Creates a dispatch data object with a copy of the given contiguous buffer of memory.

Source

pub fn from_static_bytes(data: &'static [u8]) -> DispatchRetained<Self>

Creates a dispatch data object with a reference to the given contiguous buffer of memory.

Source

pub fn from_boxed(data: Box<[u8]>) -> DispatchRetained<Self>

Creates a dispatch data object with ownership of the given contiguous buffer of memory.

Source

pub fn to_vec(&self) -> Vec<u8>

Copy all the non-contiguous parts of the data into a contiguous Vec.

§Examples
use dispatch2::DispatchData;

let data = DispatchData::from_bytes(b"foo");
assert_eq!(data.to_vec(), b"foo");
Source§

impl DispatchData

Source

pub unsafe fn new( buffer: NonNull<c_void>, size: usize, queue: Option<&DispatchQueue>, destructor: dispatch_block_t, ) -> DispatchRetained<DispatchData>

Creates a dispatch data object from the given contiguous buffer of memory. If a non-default destructor is provided, ownership of the buffer remains with the caller (i.e. the bytes will not be copied). The last release of the data object will result in the invocation of the specified destructor on the specified queue to free the buffer.

If the DISPATCH_DATA_DESTRUCTOR_FREE destructor is provided the buffer will be freed via free(3) and the queue argument ignored.

If the DISPATCH_DATA_DESTRUCTOR_DEFAULT destructor is provided, data object creation will copy the buffer into internal memory managed by the system.

Parameter buffer: A contiguous buffer of data.

Parameter size: The size of the contiguous buffer of data.

Parameter queue: The queue to which the destructor should be submitted.

Parameter destructor: The destructor responsible for freeing the data when it is no longer needed.

Returns: A newly created dispatch data object.

Source

pub fn size(self: &DispatchData) -> usize

Returns the logical size of the memory region(s) represented by the specified dispatch data object.

Parameter data: The dispatch data object to query.

Returns: The number of bytes represented by the data object.

Source

pub unsafe fn map( self: &DispatchData, buffer_ptr: *mut *const c_void, size_ptr: *mut usize, ) -> DispatchRetained<DispatchData>

Maps the memory represented by the specified dispatch data object as a single contiguous memory region and returns a new data object representing it. If non-NULL references to a pointer and a size variable are provided, they are filled with the location and extent of that region. These allow direct read access to the represented memory, but are only valid until the returned object is released. Under ARC, if that object is held in a variable with automatic storage, care needs to be taken to ensure that it is not released by the compiler before memory access via the pointer has been completed.

Parameter data: The dispatch data object to map.

Parameter buffer_ptr: A pointer to a pointer variable to be filled with the location of the mapped contiguous memory region, or NULL.

Parameter size_ptr: A pointer to a size_t variable to be filled with the size of the mapped contiguous memory region, or NULL.

Returns: A newly created dispatch data object.

Source

pub fn concat( self: &DispatchData, data2: &DispatchData, ) -> DispatchRetained<DispatchData>

Returns a new dispatch data object representing the concatenation of the specified data objects. Those objects may be released by the application after the call returns (however, the system might not deallocate the memory region(s) described by them until the newly created object has also been released).

Parameter data1: The data object representing the region(s) of memory to place at the beginning of the newly created object.

Parameter data2: The data object representing the region(s) of memory to place at the end of the newly created object.

Returns: A newly created object representing the concatenation of the data1 and data2 objects.

Source

pub unsafe fn subrange( self: &DispatchData, offset: usize, length: usize, ) -> DispatchRetained<DispatchData>

Returns a new dispatch data object representing a subrange of the specified data object, which may be released by the application after the call returns (however, the system might not deallocate the memory region(s) described by that object until the newly created object has also been released).

Parameter data: The data object representing the region(s) of memory to create a subrange of.

Parameter offset: The offset into the data object where the subrange starts.

Parameter length: The length of the range.

Returns: A newly created object representing the specified subrange of the data object.

Source§

impl DispatchData

Source

pub unsafe fn apply( self: &DispatchData, applier: dispatch_data_applier_t, ) -> bool

Traverse the memory regions represented by the specified dispatch data object in logical order and invoke the specified block once for every contiguous memory region encountered.

Each invocation of the block is passed a data object representing the current region and its logical offset, along with the memory location and extent of the region. These allow direct read access to the memory region, but are only valid until the passed-in region object is released. Note that the region object is released by the system when the block returns, it is the responsibility of the application to retain it if the region object or the associated memory location are needed after the block returns.

Parameter data: The data object to traverse.

Parameter applier: The block to be invoked for every contiguous memory region in the data object.

Returns: A Boolean indicating whether traversal completed successfully.

Source

pub unsafe fn region( self: &DispatchData, location: usize, offset_ptr: NonNull<usize>, ) -> DispatchRetained<DispatchData>

Finds the contiguous memory region containing the specified location among the regions represented by the specified object and returns a copy of the internal dispatch data object representing that region along with its logical offset in the specified object.

Parameter data: The dispatch data object to query.

Parameter location: The logical position in the data object to query.

Parameter offset_ptr: A pointer to a size_t variable to be filled with the logical offset of the returned region object to the start of the queried data object.

Returns: A newly created dispatch data object.

Trait Implementations§

Source§

impl AsRef<AnyObject> for DispatchData

Source§

fn as_ref(&self) -> &AnyObject

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

impl AsRef<DispatchData> for DispatchData

Source§

fn as_ref(&self) -> &Self

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

impl Debug for DispatchData

Source§

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

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

impl DispatchObject for DispatchData

Source§

fn retain(&self) -> DispatchRetained<Self>

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

fn context(&self) -> *mut c_void

TODO. Read more
Source§

unsafe fn set_context(&self, context: *mut c_void)

TODO. Read more
Source§

unsafe fn set_finalizer_f(&self, finalizer: dispatch_function_t)

TODO. Read more
Source§

fn set_finalizer<F>(&self, destructor: F)
where F: Send + FnOnce(),

Set the finalizer function for the object.
Source§

unsafe fn set_target_queue(&self, queue: &DispatchQueue)

Set the target DispatchQueue of this object. Read more
Source§

unsafe fn set_qos_class_floor( &self, qos_class: DispatchQoS, relative_priority: i32, ) -> Result<(), QualityOfServiceClassFloorError>

Set the QOS class floor on a dispatch queue, source or workloop. Read more
Source§

fn activate(&self)

Activate the object.
Source§

fn suspend(&self)

Suspend the invocation of functions on the object.
Source§

fn resume(&self)

Resume the invocation of functions on the object.
Source§

impl Hash for DispatchData

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 DispatchData

Source§

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

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

impl PartialEq for DispatchData

Source§

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

Compare this [$type] with another using pointer equality.

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 DispatchData

Source§

const ENCODING_REF: Encoding = objc2::encode::Encoding::Object

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

impl Eq for DispatchData

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<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<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,