memory - Why is ?Sized a bound for certain RefCell functions, but not all? -
i noticed ?sized bound on type parameter t functions (borrow, borrow_state, , borrow_mut), however, not bound new or into_inner. if can't create refcell containing dynamically sized (refcell<t : ?sized>), having functions can operate on such thing?
that support added in commit added tests. can @ tests see how expected used:
use std::cell::refcell; #[test] fn refcell_unsized() { let cell: &refcell<[i32]> = &refcell::new([1, 2, 3]); { let b = &mut *cell.borrow_mut(); b[0] = 4; b[2] = 5; } let comp: &mut [i32] = &mut [4, 2, 5]; assert_eq!(&*cell.borrow(), comp); } you need have constructor sized bound compiler needs know amount of space allocate on stack. once have that, can coerce dynamically-sized type.
Comments
Post a Comment