Skip to main content
added 4 characters in body
Source Link

in rust you can do this:

struct PLANNED; struct INPROGRESS; struct ABOARTED; struct COMPLETED; struct Mission<State> { detail: String, _marker: std::marker::PhantomData<State>, } impl<T> Mission<T> { fn new(detail: &str) -> Mission<PLANNED> { Mission { detail: detail.to_string(), _marker: std::marker::PhantomData, } } } impl Mission<PLANNED> { fn start(self) -> Mission<INPROGRESS> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<INPROGRESS> { fn abort(self) -> Mission<ABOARTED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } fn completed(self) -> Mission<COMPLETED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<COMPLETED> { fn requestReimbursement(self) { // ... } } 

if you call requestReimbursement by MissionMission<PLANNED> or some other non-MissionMission<COMPLETED> type, which will can't be compliledcompiled.

in rust you can do this:

struct PLANNED; struct INPROGRESS; struct ABOARTED; struct COMPLETED; struct Mission<State> { detail: String, _marker: std::marker::PhantomData<State>, } impl<T> Mission<T> { fn new(detail: &str) -> Mission<PLANNED> { Mission { detail: detail.to_string(), _marker: std::marker::PhantomData, } } } impl Mission<PLANNED> { fn start(self) -> Mission<INPROGRESS> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<INPROGRESS> { fn abort(self) -> Mission<ABOARTED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } fn completed(self) -> Mission<COMPLETED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<COMPLETED> { fn requestReimbursement(self) { // ... } } 

if you call requestReimbursement by Mission or some other non-Mission type which will can't be compliled.

in rust you can do this:

struct PLANNED; struct INPROGRESS; struct ABOARTED; struct COMPLETED; struct Mission<State> { detail: String, _marker: std::marker::PhantomData<State>, } impl<T> Mission<T> { fn new(detail: &str) -> Mission<PLANNED> { Mission { detail: detail.to_string(), _marker: std::marker::PhantomData, } } } impl Mission<PLANNED> { fn start(self) -> Mission<INPROGRESS> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<INPROGRESS> { fn abort(self) -> Mission<ABOARTED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } fn completed(self) -> Mission<COMPLETED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<COMPLETED> { fn requestReimbursement(self) { // ... } } 

if you call requestReimbursement by Mission<PLANNED> or some other non-Mission<COMPLETED> type, which will can't be compiled.

added 2 characters in body
Source Link

in rust you can do this:

struct PLANNED; struct INPROGRESS; struct ABOARTED; struct COMPLETED; struct Mission<State> { detail: String, _marker: std::marker::PhantomData<State>, } impl<T> Mission<T> { fn new(detail: &str) -> Mission<PLANNED> { Mission { detail: detail.to_string(), _marker: std::marker::PhantomData, } } } impl Mission<PLANNED> { fn start(self) -> Mission<INPROGRESS> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<INPROGRESS> { fn abort(self) -> Mission<ABOARTED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } fn completed(self) -> Mission<COMPLETED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<COMPLETED> { fn requestReimbursement(self) { // ... } }``` if you call `requestReimbursement` by Mission<PLANNED> or some other non-Mission<COMPLETED> type which will can't be compliled. 

if you call requestReimbursement by Mission or some other non-Mission type which will can't be compliled.

in rust you can do this:

struct PLANNED; struct INPROGRESS; struct ABOARTED; struct COMPLETED; struct Mission<State> { detail: String, _marker: std::marker::PhantomData<State>, } impl<T> Mission<T> { fn new(detail: &str) -> Mission<PLANNED> { Mission { detail: detail.to_string(), _marker: std::marker::PhantomData, } } } impl Mission<PLANNED> { fn start(self) -> Mission<INPROGRESS> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<INPROGRESS> { fn abort(self) -> Mission<ABOARTED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } fn completed(self) -> Mission<COMPLETED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<COMPLETED> { fn requestReimbursement(self) { // ... } }``` if you call `requestReimbursement` by Mission<PLANNED> or some other non-Mission<COMPLETED> type which will can't be compliled. 

in rust you can do this:

struct PLANNED; struct INPROGRESS; struct ABOARTED; struct COMPLETED; struct Mission<State> { detail: String, _marker: std::marker::PhantomData<State>, } impl<T> Mission<T> { fn new(detail: &str) -> Mission<PLANNED> { Mission { detail: detail.to_string(), _marker: std::marker::PhantomData, } } } impl Mission<PLANNED> { fn start(self) -> Mission<INPROGRESS> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<INPROGRESS> { fn abort(self) -> Mission<ABOARTED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } fn completed(self) -> Mission<COMPLETED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<COMPLETED> { fn requestReimbursement(self) { // ... } } 

if you call requestReimbursement by Mission or some other non-Mission type which will can't be compliled.

Source Link

in rust you can do this:

struct PLANNED; struct INPROGRESS; struct ABOARTED; struct COMPLETED; struct Mission<State> { detail: String, _marker: std::marker::PhantomData<State>, } impl<T> Mission<T> { fn new(detail: &str) -> Mission<PLANNED> { Mission { detail: detail.to_string(), _marker: std::marker::PhantomData, } } } impl Mission<PLANNED> { fn start(self) -> Mission<INPROGRESS> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<INPROGRESS> { fn abort(self) -> Mission<ABOARTED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } fn completed(self) -> Mission<COMPLETED> { Mission { detail: self.detail, _marker: std::marker::PhantomData, } } } impl Mission<COMPLETED> { fn requestReimbursement(self) { // ... } }``` if you call `requestReimbursement` by Mission<PLANNED> or some other non-Mission<COMPLETED> type which will can't be compliled.