Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 857
Madhouse1999 Avatar asked Oct 15 '25 19:10

Madhouse1999


1 Answers

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();
like image 104
Валентин Стайков Avatar answered Oct 18 '25 16:10

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



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!