1
0
Fork 0
forked from wry/wry
wry/src/ei/ei_object.rs

66 lines
1.4 KiB
Rust

use {
crate::{
ei::{
EiContext,
ei_client::{EiClient, EiClientError},
},
utils::buffd::EiMsgParser,
wire_ei::EiHandshakeId,
},
std::{
cmp::Ordering,
rc::Rc,
},
};
pub use jay_wire_types::EiObjectId;
pub const EI_HANDSHAKE_ID: EiHandshakeId = EiHandshakeId::from_raw(0);
pub trait EiObjectBase {
fn id(&self) -> EiObjectId;
fn version(&self) -> EiVersion;
fn client(&self) -> &EiClient;
fn handle_request(
self: Rc<Self>,
client: &EiClient,
request: u32,
parser: EiMsgParser<'_, '_>,
) -> Result<(), EiClientError>;
fn interface(&self) -> EiInterface;
}
pub trait EiObject: EiObjectBase + 'static {
fn break_loops(&self) {}
fn context(&self) -> EiContext {
self.client().context.get()
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct EiInterface(pub &'static str);
impl EiInterface {
pub fn name(self) -> &'static str {
self.0
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct EiVersion(pub u32);
impl EiVersion {
// pub const ALL: EiVersion = EiVersion(0);
}
impl PartialEq<u32> for EiVersion {
fn eq(&self, other: &u32) -> bool {
self.0 == *other
}
}
impl PartialOrd<u32> for EiVersion {
fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
self.0.partial_cmp(other)
}
}