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
impl Session
Sourcepub 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>
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.
Sourcepub async fn publish_to_internal(
&self,
message_ctx: &MessageContext,
blob: Vec<u8>,
payload_type: Option<String>,
metadata: Option<HashMap<String, String>>,
) -> Result<SlimCompletionHandle, SessionError>
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.
Sourcepub async fn invite_internal(
&self,
destination: &SlimName,
) -> Result<SlimCompletionHandle, SessionError>
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.
Sourcepub async fn remove_internal(
&self,
destination: &SlimName,
) -> Result<SlimCompletionHandle, SessionError>
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.
Sourcepub async fn get_session_message(
&self,
timeout: Option<Duration>,
) -> Result<(MessageContext, Vec<u8>), SessionError>
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
impl Session
Sourcepub fn publish(
&self,
data: Vec<u8>,
payload_type: Option<String>,
metadata: Option<HashMap<String, String>>,
) -> Result<Arc<CompletionHandle>, SlimError>
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 bytespayload_type- Optional content type identifiermetadata- Optional key-value metadata pairs
§Returns
Ok(CompletionHandle)- Handle to await delivery confirmationErr(SlimError)- If publishing fails
§Example
let completion = session.publish(data, None, None)?;
completion.wait()?; // Blocks until message is deliveredSourcepub async fn publish_async(
&self,
data: Vec<u8>,
payload_type: Option<String>,
metadata: Option<HashMap<String, String>>,
) -> Result<Arc<CompletionHandle>, SlimError>
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.
Sourcepub fn publish_and_wait(
&self,
data: Vec<u8>,
payload_type: Option<String>,
metadata: Option<HashMap<String, String>>,
) -> Result<(), SlimError>
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.
Sourcepub async fn publish_and_wait_async(
&self,
data: Vec<u8>,
payload_type: Option<String>,
metadata: Option<HashMap<String, String>>,
) -> Result<(), SlimError>
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.
Sourcepub fn publish_to(
&self,
message_context: MessageContext,
data: Vec<u8>,
payload_type: Option<String>,
metadata: Option<HashMap<String, String>>,
) -> Result<Arc<CompletionHandle>, SlimError>
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 viaget_message()data- The reply payload bytespayload_type- Optional content type identifiermetadata- Optional key-value metadata pairs
§Returns
Ok(CompletionHandle)- Handle to await delivery confirmationErr(SlimError)- If publishing fails
Sourcepub 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>
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.
Sourcepub fn publish_to_and_wait(
&self,
message_context: MessageContext,
data: Vec<u8>,
payload_type: Option<String>,
metadata: Option<HashMap<String, String>>,
) -> Result<(), SlimError>
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.
Sourcepub 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>
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.
Sourcepub 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>
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 tofanout- Number of copies to send (for multicast)data- The message payload bytesconnection_out- Optional specific connection ID to usepayload_type- Optional content type identifiermetadata- Optional key-value metadata pairs
Sourcepub 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>
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)
Sourcepub fn get_message(
&self,
timeout: Option<Duration>,
) -> Result<ReceivedMessage, SlimError>
pub fn get_message( &self, timeout: Option<Duration>, ) -> Result<ReceivedMessage, SlimError>
Sourcepub async fn get_message_async(
&self,
timeout: Option<Duration>,
) -> Result<ReceivedMessage, SlimError>
pub async fn get_message_async( &self, timeout: Option<Duration>, ) -> Result<ReceivedMessage, SlimError>
Receive a message from the session (async version)
Sourcepub fn invite(
&self,
participant: Arc<Name>,
) -> Result<Arc<CompletionHandle>, SlimError>
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.
Sourcepub async fn invite_async(
&self,
participant: Arc<Name>,
) -> Result<Arc<CompletionHandle>, SlimError>
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.
Sourcepub fn invite_and_wait(&self, participant: Arc<Name>) -> Result<(), SlimError>
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.
Sourcepub async fn invite_and_wait_async(
&self,
participant: Arc<Name>,
) -> Result<(), SlimError>
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.
Sourcepub fn remove(
&self,
participant: Arc<Name>,
) -> Result<Arc<CompletionHandle>, SlimError>
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.
Sourcepub async fn remove_async(
&self,
participant: Arc<Name>,
) -> Result<Arc<CompletionHandle>, SlimError>
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.
Sourcepub fn remove_and_wait(&self, participant: Arc<Name>) -> Result<(), SlimError>
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.
Sourcepub async fn remove_and_wait_async(
&self,
participant: Arc<Name>,
) -> Result<(), SlimError>
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.
Sourcepub fn destination(&self) -> Result<Name, SlimError>
pub fn destination(&self) -> Result<Name, SlimError>
Get the destination name for this session
Sourcepub fn session_id(&self) -> Result<u32, SlimError>
pub fn session_id(&self) -> Result<u32, SlimError>
Get the session ID
Sourcepub fn session_type(&self) -> Result<SessionType, SlimError>
pub fn session_type(&self) -> Result<SessionType, SlimError>
Get the session type (PointToPoint or Group)
Sourcepub fn is_initiator(&self) -> Result<bool, SlimError>
pub fn is_initiator(&self) -> Result<bool, SlimError>
Check if this session is the initiator
Sourcepub fn config(&self) -> Result<SessionConfig, SlimError>
pub fn config(&self) -> Result<SessionConfig, SlimError>
Get the session configuration
Trait Implementations§
Source§impl<UT> LowerError<UT> for Session
impl<UT> LowerError<UT> for Session
Source§fn lower_error(obj: Self) -> RustBuffer
fn lower_error(obj: Self) -> RustBuffer
Source§impl<UT> LowerReturn<UT> for Session
impl<UT> LowerReturn<UT> for Session
Source§type ReturnType = <Arc<Session> as LowerReturn<UniFfiTag>>::ReturnType
type ReturnType = <Arc<Session> as LowerReturn<UniFfiTag>>::ReturnType
Source§fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
Source§fn handle_failed_lift(
error: LiftArgsError,
) -> Result<Self::ReturnType, RustCallError>
fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>
Auto Trait Implementations§
impl !Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl !UnwindSafe for Session
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request