pub struct OriginSdk { /* private fields */ }Expand description
The client for interacting with the Origin SDK protocol.
Implementations§
Source§impl OriginSdk
impl OriginSdk
Sourcepub async fn connect(
config: ClientConfig,
port: u16,
) -> Result<(Self, Receiver<Event>), SdkError>
pub async fn connect( config: ClientConfig, port: u16, ) -> Result<(Self, Receiver<Event>), SdkError>
Establish a connection to the Origin SDK server
Returns a tuple of:
- The
OriginSdkclient instance - An
mpsc::Receiverfor incomingEvents
Sourcepub async fn send_request<T>(&self, body: T) -> Result<T::Response, SdkError>
pub async fn send_request<T>(&self, body: T) -> Result<T::Response, SdkError>
Send a typed request to the server and await its response.
§How requests & responses are defined
All request types are declared under crate::protocol and grouped by domain
(achievements.rs, auth.rs, chat.rs, etc). Each request type implements
RequestResponse, which is generated by the crate::request_response! macro.
This macro wires requests to their corresponding response body variants
in ResponseBody. For example:
ⓘ
pub enum RequestBody {
// ...
GetProfile(GetProfile)
// ...
}
pub enum ResponseBody {
// ...
GetProfileResponse(GetProfileResponse),
// ...
}
request_response! {
// ...
GetProfile => GetProfileResponse,
// ...
}This means calling:
ⓘ
let profile: GetProfileResponse = client.send_request(GetProfile { /* ... */ }).await?;automatically deserializes the server response into the correct type.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for OriginSdk
impl !RefUnwindSafe for OriginSdk
impl Send for OriginSdk
impl Sync for OriginSdk
impl Unpin for OriginSdk
impl !UnwindSafe for OriginSdk
Blanket Implementations§
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
Mutably borrows from an owned value. Read more