“IS THE SLEIGH PARKED, READY, OR FLYING? WHY DOESN’T ANYONE KNOW?”
“Uh… shouldn’t you know? Didn't we use the type state pattern?” Bernard spoke up.
Santa's face twitched. "Of course, we used the type state pattern! But does anyone have a quick way to check the state right now? There are some sleighs in the air, it's hard to keep track on all of them."
Blitzen, lounging in a corner, snorted. “Sounds like y'all need to add a status()
method.”
Prancer’s ears perked up. “Yeah! A single method we can call to figure out the state, no matter which one it’s in.”
Santa stroked his beard, muttering. “Fine. Add it. And make sure it’s compile-time safe. If I get a wrong answer, someone’s spending Christmas hand-delivering packets in binary.”
It's time to give Santa what he wants: a single status()
method that works in all states of the sleigh (Empty
, Ready
, and Flying
), returning the current state as a string.
Here's the plan:
status()
method: It should be callable on the Sleigh
regardless of its state."Empty"
when the sleigh is empty."Ready"
when the sleigh is loaded and ready to fly."Flying"
when the sleigh is in the air.Sleigh
struct should have a trait bound, not just a generic <T>
.Here's how Santa wants to the the API:
let sleigh = Sleigh::new();
assert_eq!(sleigh.status(), "Empty");
sleigh.load();
assert_eq!(sleigh.status(), "Ready");
sleigh.take_off();
assert_eq!(sleigh.status(), "Flying");
If you’re unsure where to start, take a look at these tips:
Use a trait to define shared behavior across all states. For example:
pub trait State {
fn status() -> &'static str;
}
Implement the trait for each state. e.g.
impl State for Empty {
fn status() -> &'static str {
"Empty"
}
}
Implement a method for all types that implement the State
trait. e.g.
impl<T: State> Sleigh<T> {
pub fn status(&self) -> &'static str {
T::status()
}
}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait State { fn status() -> &'static str;}pub struct Sleigh<T: State> { pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl State for Empty { fn status() -> &'static str { "Empty" }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl State for Empty { fn status() -> &'static str { "Empty" }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl State for Flying { fn status() -> &'static str { "Flying" }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State{ fn status() -> &'static str;}impl State for Empty{ fn status() -> &'static str { "Empty" }}impl State for Ready{ fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" } }pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait State { fn status() -> &'static str; }impl State for Empty { fn status() -> &'static str { "Empty" } }impl State for Ready { fn status() -> &'static str { "Ready" } }impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait State { fn status() -> &'static str; }impl State for Empty { fn status() -> &'static str { "Empty" } }impl State for Ready { fn status() -> &'static str { "Ready" } }impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait Status { fn status(&self) -> &'static str;}impl Status for Empty { fn status(&self) -> &'static str { "Empty" }}impl Status for Ready { fn status(&self) -> &'static str { "Ready" }}impl Status for Flying { fn status(&self) -> &'static str { "Flying" }}pub struct Sleigh<T: Status> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } } pub fn status(&self) -> &'static str { Empty.status() }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } } pub fn status(&self) -> &'static str { Ready.status() }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } } pub fn status(&self) -> &'static str { Flying.status() }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait SleighState { fn status() -> &'static str;}impl SleighState for Empty { fn status() -> &'static str { "Empty" }}impl SleighState for Ready { fn status() -> &'static str { "Ready" }}impl SleighState for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: SleighState> { pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}// Add a `status` method for all `Sleigh` instancesimpl<T: SleighState> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}
use std::marker::PhantomData;pub trait SleighStatus { fn status<'a>() -> &'a str;}pub struct Empty;pub struct Ready;pub struct Flying;impl SleighStatus for Empty { fn status<'a>() -> &'a str { "Empty" }}impl SleighStatus for Ready { fn status<'a>() -> &'a str { "Ready" }}impl SleighStatus for Flying { fn status<'a>() -> &'a str { "Flying"}}// TODO: Define the `status` method for all statespub struct Sleigh<T: SleighStatus> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: SleighStatus> Sleigh<T> { pub fn status<'a>(&self) -> &'a str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub trait SelighStatus { fn status() -> String;}pub struct Empty;pub struct Ready;pub struct Flying;impl SelighStatus for Empty { fn status() -> String { "Empty".to_string() }}impl SelighStatus for Ready { fn status() -> String { "Ready".to_string() }}impl SelighStatus for Flying { fn status() -> String { "Flying".to_string() }}// TODO: Define the `status` method for all statespub struct Sleigh<T: SelighStatus> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: SelighStatus> Sleigh<T> { pub fn status(&self) -> String { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait Status { fn status(&self) -> &'static str;}impl Status for Empty { fn status(&self) -> &'static str { "Empty" }}impl Status for Ready { fn status(&self) -> &'static str { "Ready" }}impl Status for Flying { fn status(&self) -> &'static str { "Flying" }}// TODO: Define the `status` method for all statespub struct Sleigh<T: Status> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } } pub fn status(&self) -> &'static str { Empty.status() }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } } pub fn status(&self) -> &'static str { Ready.status() }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } } pub fn status(&self) -> &'static str { Flying.status() }}//
use std::marker::PhantomData;// Define the state structspub struct Empty;pub struct Ready;pub struct Flying;// Define the `State` trait with a `status` methodtrait State { fn status() -> &'static str;}// Implement `State` trait for each stateimpl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}// Define the `Sleigh` struct with a generic statepub struct Sleigh<T: State> { state: PhantomData<T>,}// Implement methods for `Sleigh` in any stateimpl<T: State> Sleigh<T> { /// Returns the current status of the sleigh pub fn status(&self) -> &'static str { T::status() }}// Implement methods specific to the `Empty` stateimpl Sleigh<Empty> { /// Creates a new sleigh in the `Empty` state pub fn new() -> Self { Self { state: PhantomData } } /// Transitions the sleigh to the `Ready` state pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}// Implement methods specific to the `Ready` stateimpl Sleigh<Ready> { /// Transitions the sleigh to the `Flying` state pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } /// Transitions the sleigh back to the `Empty` state pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}// Implement methods specific to the `Flying` stateimpl Sleigh<Flying> { /// Transitions the sleigh back to the `Ready` state pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}// TODO: Define the `status` method for all statespub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub trait State { fn status() -> &'static str;}pub struct Empty;pub struct Ready;pub struct Flying;impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait SleighState { const LABEL: &'static str;}impl SleighState for Empty { const LABEL: &'static str = "Empty";}impl SleighState for Ready { const LABEL: &'static str = "Ready";}impl SleighState for Flying { const LABEL: &'static str = "Flying";}pub struct Sleigh<T: SleighState> { pub state: PhantomData<T>,}impl<T: SleighState> Sleigh<T> { pub fn status(&self) -> &'static str { T::LABEL }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}pub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T> { // This is only public for testing purposes // In real-world scenarios, this should be private state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait State { fn status() -> &'static str;}// TODO: Define the `status` method for all statesimpl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T> { state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub trait State { fn status() -> &'static str;}pub struct Empty;impl State for Empty { fn status() -> &'static str { "Empty" }}pub struct Ready;impl State for Ready { fn status() -> &'static str { "Ready" }}pub struct Flying;impl State for Flying { fn status() -> &'static str { "Flying" }}// TODO: Define the `status` method for all statespub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}// TODO: Define the `status` method for all statespub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}pub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait Statusable { fn status() -> &'static str;}impl Statusable for Empty { fn status() -> &'static str { "Empty" }}impl Statusable for Ready { fn status() -> &'static str { "Ready" }}impl Statusable for Flying { fn status() -> &'static str { "Flying" }}// TODO: Define the `status` method for all statesimpl<T: Statusable> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T: Statusable> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } } }impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;pub trait Statusable { fn status() -> &'static str;}impl Statusable for Empty { fn status() -> &'static str { "Empty" }}impl Statusable for Ready { fn status() -> &'static str { "Ready" }}impl Statusable for Flying { fn status() -> &'static str { "Flying" }}// TODO: Define the `status` method for all statespub struct Sleigh<T: Statusable> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } } pub fn status(&self) -> String { Empty::status().to_string() }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } } pub fn status(&self) -> String { Ready::status().to_string() }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } } pub fn status(&self) -> String { Flying::status().to_string() }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub struct Sleigh<T:Stateful> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}pub trait Stateful { fn status() -> &'static str;}impl Stateful for Empty { fn status() -> &'static str { "Empty" }}impl Stateful for Ready { fn status() -> &'static str { "Ready" }}impl Stateful for Flying { fn status() -> &'static str { "Flying" }}impl<T: Stateful> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub struct Sleigh<T:Stateful> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}pub trait Stateful { fn status() -> &'static str;}impl Stateful for Empty { fn status() -> &'static str { "Empty" }}impl Stateful for Ready { fn status() -> &'static str { "Ready" }}impl Stateful for Flying { fn status() -> &'static str { "Flying" }}impl<T: Stateful> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub struct Sleigh<T:Stateful> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}pub trait Stateful { fn status() -> &'static str;}impl Stateful for Empty { fn status() -> &'static str { "Empty" }}impl Stateful for Ready { fn status() -> &'static str { "Ready" }}impl Stateful for Flying { fn status() -> &'static str { "Flying" }}impl<T: Stateful> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}pub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait Status { fn status() -> &'static str;}pub struct Sleigh<T: Status> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: Status> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Status for Empty { fn status() -> &'static str{ "Empty" }}impl Status for Flying { fn status() -> &'static str{ "Flying" }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Status for Ready { fn status() -> &'static str{ "Ready" }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl <T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }} impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statestrait Status { fn status() -> &'static str;}impl Status for Empty { fn status() -> &'static str { "Empty" }}impl Status for Ready { fn status() -> &'static str { "Ready" }}impl Status for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: Status> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: Status> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}pub trait State { fn status() -> &'static str;}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}fn main() { println!("{}", Sleigh::new().status()); println!("{}", Sleigh::new().load().status()); println!("{}", Sleigh::new().load().take_off().status());}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}
use std::marker::PhantomData;pub struct Empty;pub struct Ready;pub struct Flying;// TODO: Define the `status` method for all statespub trait State { fn status() -> &'static str;}impl State for Empty { fn status() -> &'static str { "Empty" }}impl State for Ready { fn status() -> &'static str { "Ready" }}impl State for Flying { fn status() -> &'static str { "Flying" }}pub struct Sleigh<T: State> { // This is only public for testing purposes // In real-world scenarios, this should be private pub state: PhantomData<T>,}impl<T: State> Sleigh<T> { pub fn status(&self) -> &'static str { T::status() }}impl Sleigh<Empty> { pub fn new() -> Self { Self { state: PhantomData } } pub fn load(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}impl Sleigh<Ready> { pub fn take_off(self) -> Sleigh<Flying> { Sleigh { state: PhantomData } } pub fn unload(self) -> Sleigh<Empty> { Sleigh { state: PhantomData } }}impl Sleigh<Flying> { pub fn land(self) -> Sleigh<Ready> { Sleigh { state: PhantomData } }}