pub struct WireframeClient<S = BincodeSerializer, T = TcpStream>where
T: ClientStream,{ /* private fields */ }Expand description
Client runtime for wireframe connections.
§Examples
use std::net::SocketAddr;
use wireframe::WireframeClient;
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let _client = WireframeClient::builder().connect(addr).await?;Implementations§
Source§impl WireframeClient<BincodeSerializer, TcpStream>
impl WireframeClient<BincodeSerializer, TcpStream>
Sourcepub fn builder() -> WireframeClientBuilder<BincodeSerializer, ()>
pub fn builder() -> WireframeClientBuilder<BincodeSerializer, ()>
Start building a new client with the default serializer and codec.
§Examples
use std::net::SocketAddr;
use wireframe::WireframeClient;
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let _client = WireframeClient::builder().connect(addr).await?;Source§impl<S, T> WireframeClient<S, T>
impl<S, T> WireframeClient<S, T>
Sourcepub async fn send<M: Message>(&mut self, message: &M) -> Result<(), ClientError>
pub async fn send<M: Message>(&mut self, message: &M) -> Result<(), ClientError>
Send a message to the peer using the configured serializer.
§Errors
Returns ClientError if serialization or I/O fails.
§Examples
use std::net::SocketAddr;
use wireframe::{ClientError, WireframeClient};
#[derive(bincode::Encode, bincode::BorrowDecode)]
struct Ping(u8);
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let mut client = WireframeClient::builder().connect(addr).await?;
client.send(&Ping(1)).await?;Sourcepub async fn receive<M: Message>(&mut self) -> Result<M, ClientError>
pub async fn receive<M: Message>(&mut self) -> Result<M, ClientError>
Receive the next message from the peer.
§Errors
Returns ClientError if the connection closes, decoding fails, or I/O
errors occur.
§Examples
use std::net::SocketAddr;
use wireframe::{ClientError, WireframeClient};
#[derive(bincode::Encode, bincode::BorrowDecode, Debug, PartialEq)]
struct Pong(u8);
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let mut client = WireframeClient::builder().connect(addr).await?;
let _pong: Pong = client.receive().await?;Sourcepub async fn call<Req: Message, Resp: Message>(
&mut self,
request: &Req,
) -> Result<Resp, ClientError>
pub async fn call<Req: Message, Resp: Message>( &mut self, request: &Req, ) -> Result<Resp, ClientError>
Send a message and await the next response.
§Errors
Returns ClientError if the request cannot be sent or the response
cannot be decoded.
§Examples
use std::net::SocketAddr;
use wireframe::{ClientError, WireframeClient};
#[derive(bincode::Encode, bincode::BorrowDecode)]
struct Login {
username: String,
}
#[derive(bincode::Encode, bincode::BorrowDecode, Debug, PartialEq)]
struct LoginAck {
ok: bool,
}
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let mut client = WireframeClient::builder().connect(addr).await?;
let login = Login {
username: "guest".to_string(),
};
let _ack: LoginAck = client.call(&login).await?;Sourcepub const fn codec_config(&self) -> &ClientCodecConfig
pub const fn codec_config(&self) -> &ClientCodecConfig
Inspect the configured codec settings.
§Examples
use std::net::SocketAddr;
use wireframe::{ClientError, WireframeClient};
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let client = WireframeClient::builder().connect(addr).await?;
let codec = client.codec_config();
assert_eq!(codec.max_frame_length_value(), 1024);Sourcepub fn stream(&self) -> &T
pub fn stream(&self) -> &T
Access the underlying stream.
§Examples
use std::net::SocketAddr;
use wireframe::{ClientError, WireframeClient};
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let client = WireframeClient::builder().connect(addr).await?;
let _stream = client.stream();Source§impl<S> WireframeClient<S, RewindStream<TcpStream>>
impl<S> WireframeClient<S, RewindStream<TcpStream>>
Sourcepub fn tcp_stream(&self) -> &TcpStream
pub fn tcp_stream(&self) -> &TcpStream
Sourcepub fn rewind_stream(&self) -> &RewindStream<TcpStream>
pub fn rewind_stream(&self) -> &RewindStream<TcpStream>
Access the rewind stream wrapper.
This provides access to the RewindStream that wraps the TCP stream,
which may contain leftover bytes from preamble exchange.
Trait Implementations§
Auto Trait Implementations§
impl<S, T> Freeze for WireframeClient<S, T>
impl<S, T> RefUnwindSafe for WireframeClient<S, T>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<S, T> Send for WireframeClient<S, T>
impl<S, T> Sync for WireframeClient<S, T>
impl<S, T> Unpin for WireframeClient<S, T>where
S: Unpin,
impl<S, T> UnwindSafe for WireframeClient<S, T>where
S: UnwindSafe,
T: UnwindSafe,
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