我有问题使我的通用InMemoryColumn<T>序列化.它抱怨'Encodable'和'Decodable'特性是私密的,但我认为它在这里是公开的.我如何实现这些特征,以便我可以编码和解码底层Vec<T>.
这是导入的代码:
extern crate bincode;
extern crate libc;
extern crate "rustc-serialize" as rustc_serialize;
use rustc_serialize::serialize::{Encodable,Decodable};
//import other libs
pub struct InMemoryColumn<T> {
name: String,
data: Vec<T>,
}
impl<T: Eq + Ord + Hash + Encodable + Decodable> InMemoryColumn<T> {
fn save(&self, tbl_name: &str) {
//encode self.data and write to disk
}
fn load(path: &str, name: &str) -> Result<InMemoryColumn<T>,String> {
//decode from disk and populate InMemoryColumn<T>
}
}
Run Code Online (Sandbox Code Playgroud)
这些Encodable和Decodable特征仅与serialize模块相关.该模块虽然是私密的.正如您在mod.rs文件中看到的那样,Encodable并Decodable直接在包中重新导出rustc_serialize.你可以因此使用Encodable和Decodable特征如下:
use rustc_serialize::{Encodable,Decodable};
Run Code Online (Sandbox Code Playgroud)