This repository was archived by the owner on Jan 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Default implementations don't work #26
Copy link
Copy link
Open
Description
Given the following:
use typestate::typestate;
#[typestate]
mod my_state {
#[automaton]
pub struct Automaton;
#[state]
pub struct State1(bool);
pub trait State1: Sized {
fn new() -> State1 {
Automaton {
state: State1(true),
}
}
fn to_state_2(mut self) -> State2 {
Automaton {
state: State2(true),
}
}
}
#[state]
pub struct State2(bool);
pub trait State2: Sized {
fn done(self) {}
}
}
fn t() {
use my_state::*;
let s1 = Automaton::new();
}We get an error stating that State1State trait is in scope, but not implemented for Automaton<State1>.
If I instead implement the traits, all is well:
#[automaton]
pub struct Automaton;
#[state]
pub struct State1;
pub trait State1 {
fn new() -> State1;
fn to_state_2(self) -> State2;
}
impl State1State for Automaton<State1> {
fn new() -> Automaton<State1> {
Automaton { state: State1 }
}
fn to_state_2(self) -> Automaton<State2> {
Automaton { state: State2 }
}
}
#[state]
pub struct State2;
pub trait State2 {
fn done(self);
}
impl State2State for Automaton<State2> {
fn done(self) {}
}
}
fn t() {
use my_state::*;
let s1 = Automaton::new();
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels