#convert #string #vector #different #converter #integer #type

vector_converter

A library to convert between vectors of different types

2 releases

new 0.1.1 Nov 5, 2024
0.1.0 Nov 5, 2024

#1293 in Algorithms

Download history 58/week @ 2024-10-30

70 downloads per month

MIT license

5KB

Vector Converter

A simple Rust library to convert between vectors of different types, such as converting a vector of integers to a vector of strings and vice versa.

Features

  • Convert a vector of integers to a vector of strings.
  • Convert a vector of strings to a vector of integers (with error handling).

Installation

To use the vector_converter library in your Rust project, add the following to your Cargo.toml:

[dependencies]
vector_converter = "0.1"

Example Usage

Convert Integer Vector to String Vector

use vector_converter::int_vec_to_string_vec;

fn main() {
    let int_vec = vec![1, 2, 3];
    let string_vec = int_vec_to_string_vec(int_vec);
    println!("{:?}", string_vec);  // Output: ["1", "2", "3"]
}

Convert String Vector to Integer Vector

use vector_converter::string_vec_to_int_vec;

fn main() {
    let string_vec = vec!["1".to_string(), "2".to_string(), "3".to_string()];
    match string_vec_to_int_vec(string_vec) {
        Ok(int_vec) => println!("{:?}", int_vec),  // Output: [1, 2, 3]
        Err(e) => println!("Error: {}", e),
    }
}

License

This project is licensed under the MIT License

Author

Ben Santora bensatlantik@gmail.com

Donate

https://bensatlantik.github.io/

No runtime deps