Adamarla
Adamarla

Reputation: 812

Convert Option<&&[T]> to Option<&[T]>

I have a hashmap of type HashMap<String, &[T]>.

Calling hashmap.get(&key), returns an Option<&&[T]>. [Double ampersand]

How do I convert that to Option<&[T]>? [Single ampersand]

Upvotes: 0

Views: 303

Answers (1)

trent
trent

Reputation: 27895

All & references are Copy, so you can use Option::copied:

hashmap.get(&key).copied()

Upvotes: 1

Related Questions