rune/module/
item_mut.rs
1use core::fmt;
2
3#[cfg(feature = "doc")]
4use crate::alloc::Box;
5use crate::compile::{ContextError, Docs};
6
7pub struct ItemMut<'a> {
10 pub(super) docs: &'a mut Docs,
11 #[cfg(feature = "doc")]
12 pub(super) deprecated: &'a mut Option<Box<str>>,
13}
14
15impl ItemMut<'_> {
16 pub fn docs(self, docs: impl IntoIterator<Item: AsRef<str>>) -> Result<Self, ContextError> {
20 self.docs.set_docs(docs)?;
21 Ok(self)
22 }
23
24 pub fn static_docs(self, docs: &'static [&'static str]) -> Result<Self, ContextError> {
28 self.docs.set_docs(docs)?;
29 Ok(self)
30 }
31
32 pub fn deprecated<S>(
34 self,
35 #[cfg_attr(not(feature = "doc"), allow(unused))] deprecated: S,
36 ) -> Result<Self, ContextError>
37 where
38 S: AsRef<str>,
39 {
40 #[cfg(feature = "doc")]
41 {
42 *self.deprecated = Some(deprecated.as_ref().try_into()?);
43 }
44
45 Ok(self)
46 }
47}
48
49impl fmt::Debug for ItemMut<'_> {
50 #[inline]
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 f.debug_struct("ItemMut").finish_non_exhaustive()
53 }
54}