Skip to content
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

Refactor #133

Merged
merged 6 commits into from Oct 8, 2020
Merged

Refactor #133

merged 6 commits into from Oct 8, 2020

Conversation

jplatte
Copy link
Contributor

@jplatte jplatte commented Oct 7, 2020

No description provided.

Copy link
Owner

@Peternator7 Peternator7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to switch to Result style error handling we should try and switch all the panics to return Err instead.

Otherwise, everything looks great.


for meta in strum_meta {
let meta = match meta {
syn::Meta::NameValue(mv) => mv,
Meta::NameValue(mv) => mv,
_ => panic!("strum on types only supports key-values"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return an Err here was well?

_ => panic!("strum on types only supports key-values"),
};

if meta.path.is_ident("serialize_all") {
let style = match meta.lit {
syn::Lit::Str(s) => s.value(),
Lit::Str(s) => s.value(),
_ => panic!("expected string value for 'serialize_all'"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well.

let name = &ast.ident;
let vis = &ast.vis;

let variants = match ast.data {
syn::Data::Enum(ref v) => &v.variants,
Data::Enum(ref v) => &v.variants,
_ => panic!("EnumDiscriminants only works on Enums"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return a result?

@@ -24,17 +25,19 @@ pub fn enum_iter_inner(ast: &syn::DeriveInput) -> TokenStream {
};

let variants = match ast.data {
syn::Data::Enum(ref v) => &v.variants,
Data::Enum(ref v) => &v.variants,
_ => panic!("EnumIter only works on Enums"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can use Span.call_site() as the error position here.

@jplatte
Copy link
Contributor Author

jplatte commented Oct 8, 2020

Yes, I'm planning to convert more panics to syn::Error. This is just the start :)

@Peternator7 Peternator7 merged commit 4ad3992 into Peternator7:master Oct 8, 2020
@Peternator7
Copy link
Owner

Change is merged. I'm going to hold off publishing a new version until the rest of your changes are in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants