Struct Host

Source
pub struct Host<StepT>
where StepT: Clone + Debug + Eq + Deserialize + Serialize + Display,
{ /* private fields */ }
Expand description

The main host structure managing game logic and client connections.

Host handles the game session, processes client commands, and manages the state of each connection.

§Type Parameters

  • StepT: The type representing a step in the game logic. Must implement Clone, Debug, Eq, Deserialize, Serialize, and Display.

Implementations§

Source§

impl<StepT> Host<StepT>
where StepT: Clone + Deserialize + Serialize + Eq + Debug + Display,

Source

pub fn new(app_version: Version, tick_id: TickId) -> Host<StepT>

Creates a new Host instance with the specified application version and initial tick ID.

§Arguments
  • app_version - The version of the application.
  • tick_id - The initial tick identifier.
Source

pub const fn debug_logic(&self) -> &HostLogic<StepT>

Returns a reference to the internal HostLogic for debugging purposes.

Source

pub fn debug_get_logic( &self, connection_id: HostConnectionId, ) -> Option<&Connection<StepT>>

Retrieves a specific connection’s logic by its connection ID for debugging purposes.

Source

pub const fn session(&self) -> &GameSession<StepT>

Returns a reference to the current game session.

Source

pub fn update( &mut self, connection_id: HostConnectionId, now: Millis, datagram: &[u8], state_provider: &impl GameStateProvider, ) -> Result<Vec<Vec<u8>>, HostError>

Updates the host state based on incoming datagrams from a client.

Processes the datagram, updates game logic, and prepares outgoing datagrams to be sent back to the client.

§Arguments
  • connection_id - The ID of the connection sending the datagram.
  • now - The current time in milliseconds.
  • datagram - The incoming datagram data.
  • state_provider - A reference to an implementation providing game state if needed.
§Returns

A Result containing a vector of outgoing datagrams or a HostError on failure.

§Errors

HostError TODO:

Source

pub fn get(&self, connection_id: HostConnectionId) -> Option<&HostConnection>

Retrieves a reference to a HostConnection by its connection ID.

§Arguments
  • connection_id - The ID of the connection to retrieve.
Source

pub fn create_connection(&mut self) -> Option<HostConnectionId>

Creates a new connection and adds it to the host.

§Returns

An Option containing the new HostConnectionId if successful, or None if the connection could not be created.

Source

pub fn destroy_connection( &mut self, connection_id: HostConnectionId, ) -> Result<(), HostError>

Destroys an existing connection and removes it from the host.

§Arguments
  • connection_id - The ID of the connection to destroy.
§Errors

Returns a HostError if the connection could not be found or destroyed.

Auto Trait Implementations§

§

impl<StepT> Freeze for Host<StepT>

§

impl<StepT> !RefUnwindSafe for Host<StepT>

§

impl<StepT> !Send for Host<StepT>

§

impl<StepT> !Sync for Host<StepT>

§

impl<StepT> Unpin for Host<StepT>
where StepT: Unpin,

§

impl<StepT> !UnwindSafe for Host<StepT>

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, 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.