0

The below example reads lines from a file buffer. I want to split the lines into an array which will later be converted to a Table struct.

When I print the String is looks similar to this:

let string_line: String = line.unwrap()
println!("{}", string_line);
Tom,Stuart,1,23.0

However after splitting it, it is converted to another type/struct and I don't know how to convert it to an array.

let string_line = line.unwrap();
let split_line = string_line.split(",");
println!("{:?}", split_line);
Split(SplitInternal { start: 0, end: 72, matcher: StrSearcher { haystack: "Tom,Stuart,1,23.0", needle: ",", searcher: TwoWay(TwoWaySearcher { crit_pos: 0, crit_pos_back: 1, period: 1, byteset: 17592186044416, position: 0, end: 72, memory: 0, memory_back: 1 }) }, allow_trailing_empty: true, finished: false })

How to convert a String to an array so that it can be converted to a Table struct later?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Greg
  • 8,175
  • 16
  • 72
  • 125
  • 1
    What you have there is the `Split` struct, which can be converted to a `Vec` using `collect`. See: https://stackoverflow.com/questions/26643688/how-to-split-a-string-in-rust. Note that this isn [Rust arrays](https://doc.rust-lang.org/std/primitive.array.html) per se, but I imagine this should still help create your `Table`. – bow Nov 07 '17 at 07:04

0 Answers0