Skip to content

Instantly share code, notes, and snippets.

@millerjs
Last active July 29, 2016 15:27
Show Gist options
  • Save millerjs/456c2b1c514339cb94ed6c715934eb14 to your computer and use it in GitHub Desktop.
Save millerjs/456c2b1c514339cb94ed6c715934eb14 to your computer and use it in GitHub Desktop.

Storage Engine

A general storage engine, not sure what to pick as the interface

Simpler:

pub trait StorageEngine { fn store<T: RustcEncodable>(&mut self, t: T); }

Probably better?

pub type PrimaryKey =  &[u8];
pub type SerializedRecord = &[u8];

pub trait StorageEngine { 
  fn store<T: Storable>(&mut self, t: T) -> ConstableResult<()>;
}

pub trait Storable {
  fn get_primary_key(&self) -> PrimaryKey;
  fn to_binary(&self) -> SerializedRecord;
  fn from_binary(record: SerializedRecord) -> Self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment