Create new Vec<Subtype> with Select of Vec<Type>

Hello! I am learning rust and I was wondering if something was possible, since I have trouble describing this problem, so I'll explain it with an example.

Let's say we have this struct:

struct A {
word: String,
number: u32,
}

fn some_function() {
    let some_A: Vec<A> = Vec::new();
    let phrases: Vec<String> = Vec::new();
}

Now I would like "phrases" to be initialize with all of the "words" of "some_A" without having to loop.

If this is not clear enough, please let me know, I'll do my best to clarify.
I realize this may already have been asked but I have trouble putting it into words and so searching is not really a simple task

Thank you.

Will something like this do?

fn some_function(some_a: Vec<A>) -> Vec<String> {
    some_a.into_iter().map(|a| a.word).collect()
}

Playground

1 Like

This is actually it, thank you!
Quite happy that this is possible.