use serde::Serialize;
use serde::de::DeserializeOwned;
use std::fmt;
pub use self::id::*;
pub use self::status::*;
pub use self::batchcentroid::BatchCentroid;
pub use self::batchprediction::BatchPrediction;
pub use self::cluster::Cluster;
pub use self::ensemble::Ensemble;
pub use self::evaluation::Evaluation;
pub use self::execution::Execution;
pub use self::script::Script;
pub use self::source::Source;
pub trait Resource: fmt::Debug + DeserializeOwned {
fn id_prefix() -> &'static str;
fn create_path() -> &'static str;
fn id(&self) -> &Id<Self>;
fn status(&self) -> &Status;
}
pub trait Args: fmt::Debug + Serialize {
type Resource: Resource;
}
macro_rules! resource {
(
api_name $string_name:expr;
// The pattern `$(<$($Ty : $Tr),*>)*` is overly generous. We want
$(#[ $meta:meta ])*
pub struct $name:ident $(<$($Ty:ident : $Tr:ident),*>)* {
$(
$(#[ $field_type_meta:meta ])*
pub $field_name:ident: $field_ty:ty,
)*
}
) => {
$(#[ $meta ])*
pub struct $name $(<$($Ty : $Tr),*>)* {
// Start by declaring the fields which appear on every resource
pub category: i64,
pub code: u16,
pub dev: Option<bool>,
pub description: String,
pub name: String,
pub shared: bool,
pub subscription: bool,
pub tags: Vec<String>,
pub resource: Id<$name $(<$($Ty),*>)*>,
#[serde(default, skip_serializing)]
_hidden: (),
$(
$(#[ $field_type_meta ])*
pub $field_name: $field_ty
),*
}
impl $(<$($Ty : $Tr),*>)* Resource for $name $(<$($Ty),*>)* {
fn id_prefix() -> &'static str {
concat!($string_name, "/")
}
fn create_path() -> &'static str {
concat!("/", $string_name)
}
fn id(&self) -> &Id<Self> {
&self.resource
}
fn status(&self) -> &Status {
&self.status
}
}
};
}
mod id;
mod status;
pub mod batchcentroid;
pub mod batchprediction;
pub mod cluster;
pub mod ensemble;
pub mod evaluation;
pub mod execution;
pub mod script;
pub mod source;