How do I convert a Vec <&str> to Vec <String>?

1.4k Views Asked by At
let parts: Vec<String> = line.split_whitespace().collect();
let parts: Vec<String> = map(AsRef::as_ref).line.split_whitespace().collect();
if parts.len() >= 3 {
    let attribute_name = parts[1].to_string();
    let attribute_type = parts[2].to_lowercase();
    let attribute = match attribute_type.as_str() {
        "numeric" => Attribute::Numeric,
        "date" => Attribute::Date(parts.get(3).cloned()),
        "string" => Attribute::String,
        "nominal" => {
            let nominal_values: Vec<String> = parts[3..]
                .iter()
                .map(|s| s.trim_matches(|c| c == '{' || c == '}' || c == ',').to_string())
                .collect();
            Attribute::Nominal(nominal_values)
        }

enter image description here

My goal is to implement an algorithm in Rust for loading and reading .arff files. It reads an .arff file, extract information from header, attributes and instances, then prints it on the output. Each attribute is represented as a pair (name, type) in array attributes, and instances are stored as arrays of attribute values ​​in array instances.

1

There are 1 best solutions below

0
Валентин Стайков On

You would need to map the values of the vector. Something like this:

let parts: Vec<String> = line.split_whitespace().map(|v| v.to_string()).collect();