Is it possible to create a RefCell <Any>?
Is it possible to create something like this RefCell<Any>
in Rust? I tried the following:
fn test2<T : Any>(x : T) -> RefCell<Any>{
return RefCell::new(x) as RefCell<Any>
}
But I get the following error:
error: the trait `core::marker::Sized` is not implemented for the type `core::any::Any + 'static` [E0277]
<anon>:8 fn test2<T : Any>(x : T) -> RefCell<Any>{
The documentation for RefCell
includes the following
pub struct RefCell<T> where T: ?Sized {
// some fields omitted
}
It makes me believe (along with the answer to this question) that this is possible. I also tried:
fn test1<T : Any>(x : T) -> Box<Any>{
return Box::new(x) as Box<Any>
}
which works great. Both Box
, and RefCell
it seems, have the same boundaries, so I'm not quite sure what I am missing here. Any help is appreciated. I have this in Rust Playground , if useful.
+4