Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Remove anyhow dependency #830

Merged
merged 1 commit into from
Jul 29, 2023
Merged
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
1 change: 0 additions & 1 deletion gtk3-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ rust-version = "1.70"
proc-macro = true

[dependencies]
anyhow = "1.0"
proc-macro-error = "1.0"
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
40 changes: 33 additions & 7 deletions gtk3-macros/src/attribute_parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use anyhow::{bail, Result};
use proc_macro2::Span;
use syn::spanned::Spanned;
use syn::{
Expand Down Expand Up @@ -45,13 +44,40 @@ impl Parse for TemplateSource {
}
}

pub fn parse_template_source(input: &DeriveInput) -> Result<TemplateSource> {
let attr = match input.attrs.iter().find(|a| a.path().is_ident("template")) {
Some(attr) => attr,
_ => bail!("Missing 'template' attribute"),
};
#[derive(Debug)]
pub enum ParseTemplateSourceError {
MissingAttribute,
Parse(syn::Error),
}

bilelmoussaoui marked this conversation as resolved.
Show resolved Hide resolved
impl std::fmt::Display for ParseTemplateSourceError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingAttribute => write!(f, "Missing 'template' attribute"),
Self::Parse(err) => write!(f, "{}", err),
}
}
}

impl std::error::Error for ParseTemplateSourceError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::MissingAttribute => None,
Self::Parse(err) => Some(err),
}
}
}

Ok(attr.parse_args()?)
pub fn parse_template_source(
input: &DeriveInput,
) -> Result<TemplateSource, ParseTemplateSourceError> {
input
.attrs
.iter()
.find(|a| a.path().is_ident("template"))
.ok_or(ParseTemplateSourceError::MissingAttribute)?
.parse_args()
.map_err(ParseTemplateSourceError::Parse)
}

pub enum FieldAttributeArg {
Expand Down
Loading