-
Notifications
You must be signed in to change notification settings - Fork 3
Allow using self in Solution implementation #5
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
All the methods on the traits so far are associated functions.
So essentially the implementing struct is just a marker or container for organising the solutions. It has no use for any data or fields.
I'd like people to experiment with this idea, I have in mind fun implementations of Solution like this:
// from Advent of Code 2019
pub struct IntcodeComputer {
program: Vec<Instruction>,
stack: Vec<i32>,
register: HashMap<Register, i32>,
}
impl Solution<Day2> for IntcodeComputer {
fn part1(&self) -> u32 {
// use the intcode computer and access its fields, methods!
self.program.iter() // ...
}
}We could even have mutability.
impl Solution<Day2> for IntcodeComputer {
fn part1(&mut self) -> u32 {
// use the intcode computer and mutate it while solving the solution
self.stack.push(3)
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed