use proc_macro2::{Ident, TokenStream};
#[derive(Debug, Clone)]
pub struct MessageType {
pub name: Ident,
pub type_annotation: Option<TokenStream>,
pub payload: Option<TokenStream>,
}
impl PartialEq for MessageType {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
&& self
.type_annotation
.as_ref()
.map(std::string::ToString::to_string)
== other
.type_annotation
.as_ref()
.map(std::string::ToString::to_string)
&& self.payload.as_ref().map(std::string::ToString::to_string)
== other.payload.as_ref().map(std::string::ToString::to_string)
}
}
impl Eq for MessageType {}
impl std::hash::Hash for MessageType {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name.hash(state);
if let Some(ref type_annotation) = self.type_annotation {
type_annotation.to_string().hash(state);
}
if let Some(ref payload) = self.payload {
payload.to_string().hash(state);
}
}
}
impl MessageType {
#[must_use]
pub fn to_ident(&self) -> Ident {
self.name.clone()
}
}