#[post("/users/create-user", format = "json", data = "<user_info>")]
pub async fn create_user(user_info: Json<Vec<UserInputUser>>) -> Value {
let mut rng = rand::thread_rng();
loop {
let user_info_random = UserInputUser {
// Generate random data using the `rand` crate
first_name: rng.sample_iter(rand::distributions::Alphanumeric).take(10).map(char::from).collect(),
middle_name: rng.sample_iter(rand::distributions::Alphanumeric).take(10).map(char::from).collect(),
last_name: rng.sample_iter(rand::distributions::Alphanumeric).take(10).map(char::from).collect(),
email: rng.sample_iter(rand::distributions::Alphanumeric).take(10).map(char::from).collect(),
role_id: rng.sample_iter(rand::distributions::Alphanumeric).take(10).map(char::from).collect(),
password: rng.sample_iter(rand::distributions::Alphanumeric).take(10).map(char::from).collect()
};
// Insert the generated user into the database using your existing `create_user` function
services::users::create_user(&user_info_random);
// Wait for 5 seconds before generating the next user
sleep(Duration::from_secs(5));
}
}
For above code I am getting following error
error[E0277]: a value of type std::option::Option<std::string::String>
cannot be built from an iterator over elements of type char
--> src/routes/users.rs:280:98
|
280 | role_id: rng.sample_iter(rand::distributions::Alphanumeric).take(10).map(char::from).collect(),
| ^^^^^^^ value of type std::option::Option<std::string::String>
cannot be built from std::iter::Iterator<Item=char>
|
= help: the trait FromIterator<char>
is not implemented for std::option::Option<std::string::String>
= help: the trait FromIterator<std::option::Option<A>>
is implemented for std::option::Option<V>
What changes should I do ?