Converts the inner value by the given function. Typically `T` is a static reference to a collection, and `U` is an iterator of that collection. # Panics Panics if the underlying reference has been invalidated. This is typically called immediately after the `UnsafePyLeaked` is obtained. At this time, the reference must be valid and no panic would occur. # Safety The lifetime of the object pas
(self, py: Python, f: impl FnOnce(T) -> U)
| 416 | /// corresponding `UnsafePyLeaked` is alive. Do not copy it out of the |
| 417 | /// function call. |
| 418 | pub unsafe fn map<U>(self, py: Python, f: impl FnOnce(T) -> U) -> UnsafePyLeaked<U> { |
| 419 | // Needs to test the generation value to make sure self.data reference |
| 420 | // is still intact. |
| 421 | self.validate_generation(py) |
| 422 | .expect("map() over invalidated leaked reference"); |
| 423 | |
| 424 | // f() could make the self.data outlive. That's why map() is unsafe. |
| 425 | // In order to make this function safe, maybe we'll need a way to |
| 426 | // temporarily restrict the lifetime of self.data and translate the |
| 427 | // returned object back to Something<'static>. |
| 428 | let new_data = f(self.data); |
| 429 | UnsafePyLeaked { |
| 430 | owner: self.owner, |
| 431 | state: self.state, |
| 432 | generation: self.generation, |
| 433 | data: new_data, |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /// An immutably borrowed reference to a leaked value. |