Skip to content

Commit e149693

Browse files
committed
use anyhow::Error everywhere.
1 parent d578883 commit e149693

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

java-spaghetti-gen/src/emit/classes.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::HashSet;
2-
use std::error::Error;
32
use std::fmt::Write;
43

54
use proc_macro2::TokenStream;
@@ -20,7 +19,7 @@ pub(crate) struct StructPaths {
2019
}
2120

2221
impl StructPaths {
23-
pub(crate) fn new(class: Id) -> Result<Self, Box<dyn Error>> {
22+
pub(crate) fn new(class: Id) -> Result<Self, anyhow::Error> {
2423
Ok(Self {
2524
mod_: Class::mod_for(class)?,
2625
struct_name: Class::name_for(class)?,
@@ -34,7 +33,7 @@ pub(crate) struct Class {
3433
pub java: JavaClass,
3534
}
3635

37-
fn rust_id(id: &str) -> Result<String, Box<dyn Error>> {
36+
fn rust_id(id: &str) -> Result<String, anyhow::Error> {
3837
Ok(match RustIdentifier::from_str(id) {
3938
RustIdentifier::Identifier(id) => id,
4039
RustIdentifier::KeywordRawSafe(id) => id,
@@ -47,7 +46,7 @@ fn rust_id(id: &str) -> Result<String, Box<dyn Error>> {
4746
}
4847

4948
impl Class {
50-
pub(crate) fn mod_for(class: Id) -> Result<String, Box<dyn Error>> {
49+
pub(crate) fn mod_for(class: Id) -> Result<String, anyhow::Error> {
5150
let mut buf = String::new();
5251
for component in class {
5352
match component {
@@ -64,7 +63,7 @@ impl Class {
6463
Ok(buf)
6564
}
6665

67-
pub(crate) fn name_for(class: Id) -> Result<String, Box<dyn Error>> {
66+
pub(crate) fn name_for(class: Id) -> Result<String, anyhow::Error> {
6867
let mut buf = String::new();
6968
for component in class.iter() {
7069
match component {
@@ -76,7 +75,7 @@ impl Class {
7675
Ok(buf)
7776
}
7877

79-
pub(crate) fn new(java: JavaClass) -> Result<Self, Box<dyn Error>> {
78+
pub(crate) fn new(java: JavaClass) -> Result<Self, anyhow::Error> {
8079
let rust = StructPaths::new(java.path())?;
8180

8281
Ok(Self { rust, java })

java-spaghetti-gen/src/emit/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod modules;
1010
mod preamble;
1111

1212
use std::collections::HashMap;
13-
use std::error::Error;
1413
use std::ffi::CString;
1514
use std::io;
1615
use std::rc::Rc;
@@ -50,7 +49,7 @@ impl<'a> Context<'a> {
5049
.unwrap()
5150
}
5251

53-
pub fn java_to_rust_path(&self, java_class: parser_util::Id, mod_: &str) -> Result<TokenStream, Box<dyn Error>> {
52+
pub fn java_to_rust_path(&self, java_class: parser_util::Id, mod_: &str) -> Result<TokenStream, anyhow::Error> {
5453
let m = Class::mod_for(java_class)?;
5554
let s = Class::name_for(java_class)?;
5655
let fqn = format!("{m}::{s}");
@@ -85,7 +84,7 @@ impl<'a> Context<'a> {
8584
Ok(res)
8685
}
8786

88-
pub fn add_class(&mut self, class: parser_util::JavaClass) -> Result<(), Box<dyn Error>> {
87+
pub fn add_class(&mut self, class: parser_util::JavaClass) -> Result<(), anyhow::Error> {
8988
let cc = self.config.resolve_class(class.path().as_str());
9089
if !cc.include {
9190
return Ok(());

java-spaghetti-gen/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod emit;
66
mod identifiers;
77
mod parser_util;
88

9-
use std::error::Error;
109
use std::fs::File;
1110
use std::io::{self, Read};
1211
use std::path::{Path, PathBuf};
@@ -17,7 +16,7 @@ use crate::config::Config;
1716
use crate::parser_util::JavaClass;
1817

1918
/// The core function of this library: Generate Rust code to access Java APIs.
20-
pub fn run(config: impl Into<Config>) -> Result<(), Box<dyn Error>> {
19+
pub fn run(config: impl Into<Config>) -> Result<(), anyhow::Error> {
2120
let config: Config = config.into();
2221
println!("output: {}", config.output.display());
2322

@@ -38,7 +37,7 @@ pub fn run(config: impl Into<Config>) -> Result<(), Box<dyn Error>> {
3837
Ok(())
3938
}
4039

41-
fn gather_file(context: &mut emit::Context, path: &Path) -> Result<(), Box<dyn Error>> {
40+
fn gather_file(context: &mut emit::Context, path: &Path) -> Result<(), anyhow::Error> {
4241
let verbose = context.config.logging_verbose;
4342

4443
context

0 commit comments

Comments
 (0)