Skip to main content

Session

Struct Session 

Source
pub struct Session {
    pub session: Weak<SessionController>,
    pub rx: RwLock<AppChannelReceiver>,
}
Expand description

Session context for language bindings (UniFFI-compatible)

Wraps the session context with proper async access patterns for message reception. Provides both synchronous (blocking) and asynchronous methods for FFI compatibility.

Fields§

§session: Weak<SessionController>

Weak reference to the underlying session

§rx: RwLock<AppChannelReceiver>

Message receiver wrapped in RwLock for concurrent access

Implementations§

Source§

impl Session

Source

pub fn new(ctx: SlimSession) -> Self

Create a new Session from a Session and runtime

Source

pub fn runtime(&self) -> &'static Runtime

Get the runtime (for internal use)

Source§

impl Session

Source

pub async fn publish_internal( &self, name: &SlimName, fanout: u32, blob: Vec<u8>, conn_out: Option<u64>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<SlimCompletionHandle, SessionError>

Publish a message through this session (internal API for language bindings)

This is the low-level publish method that takes SlimName directly. Use publish() or publish_with_params() for FFI-compatible APIs.

Source

pub async fn publish_to_internal( &self, message_ctx: &MessageContext, blob: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<SlimCompletionHandle, SessionError>

Publish a message as a reply (internal API for language bindings)

This is the low-level publish_to method that takes MessageContext reference. Use publish_to() for FFI-compatible API.

Source

pub async fn invite_internal( &self, destination: &SlimName, ) -> Result<SlimCompletionHandle, SessionError>

Invite a peer to join this session (internal API for language bindings)

This is the low-level invite method that takes SlimName reference. Use invite() for FFI-compatible API with auto-wait.

Source

pub async fn remove_internal( &self, destination: &SlimName, ) -> Result<SlimCompletionHandle, SessionError>

Remove a peer from this session (internal API for language bindings)

This is the low-level remove method that takes SlimName reference. Use remove() for FFI-compatible API with auto-wait.

Source

pub async fn get_session_message( &self, timeout: Option<Duration>, ) -> Result<(MessageContext, Vec<u8>), SessionError>

Receive a message from this session with optional timeout

Source§

impl Session

Source

pub fn publish( &self, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<Arc<CompletionHandle>, SlimError>

Publish a message to the session’s destination (blocking version)

Returns a completion handle that can be awaited to ensure the message was delivered.

§Arguments
  • data - The message payload bytes
  • payload_type - Optional content type identifier
  • metadata - Optional key-value metadata pairs
§Returns
  • Ok(CompletionHandle) - Handle to await delivery confirmation
  • Err(SlimError) - If publishing fails
§Example
let completion = session.publish(data, None, None)?;
completion.wait()?; // Blocks until message is delivered
Source

pub async fn publish_async( &self, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<Arc<CompletionHandle>, SlimError>

Publish a message to the session’s destination (async version)

Returns a completion handle that can be awaited to ensure the message was delivered.

Source

pub fn publish_and_wait( &self, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<(), SlimError>

Publish a message and wait for completion (blocking version)

This method publishes a message and blocks until the delivery completes.

Source

pub async fn publish_and_wait_async( &self, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<(), SlimError>

Publish a message and wait for completion (async version)

This method publishes a message and waits until the delivery completes.

Source

pub fn publish_to( &self, message_context: MessageContext, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<Arc<CompletionHandle>, SlimError>

Publish a reply message to the originator of a received message (blocking version for FFI)

This method uses the routing information from a previously received message to send a reply back to the sender. This is the preferred way to implement request/reply patterns.

Returns a completion handle that can be awaited to ensure the message was delivered.

§Arguments
  • message_context - Context from a message received via get_message()
  • data - The reply payload bytes
  • payload_type - Optional content type identifier
  • metadata - Optional key-value metadata pairs
§Returns
  • Ok(CompletionHandle) - Handle to await delivery confirmation
  • Err(SlimError) - If publishing fails
Source

pub async fn publish_to_async( &self, message_context: MessageContext, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<Arc<CompletionHandle>, SlimError>

Publish a reply message (async version)

Returns a completion handle that can be awaited to ensure the message was delivered.

Source

pub fn publish_to_and_wait( &self, message_context: MessageContext, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<(), SlimError>

Publish a reply message and wait for completion (blocking version)

This method publishes a reply to a received message and blocks until the delivery completes.

Source

pub async fn publish_to_and_wait_async( &self, message_context: MessageContext, data: Vec<u8>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<(), SlimError>

Publish a reply message and wait for completion (async version)

This method publishes a reply to a received message and waits until the delivery completes.

Source

pub fn publish_with_params( &self, destination: Arc<Name>, fanout: u32, data: Vec<u8>, connection_out: Option<u64>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<(), SlimError>

Low-level publish with full control over all parameters (blocking version for FFI)

This is an advanced method that provides complete control over routing and delivery. Most users should use publish() or publish_to() instead.

§Arguments
  • destination - Target name to send to
  • fanout - Number of copies to send (for multicast)
  • data - The message payload bytes
  • connection_out - Optional specific connection ID to use
  • payload_type - Optional content type identifier
  • metadata - Optional key-value metadata pairs
Source

pub async fn publish_with_params_async( &self, destination: Arc<Name>, fanout: u32, data: Vec<u8>, connection_out: Option<u64>, payload_type: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<(), SlimError>

Low-level publish with full control (async version)

Source

pub fn get_message( &self, timeout: Option<Duration>, ) -> Result<ReceivedMessage, SlimError>

Receive a message from the session (blocking version for FFI)

§Arguments
  • timeout - Optional timeout duration
§Returns
  • Ok(ReceivedMessage) - Message with context and payload bytes
  • Err(SlimError) - If the receive fails or times out
Source

pub async fn get_message_async( &self, timeout: Option<Duration>, ) -> Result<ReceivedMessage, SlimError>

Receive a message from the session (async version)

Source

pub fn invite( &self, participant: Arc<Name>, ) -> Result<Arc<CompletionHandle>, SlimError>

Invite a participant to the session (blocking version)

Returns a completion handle that can be awaited to ensure the invitation completes.

Source

pub async fn invite_async( &self, participant: Arc<Name>, ) -> Result<Arc<CompletionHandle>, SlimError>

Invite a participant to the session (async version)

Returns a completion handle that can be awaited to ensure the invitation completes.

Source

pub fn invite_and_wait(&self, participant: Arc<Name>) -> Result<(), SlimError>

Invite a participant and wait for completion (blocking version)

This method invites a participant and blocks until the invitation completes.

Source

pub async fn invite_and_wait_async( &self, participant: Arc<Name>, ) -> Result<(), SlimError>

Invite a participant and wait for completion (async version)

This method invites a participant and waits until the invitation completes.

Source

pub fn remove( &self, participant: Arc<Name>, ) -> Result<Arc<CompletionHandle>, SlimError>

Remove a participant from the session (blocking version)

Returns a completion handle that can be awaited to ensure the removal completes.

Source

pub async fn remove_async( &self, participant: Arc<Name>, ) -> Result<Arc<CompletionHandle>, SlimError>

Remove a participant from the session (async version)

Returns a completion handle that can be awaited to ensure the removal completes.

Source

pub fn remove_and_wait(&self, participant: Arc<Name>) -> Result<(), SlimError>

Remove a participant and wait for completion (blocking version)

This method removes a participant and blocks until the removal completes.

Source

pub async fn remove_and_wait_async( &self, participant: Arc<Name>, ) -> Result<(), SlimError>

Remove a participant and wait for completion (async version)

This method removes a participant and waits until the removal completes.

Source

pub fn destination(&self) -> Result<Name, SlimError>

Get the destination name for this session

Source

pub fn source(&self) -> Result<Name, SlimError>

Get the source name for this session

Source

pub fn session_id(&self) -> Result<u32, SlimError>

Get the session ID

Source

pub fn session_type(&self) -> Result<SessionType, SlimError>

Get the session type (PointToPoint or Group)

Source

pub fn is_initiator(&self) -> Result<bool, SlimError>

Check if this session is the initiator

Source

pub fn metadata(&self) -> Result<HashMap<String, String>, SlimError>

Get the session metadata

Source

pub fn config(&self) -> Result<SessionConfig, SlimError>

Get the session configuration

Source

pub async fn participants_list_async(&self) -> Result<Vec<Arc<Name>>, SlimError>

Get list of participants in the session

Source

pub fn participants_list(&self) -> Result<Vec<Arc<Name>>, SlimError>

Get list of participants in the session (blocking version for FFI)

Trait Implementations§

Source§

impl<UT> LiftRef<UT> for Session

Source§

impl<UT> LowerError<UT> for Session

Source§

fn lower_error(obj: Self) -> RustBuffer

Lower this value for scaffolding function return Read more
Source§

impl<UT> LowerReturn<UT> for Session

Source§

type ReturnType = <Arc<Session> as LowerReturn<UniFfiTag>>::ReturnType

The type that should be returned by scaffolding functions for this type. Read more
Source§

fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>

Lower the return value from an scaffolding call Read more
Source§

fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>

Lower the return value for failed argument lifts Read more
Source§

impl<UT> TypeId<UT> for Session

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, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more