/// Parse out a docstring from a user provided string, handling dedenting, trimming, etc.
Parse out a docstring from a user provided string, handling dedenting, trimming, etc.
Parse out a docstring from a user provided string handling dedenting trimming etc .
pub fn from_docstring(user_docstring: &str) -> Option<DocString> {
        let trimmed_docs = user_docstring.trim();
        if trimmed_docs.is_empty() {
            None
        } else {
            static SPLIT_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\n[ ]*\n").unwrap());
            let split: Option<(&str, &str)> = SPLIT_RE.splitn(trimmed_docs, 2).collect_tuple();
            match split {
                Some((summary, details)) if !summary.is_empty() && !details.is_empty() => {
                    // Dedent the details separately so that people can have the summary on the
                    // same line as the opening quotes, and the details indented on subsequent
                    // lines.
                    Some(DocString {
                        summary: summary.to_owned(),
                        details: Some(textwrap::dedent(details).trim().to_owned()),
                    })
                }
                _ => Some(DocString {
                    summary: trimmed_docs.to_owned(),
                    details: None,
                }),
            }
        }
    }
pub fn from_docstring ( user_docstring : & str ) -> Option < DocString > { let trimmed_docs = user_docstring . trim ( ) ; if trimmed_docs . is_empty ( ) { None } else { static SPLIT_RE : Lazy < Regex > = Lazy :: new ( | | Regex :: new ( r"\n[ ]*\n" ) . unwrap ( ) ) ; let split : Option < ( & str , & str ) > = SPLIT_RE . splitn ( trimmed_docs , 2 ) . collect_tuple ( ) ; match split { Some ( ( summary , details ) ) if ! summary . is_empty ( ) && ! details . is_empty ( ) => { // Dedent the details separately so that people can have the summary on the // same line as the opening quotes, and the details indented on subsequent // lines. Some ( DocString { summary : summary . to_owned ( ) , details : Some ( textwrap :: dedent ( details ) . trim ( ) . to_owned ( ) ) , } ) } _ => Some ( DocString { summary : trimmed_docs . to_owned ( ) , details : None , } ) , } } }
Parse out a docstring from a user provided string, handling dedenting, trimming, etc.
Parse out a docstring from a user provided string handling dedenting trimming etc .
user_docstring
&str