I managed to stumble into this error (Edited for formatting):
error[E0658]: where clauses on associated types are unstable
--> src/lib.rs:6:5
6 | type Output where Self::Output: ::std::fmt::Display;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
And I think now I understand what GATs actually are (or could be).
I'm trying to make a "helper trait" to complete assignments, which in essence is to read input, parse it and Display
an Output.
Without being able to specify that the Output associated type implements Display, my trait fn for display looks a bit weak, and I can't provide a default implementation, which would be something like:
fn display(output: Self::Output) {
println!("{}", output);
}
I'm still experimenting but envisage a consumer (lazy me) using the trait like so:
struct MySolution {};
struct MyData {
x: u32,
y: u32,
};
impl Assignment for MySolution {
type Input = MyData;
type Output = u32;
fn parse(input: String) -> Self::Input {
let input = input.split_whitespace();
let x = input.next().unwrap();
let y = input.next().unwrap();
MyData {
x,
y,
}
}
fn solve(input: Self::Input) -> Self::Output {
... a solution here ...
4
}
}
fn main() {
let s = MySolution;
s.display(s.solve(s.parse(s.read()));
}
Or something along those lines.
I've previously used cargo-aoc which uses some clever macros and derives to achieve a similar problem solving framework idea but I'm apprehensive about writing "oh so complicated" macros myself (maybe I shouldn't be?).
Open to suggestions, but primarily sharing because I heard about GATs in various places when reading about rust features and was surprised to run into them myself.