Struct Channel

Source
pub struct Channel<'session>(/* private fields */);

Implementations§

Source§

impl<'a> Channel<'a>

Source

pub fn set_private<T>(&self, key: &CStr, data: T) -> Result<()>
where T: IntoChannelValue + Clone + 'a,

Set private data on channel. See: switch_channel_set_private.

Source

pub fn get_private<T>(&self, key: &CStr) -> Option<T>
where T: IntoChannelValue + Clone + 'a,

Retrieve private data from a given channel for the given key. See: switch_channel_get_private.

Source

pub fn remove_private<T: IntoChannelValue>(&self, key: &CStr) -> Result<()>

Remove private data from channel for the given key. See: switch_channel_set_private.

Source

pub unsafe fn set_private_raw_ptr<T>( &self, key: &CStr, data: *const T, ) -> Result<()>

Set private data on channel. See: switch_channel_set_private.

§Safety

Channels do not own or cleanup their data, so caller must ensure rust allocated structs are cleaned up IF required ie anything on the heap normally by using [add_state_handler]

§Examples
#[switch_state_handler]
pub fn cleanup(s: &Session) -> switch_status_t {
  unsafe {
    let ptr = s.get_channel().map(|c| c.get_private_raw_ptr());
    // Cast and drop ...
  }
}
Source

pub unsafe fn get_private_raw_ptr<T>(&self, key: &CStr) -> Option<*mut T>

Retrieve private data from a given channel for the given key. See: switch_channel_get_private.

§Safety

Care must be taken to not invalidate the stored pointer whilst the channel holds the value ie ensure T is not dropped

Source

pub fn add_state_handler( &self, table: &'static switch_state_handler_table_t, ) -> Result<usize>

Add a state handler table to a given channel. Returns the index number/priority of the table.

See: switch_channel_add_state_handler.

§Examples
#[switch_state_handler]
pub fn cleanup(s: &Session) -> switch_status_t {
   // cleanup ...
}
const STATE_HANDLERS: StateHandlerTable = StateHandlerTable {
    on_destroy: Some(cleanup),
    ..DEFAULT_STATE_HANDLER_TABLE
}

Trait Implementations§

Source§

impl<'session> Debug for Channel<'session>

Source§

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

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

impl<'a> FSNewType for Channel<'a>

Auto Trait Implementations§

§

impl<'session> Freeze for Channel<'session>

§

impl<'session> RefUnwindSafe for Channel<'session>

§

impl<'session> !Send for Channel<'session>

§

impl<'session> !Sync for Channel<'session>

§

impl<'session> Unpin for Channel<'session>

§

impl<'session> UnwindSafe for Channel<'session>

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> IntoChannelValue for T
where T: FSNewType<Inner = *mut U>,

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.