home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Convert Lines Of Characters Into A Vec Of Vecs In Rust

December 2023
Code
fn main() {
  let cases = vec![
    (
      "abcd\nefgh",
      vec![vec!['a', 'b', 'c', 'd'], vec!['e', 'f', 'g', 'h']]
    )
  ];

  cases.iter().for_each(|case| {
    let left = split_line_chars(case.0);
    dbg!(&left);
    assert_eq!(left, case.1);
  });

}

fn split_line_chars(source: &str) -> Vec<Vec<char>> {
  let lines = source.lines();
  lines.map(|line| line.chars().map(|c| c).collect()).collect()
}
Results
[neopolitan_code_run:12] &left = [
    [
        'a',
        'b',
        'c',
        'd',
    ],
    [
        'e',
        'f',
        'g',
        'h',
    ],
]
═══ § ═══