Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

A broadcast relay game server.

Create a server with Server::builder, optionally create rooms with Server::pre_create_room, then call Server::run to start accepting connections or use ServerHandle::create_room to perform at runtime, you create a daemon wrapper this way :)

use ghost_sync::Server;

let server = Server::builder()
    .bind("0.0.0.0:7777")
    .build();

// Spin up the server with an initial rooms (This is not standard, but you have freedom)
server.pre_create_room("standoff").unwrap();

let handle = server.run().await?;
// Rooms can also be managed at runtime via the handle:
// handle.create_room_runtime("match-001").unwrap();

Implementations§

Source§

impl Server

Source

pub fn builder() -> ServerBuilder

Start building a server.

Source

pub fn pre_create_room(&self, id: &str) -> Result<()>

👎Deprecated: Use ServerHandle::create_room instead, at runtime

Create a room. Call this before Server::run. (pre-run) Clients can only join rooms that have been explicitly created. Returns SyncError::RoomAlreadyExists if a room with this ID exists.

Source

pub fn pre_delete_room(&self, id: &str) -> bool

👎Deprecated: Use ServerHandle::delete_room instead, at runtime

Delete a room. Call this before Server::run. (pre-run) Returns true if the room existed.

Source

pub async fn run(self) -> Result<ServerHandle>

Start accepting connections.

Binds the TCP listener synchronously. If the bind fails, the error is returned immediately — nothing is spawned on failure.

On success, spawns the accept loop on the current runtime and returns a ServerHandle for shutdown and runtime control.

Auto Trait Implementations§

§

impl Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl !UnwindSafe for Server

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.