我在使我的通用InMemoryColumn<T>可序列化方面有问题。它抱怨说,“可编码”和“可解码”的特性是私密的,但我看到它是公开的这里。如何实现这些特性,以便对底层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>
}
}发布于 2015-03-18 12:51:14
Encodable和Decodable特征仅相对于serialize模块是公开的。不过,该模块是私有的。。正如您在文件中看到的那样,Encodable和Decodable直接在rustc_serialize机箱中重新导出。因此,您可以使用Encodable和Decodable特性如下:
use rustc_serialize::{Encodable,Decodable};https://stackoverflow.com/questions/29121993
复制相似问题