pub struct Hub { /* private fields */ }
Expand description
Client-side hub
Hub
can be called by the server. It currently supports only value-like arguments - ones that can be deserialized from a single message.
There are also stream-like arguments - ones that server can stream to client asynchronously, but they are not supported yet.
use signalrs_client::SignalRClient;
use signalrs_client::hub::Hub;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let hub = Hub::default().method("Send", print);
let client = SignalRClient::builder("localhost")
.use_port(8080)
.use_hub("echo")
.with_client_hub(hub)
.build()
.await?;
}
// Hub methods need to be async
async fn print(message: String) {
println!("{message}");
}
Implementations§
Source§impl Hub
impl Hub
Sourcepub fn method<M, Args>(self, name: impl ToString, method: M) -> Self
pub fn method<M, Args>(self, name: impl ToString, method: M) -> Self
Embeds a new method in a hub under name
.
Any server calls to a method of name
will be routed to function pointed to by method
.
Only functions returning ()
and async
are allowed.
Up to 13 arguments are supported. They will be extracted from server call.
In case extraction fails, error will be logged.
All primitive arguments should be usable out of the box. In case custom one needs to be used see HubArgument
.
Value-like hub arguments need to implement Deserialize
as well.
§Example
use serde::Deserialize;
use signalrs_derive::HubArgument;
#[derive(Deserialize, HubArgument)]
struct Data {
f1: i32,
f2: String
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Hub
impl !RefUnwindSafe for Hub
impl Send for Hub
impl Sync for Hub
impl Unpin for Hub
impl !UnwindSafe for Hub
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