use core::fmt;
#[cfg(feature = "doc")]
use crate::alloc::Box;
#[cfg(feature = "doc")]
use crate::compile::meta;
use crate::compile::{ContextError, Docs};
use crate::function_meta::FunctionArgs;
use crate::runtime::MaybeTypeOf;
pub struct ItemFnMut<'a> {
pub(super) docs: &'a mut Docs,
#[cfg(feature = "doc")]
pub(super) deprecated: &'a mut Option<Box<str>>,
#[cfg(feature = "doc")]
pub(super) is_async: &'a mut bool,
#[cfg(feature = "doc")]
pub(super) args: &'a mut Option<usize>,
#[cfg(feature = "doc")]
pub(super) argument_types: &'a mut Box<[meta::DocType]>,
#[cfg(feature = "doc")]
pub(super) return_type: &'a mut meta::DocType,
}
impl ItemFnMut<'_> {
pub fn docs(self, docs: impl IntoIterator<Item: AsRef<str>>) -> Result<Self, ContextError> {
self.docs.set_docs(docs)?;
Ok(self)
}
pub fn is_async(self, #[cfg_attr(not(feature = "doc"), allow(unused))] is_async: bool) -> Self {
#[cfg(feature = "doc")]
{
*self.is_async = is_async;
}
self
}
pub fn deprecated(
self,
#[cfg_attr(not(feature = "doc"), allow(unused))] deprecated: impl AsRef<str>,
) -> Result<Self, ContextError> {
#[cfg(feature = "doc")]
{
*self.deprecated = Some(deprecated.as_ref().try_into()?);
}
Ok(self)
}
pub fn args(self, #[cfg_attr(not(feature = "doc"), allow(unused))] args: usize) -> Self {
#[cfg(feature = "doc")]
{
*self.args = Some(args);
}
self
}
pub fn return_type<T>(self) -> Result<Self, ContextError>
where
T: MaybeTypeOf,
{
#[cfg(feature = "doc")]
{
*self.return_type = T::maybe_type_of()?;
}
Ok(self)
}
pub fn argument_types<A>(self) -> Result<Self, ContextError>
where
A: FunctionArgs,
{
#[cfg(feature = "doc")]
{
*self.argument_types = A::into_box()?;
*self.args = Some(A::len());
}
Ok(self)
}
}
impl fmt::Debug for ItemFnMut<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ItemFnMut").finish_non_exhaustive()
}
}