Skip to content

Replace failure with anyhow. #6

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ quote = "1.0"
enum-utils-from-str = { path = "from-str", version = "0.1.2" }
serde_derive_internals = "0.25"
syn = { version = "1.0", features = ["extra-traits"] }

[dependencies.failure]
version = "0.1"
default-features = false
features = ["std"]
anyhow = "1.0"

[dev-dependencies]
version-sync = "0.8"
18 changes: 9 additions & 9 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{BTreeSet, LinkedList};
use std::convert::{TryFrom, TryInto};
use std::fmt;

use failure::{bail, format_err, Fallible};
use anyhow::{bail, format_err, Result};

#[derive(Debug, Clone, Copy)]
pub enum Primitive {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Primitive {
}

pub fn parse_primitive_repr<'a>(attrs: impl 'a + Iterator<Item = &'a syn::Attribute>)
-> Fallible<Option<(Primitive, syn::Path)>>
-> Result<Option<(Primitive, syn::Path)>>
{
let mut repr = None;
for attr in attrs {
Expand Down Expand Up @@ -117,13 +117,13 @@ impl fmt::Debug for RenameRule {
}
}

pub type ErrorList = LinkedList<failure::Error>;
pub type ErrorList = LinkedList<anyhow::Error>;

macro_rules! bail_list {
($msg:literal $( , $args:expr )* $(,)?) => {
{
let mut list = ErrorList::new();
list.push_back(failure::format_err!($msg, $($args),*));
list.push_back(anyhow::format_err!($msg, $($args),*));
return Err(list);
}
}
Expand All @@ -139,7 +139,7 @@ pub enum Attr {
}

impl Attr {
pub fn parse_attrs(attr: &syn::Attribute) -> impl Iterator<Item = Fallible<Self>> {
pub fn parse_attrs(attr: &syn::Attribute) -> impl Iterator<Item = Result<Self>> {
use syn::NestedMeta;

Self::get_args(attr)
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Attr {

/// Parse an attr from the `syn::Meta` inside parens after "enumeration".
impl TryFrom<&'_ syn::Meta> for Attr {
type Error = failure::Error;
type Error = anyhow::Error;

fn try_from(meta: &syn::Meta) -> Result<Self, Self::Error> {
use syn::{Lit, Meta, MetaNameValue};
Expand Down Expand Up @@ -217,7 +217,7 @@ pub struct VariantAttrs {

impl VariantAttrs {
pub fn from_attrs<T>(attrs: T) -> Result<Self, ErrorList>
where T: IntoIterator<Item = Fallible<Attr>>,
where T: IntoIterator<Item = Result<Attr>>,
{
let mut ret = VariantAttrs::default();
let mut errors = ErrorList::default();
Expand Down Expand Up @@ -258,7 +258,7 @@ pub struct EnumAttrs {

impl EnumAttrs {
pub fn from_attrs<T>(attrs: T) -> Result<Self, ErrorList>
where T: IntoIterator<Item = Fallible<Attr>>,
where T: IntoIterator<Item = Result<Attr>>,
{
let mut ret = EnumAttrs::default();
let mut errors = ErrorList::default();
Expand Down Expand Up @@ -295,7 +295,7 @@ pub struct Enum<'a> {

/// This will be `None` if no `#[repr]` was specified, or an error if parsing failed or
/// multiple `#[repr]`s were specified.
pub primitive_repr: Fallible<Option<(Primitive, syn::Path)>>,
pub primitive_repr: Result<Option<(Primitive, syn::Path)>>,

pub variants: Vec<(&'a syn::Variant, VariantAttrs)>,

Expand Down
2 changes: 1 addition & 1 deletion src/conv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use failure::format_err;
use anyhow::format_err;
use proc_macro2::{TokenStream, Span};
use quote::quote;

Expand Down
2 changes: 1 addition & 1 deletion src/from_str.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use failure::format_err;
use anyhow::format_err;
use proc_macro2::TokenStream;
use quote::quote;

Expand Down
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::{Range, RangeInclusive};

use failure::format_err;
use anyhow::format_err;
use proc_macro2::{Literal, TokenStream};
use quote::quote;

Expand Down