Creating `&mut dyn Iterator<Item = &[u8]>`

I'm trying to write a test for a custom TLS verifier which uses rustls. The signature for the trait function which verifies a server cert takes &mut dyn Iterator<Item = &[u8]> as one of it's parameters. I'm trying to create it like this so far:

let mut scts: Vec<&[u8]> = vec![];

I'm then passing it to the function as &mut scts.iter(). This fails.

let res = verifier.verify_server_cert(&cert, &[], &name, &mut scts.iter(), &[], now);
   |                                                                  ^^^^^^^^^^^^^^^^ expected `&[u8]`, found `&&[u8]`

That makes sense, as it's yeilding a reference to the underlying data. I've tried a couple of other ways which have all failed for one or another reason.

Any help appreciated.

&mut v.iter().copied()

Refer to Iterator::copied in std::iter - Rust [1]

  1. but some prefers .map(|&x| x) ↩ī¸Ž


If you literally meant an empty Vec, you can use &mut [].into_iter() instead.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.