mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 07:24:49 +01:00
feat: added events struct
there's also quite some commented out code. I first approached the problem in a OOP way, but that's not the right way for rust. Keeping that code just to remember my vision.
This commit is contained in:
parent
18d86020c0
commit
5bb535385b
1 changed files with 89 additions and 0 deletions
89
src/server/events.rs
Normal file
89
src/server/events.rs
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
use crate::actor::state::{User, UserCursor};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum Event {
|
||||||
|
UserJoin { user: User },
|
||||||
|
UserLeave { name: String },
|
||||||
|
Cursor { user: String, cursor: UserCursor },
|
||||||
|
BufferNew { path: String },
|
||||||
|
BufferDelete { path: String },
|
||||||
|
}
|
||||||
|
|
||||||
|
// pub type Event = Box<dyn EventInterface>;
|
||||||
|
//
|
||||||
|
// pub trait EventInterface {
|
||||||
|
// fn class(&self) -> EventClass;
|
||||||
|
// fn unwrap(e: Event) -> Option<Self> where Self: Sized;
|
||||||
|
//
|
||||||
|
// fn wrap(self) -> Event {
|
||||||
|
// Box::new(self)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // User joining workspace
|
||||||
|
//
|
||||||
|
// pub struct UserJoinEvent {
|
||||||
|
// user: User,
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// impl EventInterface for UserJoinEvent {
|
||||||
|
// fn class(&self) -> EventClass { EventClass::UserJoin }
|
||||||
|
// fn unwrap(e: Event) -> Option<Self> where Self: Sized {
|
||||||
|
// if matches!(e.class(), EventClass::UserJoin) {
|
||||||
|
// return Some(*e);
|
||||||
|
// }
|
||||||
|
// None
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // User leaving workspace
|
||||||
|
//
|
||||||
|
// pub struct UserLeaveEvent {
|
||||||
|
// name: String,
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// impl EventInterface for UserLeaveEvent {
|
||||||
|
// fn class(&self) -> EventClass { EventClass::UserLeave }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // Cursor movement
|
||||||
|
//
|
||||||
|
// pub struct CursorEvent {
|
||||||
|
// user: String,
|
||||||
|
// cursor: UserCursor,
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// impl EventInterface for CursorEvent {
|
||||||
|
// fn class(&self) -> EventClass { EventClass::Cursor }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// impl CursorEvent {
|
||||||
|
// pub fn new(user:String, cursor: UserCursor) -> Self {
|
||||||
|
// CursorEvent { user, cursor }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // Buffer added
|
||||||
|
//
|
||||||
|
// pub struct BufferNewEvent {
|
||||||
|
// path: String,
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// impl EventInterface for BufferNewEvent {
|
||||||
|
// fn class(&self) -> EventClass { EventClass::BufferNew }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // Buffer deleted
|
||||||
|
//
|
||||||
|
// pub struct BufferDeleteEvent {
|
||||||
|
// path: String,
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// impl EventInterface for BufferDeleteEvent {
|
||||||
|
// fn class(&self) -> EventClass { EventClass::BufferDelete }
|
||||||
|
// }
|
Loading…
Reference in a new issue