aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/attr.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-12-07 17:49:03 +0000
committerLukas Wirth <[email protected]>2020-12-07 18:58:17 +0000
commit1caaa201fa55caaedaa124d23934c178bdf15b18 (patch)
tree2b4dcb3c1df22ad3bd05034e314ad0a35ca0d2c0 /crates/hir_def/src/attr.rs
parentb3652ef2886e01f772559aa90df4c45e7c7fb1fd (diff)
Remove hir_def/docs.rs module
Diffstat (limited to 'crates/hir_def/src/attr.rs')
-rw-r--r--crates/hir_def/src/attr.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index 7825290e6..98293aad3 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -15,7 +15,6 @@ use tt::Subtree;
15 15
16use crate::{ 16use crate::{
17 db::DefDatabase, 17 db::DefDatabase,
18 docs::Documentation,
19 item_tree::{ItemTreeId, ItemTreeNode}, 18 item_tree::{ItemTreeId, ItemTreeNode},
20 nameres::ModuleSource, 19 nameres::ModuleSource,
21 path::ModPath, 20 path::ModPath,
@@ -23,6 +22,22 @@ use crate::{
23 AdtId, AttrDefId, Lookup, 22 AdtId, AttrDefId, Lookup,
24}; 23};
25 24
25/// Holds documentation
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct Documentation(Arc<str>);
28
29impl Documentation {
30 pub fn as_str(&self) -> &str {
31 &self.0
32 }
33}
34
35impl Into<String> for Documentation {
36 fn into(self) -> String {
37 self.as_str().to_owned()
38 }
39}
40
26#[derive(Default, Debug, Clone, PartialEq, Eq)] 41#[derive(Default, Debug, Clone, PartialEq, Eq)]
27pub struct Attrs { 42pub struct Attrs {
28 entries: Option<Arc<[Attr]>>, 43 entries: Option<Arc<[Attr]>>,
@@ -102,7 +117,7 @@ impl Attrs {
102 }, 117 },
103 ); 118 );
104 let mut attrs = owner.attrs().peekable(); 119 let mut attrs = owner.attrs().peekable();
105 let entries = if attrs.peek().is_none() { 120 let entries = if attrs.peek().is_none() && docs.is_none() {
106 // Avoid heap allocation 121 // Avoid heap allocation
107 None 122 None
108 } else { 123 } else {
@@ -154,7 +169,11 @@ impl Attrs {
154 .intersperse(&SmolStr::new_inline("\n")) 169 .intersperse(&SmolStr::new_inline("\n"))
155 // No FromIterator<SmolStr> for String 170 // No FromIterator<SmolStr> for String
156 .for_each(|s| docs.push_str(s.as_str())); 171 .for_each(|s| docs.push_str(s.as_str()));
157 if docs.is_empty() { None } else { Some(docs) }.map(|it| Documentation::new(&it)) 172 if docs.is_empty() {
173 None
174 } else {
175 Some(Documentation(docs.into()))
176 }
158 } 177 }
159} 178}
160 179