Struct aocf::Aoc

source ·
pub struct Aoc {
    pub year: Option<i32>,
    pub day: Option<u32>,
    pub level: Level,
    pub title: Option<String>,
    pub stars: Option<u8>,
    pub solution: HashMap<Level, String>,
    /* private fields */
}
Expand description

A cache entry for a single day, containing all data related to that day’s problem

Fields§

§year: Option<i32>§day: Option<u32>§level: Level§title: Option<String>§stars: Option<u8>§solution: HashMap<Level, String>

Implementations§

Examples found in repository?
examples/day01.rs (line 6)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(1))
        .cookie_file("./examples/cookie")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}
More examples
Hide additional examples
examples/day02.rs (line 6)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(2))
        .cookie("yoursessioncookiedatagoeshere")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}

Set the year

Examples found in repository?
examples/day01.rs (line 7)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(1))
        .cookie_file("./examples/cookie")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}
More examples
Hide additional examples
examples/day02.rs (line 7)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(2))
        .cookie("yoursessioncookiedatagoeshere")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}

Set the day

Examples found in repository?
examples/day01.rs (line 8)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(1))
        .cookie_file("./examples/cookie")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}
More examples
Hide additional examples
examples/day02.rs (line 8)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(2))
        .cookie("yoursessioncookiedatagoeshere")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}

Set cookie string

Examples found in repository?
examples/day02.rs (line 9)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(2))
        .cookie("yoursessioncookiedatagoeshere")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}

Set cookie file

Examples found in repository?
examples/day01.rs (line 9)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(1))
        .cookie_file("./examples/cookie")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}

Set the cache path

Enable or disable CLI argument parsing

If enabled, the binary’s arguments will be parsed, allowing for example, to choose a file to read in as alternative input data, rather than using the input data fetched from Advent of Code.

Initialise (finish building)

Examples found in repository?
examples/day01.rs (line 10)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(1))
        .cookie_file("./examples/cookie")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}
More examples
Hide additional examples
examples/day02.rs (line 10)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(2))
        .cookie("yoursessioncookiedatagoeshere")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}

Get the input data

Examples found in repository?
examples/day01.rs (line 13)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(1))
        .cookie_file("./examples/cookie")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}
More examples
Hide additional examples
examples/day02.rs (line 13)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut aoc = Aoc::new()
        .year(Some(2019))
        .day(Some(2))
        .cookie("yoursessioncookiedatagoeshere")
        .init()
        .unwrap();

    let input = if let Ok(i) = aoc.get_input(false) {
        i
    } else {
        "you probably need to add a valid cookie".to_string()
    };

    println!("{}", input);
}

get a JSON representation for the AoC problem

Examples found in repository?
src/lib.rs (line 238)
235
236
237
238
239
240
    pub fn write_json_to(&self, path: impl AsRef<Path>) -> Result<(), Error> {
        ensure_parent_dir(path.as_ref())?;
        let mut file = File::create(path)?;
        file.write_all(self.to_json()?.as_bytes())?;
        Ok(())
    }

get an AoC problem from JSON representation

Examples found in repository?
src/lib.rs (line 245)
243
244
245
246
    pub fn load_json_from(path: impl AsRef<Path>) -> Result<Self, Error> {
        let json = read_to_string(path)?;
        Self::from_json(&json)
    }

Save problem to path as JSON

Examples found in repository?
src/lib.rs (line 251)
249
250
251
252
253
254
255
    pub fn write(&self) -> Result<(), Error> {
        if let Some(ref p) = self.cache_path {
            self.write_json_to(p)
        } else {
            self.write_json_to(self.get_default_cache_path()?)
        }
    }

Load the problem from JSON

Examples found in repository?
src/lib.rs (line 266)
264
265
266
267
268
269
270
    fn load(&self) -> Result<Self, Error> {
        if let Some(ref p) = self.cache_path {
            Self::load_json_from(p)
        } else {
            Self::load_json_from(self.get_default_cache_path()?)
        }
    }

Write JSON cache

Examples found in repository?
src/lib.rs (line 196)
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    pub fn get_input(&mut self, force: bool) -> Result<String, Error> {
        // Input file provided on CLI, read it
        if let Some(file) = &self.input_file {
            return Ok(read_to_string(file)?.trim().to_string())
        }

        // We are piped, read the piped data
        if !self.stream {
            let stdin = io::stdin();

            let data = stdin.lock().lines()
                .flatten()
                .fold(String::new(), |mut acc, line| {
                    acc.push_str(&format!("{}\n", line));
                    acc
                });

            return Ok(data);
        }

        // Get input data from adventofcode.com
        if self.input.is_none() || force {
            let input = http::get_input(self)?;
            self.input = Some(input);
        }

        self.write()?;

        Ok(self.input.clone().unwrap())
    }

Get time until release

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.