#[allow(unused_macros)]
macro_rules! define_feature_stub {
(
$(#[$meta:meta])*
struct $Name:ident;
feature = $feature:literal;
name = $name:expr;
description = $desc:expr;
error_msg = $err:expr;
$(
methods $methods_block:tt
)?
$(
impls {
$( $trait_tokens:tt )*
}
)?
) => {
$(#[$meta])*
#[cfg(not(feature = $feature))]
#[derive(Debug)]
pub struct $Name;
#[cfg(not(feature = $feature))]
$crate::backends::macros::_impl_stub_methods!($Name, $feature, $err $(, $methods_block)?);
#[cfg(not(feature = $feature))]
impl $crate::Model for $Name {
fn extract_entities(
&self,
_text: &str,
_language: Option<$crate::Language>,
) -> $crate::Result<Vec<$crate::Entity>> {
Err($crate::Error::FeatureNotAvailable($err.to_string()))
}
fn supported_types(&self) -> Vec<$crate::EntityType> {
vec![]
}
fn is_available(&self) -> bool {
false
}
fn name(&self) -> &'static str {
$name
}
fn description(&self) -> &'static str {
$desc
}
}
$(
$crate::backends::macros::_impl_stub_traits!($Name, $feature, $err; $( $trait_tokens )*);
)?
};
}
macro_rules! _impl_stub_traits {
($Name:ident, $feature:literal, $err:expr; ) => {};
($Name:ident, $feature:literal, $err:expr; , $($rest:tt)*) => {
$crate::backends::macros::_impl_stub_traits!($Name, $feature, $err; $($rest)*);
};
($Name:ident, $feature:literal, $err:expr; ZeroShotNER $($rest:tt)*) => {
#[cfg(not(feature = $feature))]
impl $crate::backends::inference::ZeroShotNER for $Name {
fn extract_with_types(
&self,
_text: &str,
_entity_types: &[&str],
_threshold: f32,
) -> $crate::Result<Vec<$crate::Entity>> {
Err($crate::Error::FeatureNotAvailable($err.to_string()))
}
fn extract_with_descriptions(
&self,
_text: &str,
_descriptions: &[&str],
_threshold: f32,
) -> $crate::Result<Vec<$crate::Entity>> {
Err($crate::Error::FeatureNotAvailable($err.to_string()))
}
fn default_types(&self) -> &[&'static str] {
&[]
}
}
$crate::backends::macros::_impl_stub_traits!($Name, $feature, $err; $( $rest )*);
};
}
macro_rules! _impl_stub_methods {
($Name:ident, $feature:literal, $err:expr, { $($methods_tokens:tt)* }) => {
impl $Name {
pub fn new(_model_name: &str) -> $crate::Result<Self> {
Err($crate::Error::FeatureNotAvailable(
concat!($err, ". Build with: cargo build --features ", $feature).to_string(),
))
}
$($methods_tokens)*
}
};
($Name:ident, $feature:literal, $err:expr) => {
impl $Name {
pub fn new(_model_name: &str) -> $crate::Result<Self> {
Err($crate::Error::FeatureNotAvailable(
concat!($err, ". Build with: cargo build --features ", $feature).to_string(),
))
}
}
};
}
#[allow(unused_imports)]
pub(crate) use _impl_stub_methods;
#[allow(unused_imports)]
pub(crate) use _impl_stub_traits;
#[allow(unused_imports)]
pub(crate) use define_feature_stub;