Skip to content

Commit

Permalink
Assert UTransport implementations to be thread-safe
Browse files Browse the repository at this point in the history
Most UTransport implementations will be implemented in a way that allows them to be invoked from multiple threads already. It therefore seems reasonable to let the UTransport trait extend Send + Sync to let client code rely on this fact.
  • Loading branch information
AnotherDaniel authored Apr 8, 2024
1 parent cef225b commit f912460
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/rpc/rpcclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use crate::{CallOptions, RpcMapperError, UMessage, UPayload, UUri};
pub type RpcClientResult = Result<UMessage, RpcMapperError>;

/// `RpcClient` is an interface used by code generators for uProtocol services defined in `.proto` files such as
/// the core uProtocol services found in [uProtocol Core API](https://github.com/eclipse-uprotocol/uprotocol-core-api).
/// the core uProtocol services found in [uProtocol Core API](https://github.com/eclipse-uprotocol/up-spec/tree/main/up-core-api).
///
/// The trait provides a clean contract for mapping a RPC requiest to a response. For more details please refer to the
/// [RpcClient Specifications](https://github.com/eclipse-uprotocol/uprotocol-spec/blob/main/up-l2/README.adoc).
/// [RpcClient Specifications](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l2/rpcclient.adoc).
#[async_trait]
pub trait RpcClient {
pub trait RpcClient: Send + Sync {
/// Invokes a method on a remote service asynchronously.
///
/// This function is an API for clients to send an RPC request and receive a response.
Expand Down
9 changes: 4 additions & 5 deletions src/utransport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use crate::{UMessage, UStatus, UUri};
///
/// Implementations of `UListener` contain the details for what should occur when a message is received
///
/// For more information, please refer to
/// [uProtocol Specification](https://github.com/eclipse-uprotocol/uprotocol-spec/blob/main/up-l1/README.adoc).
/// For more information, please refer to [uProtocol Specification](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l1/README.adoc).
///
/// # Examples
///
Expand Down Expand Up @@ -86,7 +85,7 @@ use crate::{UMessage, UStatus, UUri};
/// }
/// ```
#[async_trait]
pub trait UListener: 'static + Send + Sync {
pub trait UListener: Send + Sync {
/// Performs some action on receipt of a message
///
/// # Parameters
Expand Down Expand Up @@ -128,9 +127,9 @@ pub trait UListener: 'static + Send + Sync {
///
/// Implementations of [`UTransport`] contain the details for connecting to the underlying transport technology and
/// sending [`UMessage`][crate::UMessage] using the configured technology. For more information, please refer to
/// [uProtocol Specification](https://github.com/eclipse-uprotocol/uprotocol-spec/blob/main/up-l1/README.adoc).
/// [uProtocol Specification](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l1/README.adoc).
#[async_trait]
pub trait UTransport {
pub trait UTransport: Send + Sync {
/// Sends a message using this transport's message exchange mechanism.
///
/// # Arguments
Expand Down

0 comments on commit f912460

Please sign in to comment.