Struct ClientConfig

Source
pub struct ClientConfig<Ctx> { /* private fields */ }
Expand description

Configuration for a client.

  • num_disconnect_packets - The number of redundant disconnect packets that will be sent to a server when the clients wants to disconnect.
  • packet_send_rate - The rate at which periodic packets will be sent to the server.
  • on_state_change - A callback that will be called when the client changes states.

§Example

use netcode::{Client, ClientConfig, ClientState};

let cfg = ClientConfig::with_context(MyContext {})
    .num_disconnect_packets(10)
    .packet_send_rate(0.1)
    .on_state_change(|from, to, _ctx| {
    if let (ClientState::SendingChallengeResponse, ClientState::Connected) = (from, to) {
       println!("client connected to server");
    }
});
let mut client = Client::with_config(&token_bytes, cfg).unwrap();
client.connect();

Implementations§

Source§

impl<Ctx> ClientConfig<Ctx>

Source

pub fn new() -> ClientConfig<()>

Create a new, default client configuration with no context.

Source

pub fn with_context(ctx: Ctx) -> Self

Create a new client configuration with context that will be passed to the callbacks.

Source

pub fn num_disconnect_packets(self, num_disconnect_packets: usize) -> Self

Set the number of redundant disconnect packets that will be sent to a server when the clients wants to disconnect. The default is 10 packets.

Source

pub fn packet_send_rate(self, rate_seconds: f64) -> Self

Set the rate at which periodic packets will be sent to the server. The default is 10 packets per second. (0.1 seconds)

Source

pub fn on_state_change<F>(self, cb: F) -> Self
where F: FnMut(ClientState, ClientState, &mut Ctx) + Send + Sync + 'static,

Set a callback that will be called when the client changes states.

Trait Implementations§

Source§

impl Default for ClientConfig<()>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Ctx> Freeze for ClientConfig<Ctx>
where Ctx: Freeze,

§

impl<Ctx> !RefUnwindSafe for ClientConfig<Ctx>

§

impl<Ctx> Send for ClientConfig<Ctx>
where Ctx: Send,

§

impl<Ctx> Sync for ClientConfig<Ctx>
where Ctx: Sync,

§

impl<Ctx> Unpin for ClientConfig<Ctx>
where Ctx: Unpin,

§

impl<Ctx> !UnwindSafe for ClientConfig<Ctx>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.