I'm trying to use the Type State Pattern to implement a server mock but am getting lost in the syntax. I have the following server code based on this tutorial for the Type State pattern:
/// Represents a PostgreSQL server.
pub struct Server<S: Messages> {
marker: std::marker::PhantomData<S>,
configuration: Configuration
}
/// Trait used to anchor message types.
pub trait Messages {}
/// Stopped server
pub enum Stopped {}
impl Messages for Stopped {}
impl Server<Stopped> {
pub fn new(configuration: Configuration) -> Self {
Server{configuration, marker: Stopped}
}
}
/// Methods available to all messages
impl<S> Server<S> where S: Messages {}
Except I can't create the new method because I have no idea what to do about the marker property. Any ideas?