Trait ohmers::Ohmer [] [src]

pub trait Ohmer: Encodable + Decodable + Default + Sized {
    fn id(&self) -> usize;
    fn set_id(&mut self, id: usize);

    fn id_field(&self) -> String { ... }
    fn unique_fields<'a>(&self) -> HashSet<&'a str> { ... }
    fn index_fields<'a>(&self) -> HashSet<&'a str> { ... }
    fn key_for_unique(&self, field: &str, value: &str) -> String { ... }
    fn key_for_index(&self, field: &str, value: &str) -> String { ... }
    fn counters(&self) -> HashSet<String> { ... }
    fn get_class_name(&self) -> String { ... }
    fn load(&mut self, id: usize, r: &Client) -> Result<(), DecoderError> { ... }
    fn encoder(&self) -> Result<Encoder, OhmerError> { ... }
    fn uniques_indices(&self, encoder: &Encoder) -> Result<(HashMap<String, String>, HashMap<String, Vec<String>>), OhmerError> { ... }
    fn save(&mut self, r: &Client) -> Result<(), OhmerError> { ... }
    fn delete(self, r: &Client) -> Result<(), OhmerError> { ... }
}

Structs that can be stored in and retrieved from Redis. You can use the model! macro as a helper.

Required Methods

fn id(&self) -> usize

The object unique identifier. It is 0 if it was not saved yet.

fn set_id(&mut self, id: usize)

Sets the object unique identifier. It should not be called manually, it is set after save.

Provided Methods

fn id_field(&self) -> String

The name of the field storing the unique auto increment identifier. It must be named "id" to be consistent with the LUA scripts.

fn unique_fields<'a>(&self) -> HashSet<&'a str>

Fields with a unique index.

fn index_fields<'a>(&self) -> HashSet<&'a str>

Fields with an index.

fn key_for_unique(&self, field: &str, value: &str) -> String

Redis key to find an element with a unique index field value.

fn key_for_index(&self, field: &str, value: &str) -> String

Redis key to find all elements with an indexed field value.

fn counters(&self) -> HashSet<String>

Name of all the fields that are counters. Counters are stored independently to keep atomicity in its operations.

fn get_class_name(&self) -> String

Object name used in the database.

fn load(&mut self, id: usize, r: &Client) -> Result<(), DecoderError>

Loads an object by id.

fn encoder(&self) -> Result<Encoder, OhmerError>

Serializes this object.

fn uniques_indices(&self, encoder: &Encoder) -> Result<(HashMap<String, String>, HashMap<String, Vec<String>>), OhmerError>

Grabs all the uniques and indices from this object.

fn save(&mut self, r: &Client) -> Result<(), OhmerError>

Saves the object in the database, and sets the instance id if it was not set.

fn delete(self, r: &Client) -> Result<(), OhmerError>

Deletes the object from the database.

Implementors