pub struct Client { /* private fields */ }Expand description
High-level client with automatic message handling
This is a simplified wrapper around aerox_client::HighLevelClient that provides
a cleaner API for common client operations.
§Example
ⓘ
use aerox::Client;
#[tokio::main]
async fn main() -> aerox::Result<()> {
let mut client = Client::connect("127.0.0.1:8080").await?;
// Register message handler
client.on_message(1001, |id, msg: MyMessage| async move {
println!("Received: {:?}", msg);
Ok(())
}).await?;
// Send message
client.send(1001, &my_message).await?;
Ok(())
}Implementations§
Source§impl Client
impl Client
Sourcepub async fn on_message<M, F>(&mut self, msg_id: u16, f: F) -> Result<()>
pub async fn on_message<M, F>(&mut self, msg_id: u16, f: F) -> Result<()>
Sourcepub async fn send<M: Message>(&mut self, msg_id: u16, msg: &M) -> Result<()>
pub async fn send<M: Message>(&mut self, msg_id: u16, msg: &M) -> Result<()>
Send a message
§Arguments
msg_id- Message IDmsg- Message to send (must implementprost::Message)
§Example
ⓘ
client.send(1001, &my_message).await?;Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Sourcepub fn inner(&self) -> &InnerClient
pub fn inner(&self) -> &InnerClient
Get the inner client for advanced use cases
Sourcepub fn inner_mut(&mut self) -> &mut InnerClient
pub fn inner_mut(&mut self) -> &mut InnerClient
Get a mutable reference to the inner client for advanced use cases
Sourcepub fn into_inner(self) -> InnerClient
pub fn into_inner(self) -> InnerClient
Consume and return the inner client
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.