macro_rules! declare_client {
($(
{
feature: $feature:literal,
field: $field:ident,
ty: $ty:ty,
doc: $doc:literal,
init: |$core_config:ident, $base_core_config:ident| $init:block $(,)?
}
),* $(,)?) => {
#[derive(Clone)]
pub struct Client {
config: openlark_core::config::Config,
$(
#[doc = $doc]
#[cfg(feature = $feature)]
pub $field: $ty,
)*
}
impl std::fmt::Debug for Client {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Client")
.field("config", &"<CoreConfig>")
$(
.field(stringify!($field), &cfg!(feature = $feature))
)*
.finish()
}
}
impl Client {
fn from_parts(
_base_core_config: openlark_core::config::Config,
core_config: openlark_core::config::Config,
) -> crate::Result<Self> {
$(
#[cfg(feature = $feature)]
let $field: $ty = (|
$core_config: openlark_core::config::Config,
$base_core_config: openlark_core::config::Config,
| -> crate::Result<$ty> { Ok($init) })(
core_config.clone(),
_base_core_config.clone(),
)?;
)*
Ok(Self {
config: core_config.clone(),
$(
#[cfg(feature = $feature)]
$field,
)*
})
}
}
};
}