MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / map

Method map

src/sharedref.rs:418–435  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 15

version_from_envFunction · 0.80
version_from_envFunction · 0.80
clone_refMethod · 0.80
to_stringMethod · 0.80
to_string_lossyMethod · 0.80
extractMethod · 0.80
next_element_seedMethod · 0.80
next_key_seedMethod · 0.80
fmtMethod · 0.80
test_leaked_borrow_mutFunction · 0.80

Calls 2

fFunction · 0.85
validate_generationMethod · 0.80