How to convert between Vectors of different types

⚓ rust    📅 2025-05-30    👤 surdeus    👁️ 3      

surdeus

I would have expected that if I have implemented From<T> for S then I get From<Vec<T>> for Vec<S> for free. However looking at the From Documentation I find nothing like this. I also cannot implement this myself, because both Vec and From are defined externally.

What is the recommended way to convert from Vec<i32> to Vec<i64>, say? In this Playground I wrote a custom from function to illustrate what I want to do. What's annoying is that this way I won't get into functions for free.

10 posts - 6 participants

Read full topic

🏷️ rust_feed