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§
source§impl Aoc
impl Aoc
sourcepub fn new() -> Self
pub fn new() -> Self
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
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);
}
sourcepub fn year(self, year: Option<i32>) -> Self
pub fn year(self, year: Option<i32>) -> Self
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
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);
}
sourcepub fn day(self, day: Option<u32>) -> Self
pub fn day(self, day: Option<u32>) -> Self
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
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);
}
sourcepub fn parse_cli(self, status: bool) -> Self
pub fn parse_cli(self, status: bool) -> Self
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.
sourcepub fn init(self) -> Result<Self, Error>
pub fn init(self) -> Result<Self, Error>
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
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);
}
sourcepub fn get_input(&mut self, force: bool) -> Result<String, Error>
pub fn get_input(&mut self, force: bool) -> Result<String, Error>
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
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);
}
sourcepub fn from_json(json: &str) -> Result<Self, Error>
pub fn from_json(json: &str) -> Result<Self, Error>
get an AoC problem from JSON representation
sourcepub fn write_json_to(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub fn write_json_to(&self, path: impl AsRef<Path>) -> Result<(), Error>
Save problem to path as JSON
sourcepub fn load_json_from(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn load_json_from(path: impl AsRef<Path>) -> Result<Self, Error>
Load the problem from JSON
sourcepub fn write(&self) -> Result<(), Error>
pub fn write(&self) -> Result<(), Error>
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())
}
pub fn advance(&mut self) -> Result<(), Error>
sourcepub fn get_time_until_release()
pub fn get_time_until_release()
Get time until release
Trait Implementations§
source§impl<'de> Deserialize<'de> for Aoc
impl<'de> Deserialize<'de> for Aoc
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more