#[cfg(feature = "diesel")]
pub mod diesel;
mod error;
pub use error::LocationStoreError;
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct Location {
pub location_id: String,
pub location_address: String,
pub location_namespace: String,
pub owner: String,
pub attributes: Vec<LocationAttribute>,
pub start_commit_num: i64,
pub end_commit_num: i64,
pub service_id: Option<String>,
}
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct LocationAttribute {
pub location_id: String,
pub location_address: String,
pub property_name: String,
pub data_type: String,
pub bytes_value: Option<Vec<u8>>,
pub boolean_value: Option<bool>,
pub number_value: Option<i64>,
pub string_value: Option<String>,
pub enum_value: Option<i32>,
pub struct_values: Option<Vec<LocationAttribute>>,
pub lat_long_value: Option<LatLongValue>,
pub start_commit_num: i64,
pub end_commit_num: i64,
pub service_id: Option<String>,
}
#[derive(Debug, Clone, Copy, Serialize)]
pub struct LatLong;
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct LatLongValue(pub i64, pub i64);
pub trait LocationStore: Send + Sync {
fn add_location(&self, location: Location) -> Result<(), LocationStoreError>;
fn fetch_location(
&self,
location_id: &str,
service_id: Option<&str>,
) -> Result<Option<Location>, LocationStoreError>;
fn list_locations(&self, service_id: Option<&str>)
-> Result<Vec<Location>, LocationStoreError>;
fn update_location(&self, location: Location) -> Result<(), LocationStoreError>;
fn delete_location(
&self,
address: &str,
current_commit_num: i64,
) -> Result<(), LocationStoreError>;
}
impl<LS> LocationStore for Box<LS>
where
LS: LocationStore + ?Sized,
{
fn add_location(&self, location: Location) -> Result<(), LocationStoreError> {
(**self).add_location(location)
}
fn fetch_location(
&self,
location_id: &str,
service_id: Option<&str>,
) -> Result<Option<Location>, LocationStoreError> {
(**self).fetch_location(location_id, service_id)
}
fn list_locations(
&self,
service_id: Option<&str>,
) -> Result<Vec<Location>, LocationStoreError> {
(**self).list_locations(service_id)
}
fn update_location(&self, location: Location) -> Result<(), LocationStoreError> {
(**self).update_location(location)
}
fn delete_location(
&self,
address: &str,
current_commit_num: i64,
) -> Result<(), LocationStoreError> {
(**self).delete_location(address, current_commit_num)
}
}