Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRustnewtype and DerefSingle-choice MCQ

Given a newtype wrapper with a `Deref` to `Vec<T>`, why does `wrapper.push(1)` fail to compile?

use std::ops::Deref; struct MyVec(Vec<i32>); impl Deref for MyVec { type Target = Vec<i32>; fn deref(&self) -> &Vec<i32> { &self.0 } } fn main() { let mut w = MyVec(vec![]); w.push(1); }