adventofcode

git clone https://git.ce9e.org/adventofcode.git

commit
79d3c4425cf0336f75076ef87c768050759eeac4
parent
9d4a564a8f9da8d47a025c080021032fd06fad74
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2022-12-09 08:24
make split_once reusable

upstream version is available since 1.52

https://doc.rust-lang.org/std/primitive.str.html#method.split_once

Diffstat

M 2022/04/solution.rs 11 +++--------
M 2022/lib.rs 5 +++++

2 files changed, 8 insertions, 8 deletions


diff --git a/2022/04/solution.rs b/2022/04/solution.rs

@@ -1,14 +1,9 @@
    1     1 #[path = "../lib.rs"] mod lib;
    2     2 
    3    -1 fn split_once(s: &str, sep: char) -> Option<(&str, &str)> {
    4    -1     let x = s.find(sep)?;
    5    -1     return Some((&s[..x], &s[x+1..]));
    6    -1 }
    7    -1 
    8     3 fn parse(line: String) -> Option<(u8, u8, u8, u8)> {
    9    -1     let (a, b) = split_once(&line, ',')?;
   10    -1     let (a1, a2) = split_once(a, '-')?;
   11    -1     let (b1, b2) = split_once(b, '-')?;
   -1     4     let (a, b) = lib::split_once(&line, ',')?;
   -1     5     let (a1, a2) = lib::split_once(a, '-')?;
   -1     6     let (b1, b2) = lib::split_once(b, '-')?;
   12     7     return Some((
   13     8         a1.parse::<u8>().ok()?,
   14     9         a2.parse::<u8>().ok()?,

diff --git a/2022/lib.rs b/2022/lib.rs

@@ -8,3 +8,8 @@ pub fn iter_input() -> impl Iterator<Item = String> {
    8     8     let file = File::open(path).unwrap();
    9     9     return BufReader::new(file).lines().map(|l| l.unwrap());
   10    10 }
   -1    11 
   -1    12 pub fn split_once(s: &str, sep: char) -> Option<(&str, &str)> {
   -1    13     let x = s.find(sep)?;
   -1    14     return Some((&s[..x], &s[x+1..]));
   -1    15 }