-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add functionality to export doc strings on types #187
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fd9ec17
added implementation and tests for type docs
timephy 0208eea
fix test with all features + syntax
timephy d3ed791
refactor
timephy 2fd04d5
Make format_docs private
escritorio-gustavo 1e0aeb6
Merge remote-tracking branch 'upstream/main'
escritorio-gustavo 1e00f1d
Tests should expect type instead of interface
escritorio-gustavo 8f921f9
Update formatting
escritorio-gustavo 76e0bf4
Add docs to EnumAttr and StrucAttr
escritorio-gustavo e9385cb
Turn docs into &'static str
escritorio-gustavo 2958a6d
Change .len() for .is_empty()
escritorio-gustavo 5e38c59
Run cargo fmt
escritorio-gustavo 0246d3e
Merge remote-tracking branch 'upstream/main'
escritorio-gustavo 545586c
generate `const Docs = None` if no docs are present, instead of omiti…
timephy d2df20f
undo last commit
timephy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use std::convert::TryFrom; | ||
|
||
use proc_macro2::Ident; | ||
use syn::{Attribute, Error, Result}; | ||
use syn::{spanned::Spanned, Attribute, Error, Expr, ExprLit, Lit, Meta, Result}; | ||
|
||
macro_rules! syn_err { | ||
($l:literal $(, $a:expr)*) => { | ||
|
@@ -116,6 +116,24 @@ pub fn parse_serde_attrs<'a, A: TryFrom<&'a Attribute, Error = Error>>( | |
.into_iter() | ||
} | ||
|
||
/// Return a vector of all lines of doc comments in the given vector of attributes. | ||
pub fn parse_docs(attrs: &[Attribute]) -> Result<Vec<String>> { | ||
attrs | ||
.into_iter() | ||
.filter_map(|a| match a.meta { | ||
Meta::NameValue(ref x) if x.path.is_ident("doc") => Some(x), | ||
_ => None, | ||
}) | ||
.map(|attr| match attr.value { | ||
Expr::Lit(ExprLit { | ||
lit: Lit::Str(ref str), | ||
.. | ||
}) => Ok(str.value()), | ||
_ => syn_err!(attr.span(); "doc attribute with non literal expression found"), | ||
}) | ||
.collect::<Result<Vec<_>>>() | ||
Comment on lines
+121
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Managed to get rid of those |
||
} | ||
|
||
#[cfg(feature = "serde-compat")] | ||
mod warning { | ||
use std::{fmt::Display, io::Write}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always prefer
&[T]
over&Vec<T>