Factor out from_file_data; hopefully this doesn't end up being the only shared thing.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use advent2021::from_file_data;
|
||||||
use std::num;
|
use std::num;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@@ -37,16 +38,6 @@ impl FromStr for Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_file_data<T: FromStr>(filedata: &str) -> Result<Vec<T>, T::Err> {
|
|
||||||
let mut retval = Vec::new();
|
|
||||||
|
|
||||||
for line in filedata.lines() {
|
|
||||||
retval.push(T::from_str(line)?);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(retval)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn command_parsing() {
|
fn command_parsing() {
|
||||||
assert_eq!(Ok(Command::Forward(5)), Command::from_str("forward 5"));
|
assert_eq!(Ok(Command::Forward(5)), Command::from_str("forward 5"));
|
||||||
|
|||||||
11
src/lib.rs
Normal file
11
src/lib.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
pub fn from_file_data<T: FromStr>(filedata: &str) -> Result<Vec<T>, T::Err> {
|
||||||
|
let mut retval = Vec::new();
|
||||||
|
|
||||||
|
for line in filedata.lines() {
|
||||||
|
retval.push(T::from_str(line)?);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(retval)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user