Updated: Minimum reproducible example is available at the Rust Playground. Please be advised that simply adding the normal derive statement at the stop isn't really sufficient, which is why it's not included in the original contents.
I would like to make a fancy universal dictionary in Rust for faster prototyping, where the keys are String
s and the values are wrapped in an AnyType
container. My implementation looks like this:
use std::collections::HashMap;
use std::boxed::Box;
use std::rc::Rc;
use std::cell::RefCell;
use std::clone::Clone;
struct AnyType<AT> {
___value: Rc<RefCell<Box<AT>>>
}
impl<AT> AnyType<AT> {
pub fn new(value: AT) -> AnyType<AT> {
AnyType {
___value: Rc::new(RefCell::from(Box::new(value)))
}
}
}
impl<AT> Copy for AnyType<AT> {}
impl<AT> Clone for AnyType<AT> {
fn clone(&self) -> Self {
*self
}
}
struct Dict<AT> {
___self: HashMap<String, AnyType<AT>>
}
impl<AT> Dict<AT> {
pub fn new(keys: Option<Vec<String>>, values: Option<Vec<AnyType<AT>>>)
-> Result<Dict<AT>, &'static str>
{
// ...
any ideas on how I might be able to maneuver the compiler's error? It says:
error[E0204]: the trait `Copy` may not be implemented for this type