Allow unsized types as mapped value in Ref::map (#8817)

# Objective

- I can't map unsized type using `Ref::map` (for example `dyn Reflect`)

## Solution

- Allow unsized types (this is possible because `Ref` stores a reference
to `T`)
This commit is contained in:
Nicola Papale 2023-06-12 19:52:11 +02:00 committed by GitHub
parent 527d3a5885
commit ea887d8ffa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -551,7 +551,7 @@ impl<'a, T: ?Sized> Ref<'a, T> {
///
/// This doesn't do anything else than call `f` on the wrapped value.
/// This is equivalent to [`Mut::map_unchanged`].
pub fn map<U>(self, f: impl FnOnce(&T) -> &U) -> Ref<'a, U> {
pub fn map<U: ?Sized>(self, f: impl FnOnce(&T) -> &U) -> Ref<'a, U> {
Ref {
value: f(self.value),
ticks: self.ticks,