mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +08:00
`/client/web` -> `/frontend` `/client/cli` -> *delete for now* `/client/native` -> *delete for now* `/core/editor` -> `/editor` `/core/document` -> `/graphene` `/core/renderer` -> `/charcoal` `/core/proc-macro` -> `/proc-macros` *(now plural)*
56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
use crate::message_prelude::*;
|
|
use graphite_proc_macros::*;
|
|
use std::{
|
|
collections::hash_map::DefaultHasher,
|
|
hash::{Hash, Hasher},
|
|
};
|
|
|
|
pub trait AsMessage: TransitiveChild
|
|
where
|
|
Self::TopParent: TransitiveChild<Parent = Self::TopParent, TopParent = Self::TopParent> + AsMessage,
|
|
{
|
|
fn local_name(self) -> String;
|
|
fn global_name(self) -> String {
|
|
<Self as Into<Self::TopParent>>::into(self).local_name()
|
|
}
|
|
}
|
|
|
|
#[impl_message]
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub enum Message {
|
|
NoOp,
|
|
#[child]
|
|
Documents(DocumentsMessage),
|
|
#[child]
|
|
Global(GlobalMessage),
|
|
#[child]
|
|
Tool(ToolMessage),
|
|
#[child]
|
|
Frontend(FrontendMessage),
|
|
#[child]
|
|
InputPreprocessor(InputPreprocessorMessage),
|
|
#[child]
|
|
InputMapper(InputMapperMessage),
|
|
}
|
|
|
|
impl Message {
|
|
/// Returns the byte representation of the message.
|
|
///
|
|
/// # Safety
|
|
/// This function reads from uninitialized memory!!!
|
|
/// Only use if you know what you are doing
|
|
unsafe fn as_slice(&self) -> &[u8] {
|
|
core::slice::from_raw_parts(self as *const Message as *const u8, std::mem::size_of::<Message>())
|
|
}
|
|
/// Returns a pseudo hash that should uniquely identify the message.
|
|
/// This is needed because `Hash` is not implemented for f64s
|
|
///
|
|
/// # Safety
|
|
/// This function reads from uninitialized memory but the generated value should be fine.
|
|
pub fn pseudo_hash(&self) -> u64 {
|
|
let mut s = DefaultHasher::new();
|
|
unsafe { self.as_slice() }.hash(&mut s);
|
|
s.finish()
|
|
}
|
|
}
|