Skip to content

Allow using self in Solution implementation #5

@drmason13

Description

@drmason13

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)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions