rune/compile/
docs.rs
1use crate as rune;
2use crate::alloc;
3use crate::alloc::prelude::*;
4#[cfg(feature = "doc")]
5use crate::alloc::{String, Vec};
6
7#[derive(Debug, TryClone)]
11pub(crate) struct Docs {
12 #[cfg(feature = "doc")]
14 docs: Vec<String>,
15 #[cfg(feature = "doc")]
17 arguments: Option<Vec<String>>,
18}
19
20impl Docs {
21 pub(crate) const EMPTY: Docs = Docs {
22 #[cfg(feature = "doc")]
23 docs: Vec::new(),
24 #[cfg(feature = "doc")]
25 arguments: None,
26 };
27
28 #[cfg(feature = "doc")]
30 pub(crate) fn args(&self) -> &[String] {
31 self.arguments.as_deref().unwrap_or_default()
32 }
33
34 #[cfg(all(feature = "doc", any(feature = "languageserver", feature = "cli")))]
36 pub(crate) fn lines(&self) -> &[String] {
37 &self.docs
38 }
39
40 #[cfg(feature = "doc")]
42 pub(crate) fn set_docs(
43 &mut self,
44 docs: impl IntoIterator<Item: AsRef<str>>,
45 ) -> alloc::Result<()> {
46 self.docs.clear();
47
48 for line in docs {
49 self.docs.try_push(line.as_ref().try_to_owned()?)?;
50 }
51
52 Ok(())
53 }
54
55 #[cfg(not(feature = "doc"))]
56 pub(crate) fn set_docs(&mut self, _: impl IntoIterator<Item: AsRef<str>>) -> alloc::Result<()> {
57 Ok(())
58 }
59
60 #[cfg(feature = "doc")]
62 pub(crate) fn set_arguments(
63 &mut self,
64 arguments: impl IntoIterator<Item: AsRef<str>>,
65 ) -> alloc::Result<()> {
66 let mut out = self.arguments.take().unwrap_or_default();
67 out.clear();
68
69 for argument in arguments {
70 out.try_push(argument.as_ref().try_to_owned()?)?;
71 }
72
73 self.arguments = Some(out);
74 Ok(())
75 }
76
77 #[cfg(not(feature = "doc"))]
78 pub(crate) fn set_arguments(
79 &mut self,
80 _: impl IntoIterator<Item: AsRef<str>>,
81 ) -> alloc::Result<()> {
82 Ok(())
83 }
84}
85
86impl Default for Docs {
87 #[inline]
88 fn default() -> Self {
89 Self::EMPTY
90 }
91}