I'm making an OOP chat client in Rust. The module messages.rs creates and handles messages to other modules as structs: SimpleMessage
and ComplexMessage
structs:
//! # Messages
use time::SteadyTime;
/// Represents a simple text message
pub struct SimpleMessage<'a> {
pub user: ...
pub time: &'a SteadyTime<'a>,
pub content: &'a str,
}
/// Represents attachments, like text or multimedia files.
pub struct ComplexMessage<'a> {
pub user: ...
pub time: &'a SteadyTime<'a>,
//pub content: PENDING
}
impl<'a> SimpleMessage<'a> { }
impl<'a> ComplexMessage<'a> { }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_simple() {
assert_eq!(&self.instance_of(), SimpleMessage);
}
#[test]
fn is_complex() {
assert_eq!(&self.instance_of(), ComplexMessage);
}
}
I'm troubled finding a Java-like function such as InstanceOf()
for structs, that would potentially work like:
&self.instance_of() -> str
This would be used to process a ComplexMessage
different from a SimpleMessage
in a GUI, adding a preview and download button for the ComplexMessage
.
Any ideas?