I'd like to map a Vec of boxes to a Vec of refs for the ToSql
trait from tokio postgres.
Vec<Box<dyn ToSql>> -> Vec<& dyn ToSql>
I'm having a lot of trouble with this.
I've tried this
pub fn ref_from_box_vec<'a>(x: Vec<Box<dyn ToSql>>) -> Vec<&'a dyn ToSql> {
x.into_iter().map(|y| *y).collect()
}
but get several compile errors
error[E0277]: the size for values of type `dyn ToSql` cannot be known at compilation time
--> edb-core/src/postgres_common/core.rs:375:19
|
375 | x.into_iter().map(|y| *y).collect()
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn ToSql`
note: required by a bound in `std::iter::Iterator::map`
--> /home/decapo01/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:776:12
|
776 | fn map<B, F>(self, f: F) -> Map<Self, F>
| ^ required by this bound in `std::iter::Iterator::map`
error[E0277]: the size for values of type `dyn ToSql` cannot be known at compilation time
--> edb-core/src/postgres_common/core.rs:375:27
|
375 | x.into_iter().map(|y| *y).collect()
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn ToSql`
= note: the return type of a function must have a statically known size
error[E0599]: the method `collect` exists for struct `std::iter::Map<std::vec::IntoIter<Box<dyn ToSql>>, [closure@edb-core/src/postgres_common/core.rs:375:23: 375:26]>`, but its trait bounds were not satisfied
--> edb-core/src/postgres_common/core.rs:375:31
|
375 | x.into_iter().map(|y| *y).collect()
| ^^^^^^^ method cannot be called on `std::iter::Map<std::vec::IntoIter<Box<dyn ToSql>>, [closure@edb-core/src/postgres_common/core.rs:375:23: 375:26]>` due to unsatisfied trait bounds
I've also tried this
pub fn ref_from_box_vec<'a>(x: Vec<Box<dyn ToSql>>) -> Vec<&'a dyn ToSql> {
x.iter().map(|y| *y.to_owned()).collect()
}
and get this error
error[E0277]: a value of type `Vec<&dyn ToSql>` cannot be built from an iterator over elements of type `Box<dyn ToSql>`
--> edb-core/src/postgres_common/core.rs:379:5
|
379 | x.iter().map(|y| *y.to_owned()).collect()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call
| |
| value of type `Vec<&dyn ToSql>` cannot be built from `std::iter::Iterator<Item=Box<dyn ToSql>>`
|
= help: the trait `FromIterator<Box<dyn ToSql>>` is not implemented for `Vec<&dyn ToSql>`
= help: the trait `FromIterator<T>` is implemented for `Vec<T>`