Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRustRefCell and interior mutabilitySingle-choice MCQ

You want to map an immutable `Ref` guard to a borrow of one struct field so the borrow stays tracked. Which function produces a `Ref` that points to a component of the originally borrowed data?

use std::cell::{RefCell, Ref}; struct P { name: String, age: u32 } let c = RefCell::new(P { name: "x".into(), age: 1 }); let name: Ref<String> = Ref::map(c.borrow(), |p| /* ??? */);