Enum HostSide
pub enum HostSide<'a> {
Server(&'a mut dyn ServerHost),
Client(&'a mut dyn ClientHost),
}Expand description
The logical side of a hook’s host.
Variants§
Server(&'a mut dyn ServerHost)
The hook fired on the server.
Client(&'a mut dyn ClientHost)
The hook fired on the client.
Implementations§
§impl HostSide<'_>
The logical side on which a hook is executing.
impl HostSide<'_>
The logical side on which a hook is executing.
A mutable client hook can use client services:
use mod_api::{self, ClientHost, Hooks, InputKeyEvent};
#[derive(Default)]
struct ScreenMod;
#[mod_api::horizon_mod]
impl Hooks for ScreenMod {
fn input_key(&self, host: &mut dyn ClientHost, _: &mut InputKeyEvent<'_>) {
host.mod_screen_open("example");
}
}A hook that fires on both sides matches on the two:
use mod_api::HostSide;
fn side(host: HostSide<'_>) -> &'static str {
match host { HostSide::Server(_) => "server", HostSide::Client(_) => "client" }
}Wrong-side services do not compile:
ⓘ
use mod_api::Host;
fn wrong(host: &dyn Host) { host.messages().broadcast(todo!()); }ⓘ
use mod_api::LevelHost;
fn wrong(host: &dyn LevelHost) { host.players().server_players(); }ⓘ
use mod_api::ClientHost;
fn wrong(host: &mut dyn ClientHost) { host.commands().run_command("list"); }ⓘ
use mod_api::ServerHost;
fn wrong(host: &mut dyn ServerHost) { host.mod_screen_open("example"); }A read-only hook receives only the base host, which cannot be used for a server or client operation, or opened as a backend by a mod:
ⓘ
use mod_api::{Host, ServerHost};
fn server(_: &mut dyn ServerHost) {}
fn read(host: &dyn Host) { server(host); }ⓘ
use mod_api::{ClientHost, Host};
fn client(_: &dyn ClientHost) {}
fn read(host: &dyn Host) { client(host); }ⓘ
use mod_api::{Host, ServerHost};
fn read(host: &dyn Host) { let _ = host.downcast_ref::<dyn ServerHost>(); }Auto Trait Implementations§
impl<'a> !RefUnwindSafe for HostSide<'a>
impl<'a> !Send for HostSide<'a>
impl<'a> !Sync for HostSide<'a>
impl<'a> !UnwindSafe for HostSide<'a>
impl<'a> Freeze for HostSide<'a>
impl<'a> Unpin for HostSide<'a>
impl<'a> UnsafeUnpin for HostSide<'a>
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