pub trait SclObject:
Clone
+ DeserializeOwned
+ Eq
+ Ord
+ PartialEq
+ PartialOrd
+ Serialize {
const PREFIX: &'static str;
// Required methods
fn name(&self) -> &SclName;
fn metadata(&self) -> &MetaData;
fn metadata_mut(&mut self) -> &mut MetaData;
fn referenced_db_keys(&self) -> Vec<String>;
fn validate_fields_before_create(&self) -> Result<()>;
fn validate_fields_before_update(
current_db_state: &Self,
proposed_new_state: &Self,
) -> Result<()>;
// Provided methods
fn uuid(&self) -> Uuid { ... }
fn separation_context(&self) -> Option<&SclName> { ... }
fn api_endpoint<'a>(
sc: impl Into<Option<&'a str>>,
name: impl Into<Option<&'a str>>,
) -> String { ... }
fn get_api_endpoint(&self) -> String { ... }
fn db_key<'a>(
sc: impl Into<Option<&'a str>>,
name: impl Into<Option<&'a str>>,
) -> String { ... }
fn get_db_key(&self) -> String { ... }
}Expand description
This trait is implemented by all SCL API objects to provide uniform access to common properties of the objects.
Required Associated Constants§
Required Methods§
Sourcefn metadata(&self) -> &MetaData
fn metadata(&self) -> &MetaData
Providing access to MetaData is essential for our optimistic concurrency control.
Sourcefn metadata_mut(&mut self) -> &mut MetaData
fn metadata_mut(&mut self) -> &mut MetaData
Providing access to MetaData is essential for our optimistic concurrency control.
Sourcefn referenced_db_keys(&self) -> Vec<String>
fn referenced_db_keys(&self) -> Vec<String>
Returns all DB keys the object is referencing / depending on.
Sourcefn validate_fields_before_create(&self) -> Result<()>
fn validate_fields_before_create(&self) -> Result<()>
Checks if all fields (except references to other SclObjects) are legal initial fields. Should be called before a create operation.
Sourcefn validate_fields_before_update(
current_db_state: &Self,
proposed_new_state: &Self,
) -> Result<()>
fn validate_fields_before_update( current_db_state: &Self, proposed_new_state: &Self, ) -> Result<()>
Checks if a proposed updated is valid. Should be called before a regular (not related to finalizers / deletion) update operation.
Provided Methods§
fn uuid(&self) -> Uuid
Sourcefn separation_context(&self) -> Option<&SclName>
fn separation_context(&self) -> Option<&SclName>
Returns the SclName of the separation context if the SclObject is connected to one,
otherwise default None.
Sourcefn api_endpoint<'a>(
sc: impl Into<Option<&'a str>>,
name: impl Into<Option<&'a str>>,
) -> String
fn api_endpoint<'a>( sc: impl Into<Option<&'a str>>, name: impl Into<Option<&'a str>>, ) -> String
Returns the API endpoint for a SclObject.
§Examples
use scl_lib::api_objects::{Controller, SclObject, VirtualMachine, Volume};
assert_eq!(VirtualMachine::api_endpoint("sc-01", "vm-01"), "/scs/sc-01/vms/vm-01");
assert_eq!(Controller::api_endpoint(None, "ctrl-01"), "/controllers/ctrl-01");
assert_eq!(Volume::api_endpoint("sc-01", None), "/scs/sc-01/volumes");Sourcefn get_api_endpoint(&self) -> String
fn get_api_endpoint(&self) -> String
Returns the API endpoint of the SclObject.
§Examples
use std::convert::TryFrom;
use scl_lib::api_objects::{Controller, ControllerKind, SclName, SclObject};
let ctrl = Controller::new(
SclName::try_from("ctrl-01".to_string()).unwrap(),
ControllerKind::VmController);
assert_eq!(ctrl.get_api_endpoint(), "/controllers/ctrl-01");Sourcefn db_key<'a>(
sc: impl Into<Option<&'a str>>,
name: impl Into<Option<&'a str>>,
) -> String
fn db_key<'a>( sc: impl Into<Option<&'a str>>, name: impl Into<Option<&'a str>>, ) -> String
Returns the database key for a SclObject.
§Examples
use scl_lib::api_objects::{Controller, SclObject, VirtualMachine, Volume};
assert_eq!(VirtualMachine::db_key("sc-01", "vm-01"), "/vms/sc-01/vm-01");
assert_eq!(Controller::db_key(None, "ctrl-01"), "/controllers/ctrl-01");
assert_eq!(Volume::db_key("sc-01", None), "/volumes/sc-01");Sourcefn get_db_key(&self) -> String
fn get_db_key(&self) -> String
Returns the database key of the SclObject.
§Examples
use std::convert::TryFrom;
use scl_lib::api_objects::{Controller, ControllerKind, SclName, SclObject};
let ctrl = Controller::new(
SclName::try_from("ctrl-01".to_string()).unwrap(),
ControllerKind::VmController);
assert_eq!(ctrl.get_db_key(), "/controllers/ctrl-01");Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.