]> git.lizzy.rs Git - rust.git/blob - crates/ra_hir/src/docs.rs
330d8f8f456e414b573b6b7b5c840ede3b879411
[rust.git] / crates / ra_hir / src / docs.rs
1 use ra_syntax::ast;
2
3 use crate::HirDatabase;
4
5 #[derive(Debug, Clone)]
6 pub struct Documentation(String);
7
8 impl Documentation {
9     pub fn new(s: &str) -> Self {
10         Self(s.into())
11     }
12
13     pub fn contents(&self) -> &str {
14         &self.0
15     }
16 }
17
18 impl Into<String> for Documentation {
19     fn into(self) -> String {
20         self.contents().into()
21     }
22 }
23
24 pub trait Docs {
25     fn docs(&self, db: &impl HirDatabase) -> Option<Documentation>;
26 }
27
28 pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> {
29     let comments = node.doc_comment_text();
30     if comments.is_empty() {
31         None
32     } else {
33         Some(Documentation::new(&comments))
34     }
35 }