Removed the anyhow crate and added the error mod instead
parent
25863f9e46
commit
88816705fb
|
@ -8,10 +8,9 @@ authors = ["Wynd"]
|
||||||
members = ["examples/*"]
|
members = ["examples/*"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.198", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.116" }
|
serde_json = { version = "1" }
|
||||||
reqwest = { version = "0.12.4", features = ["json", "blocking"] }
|
reqwest = { version = "0.12", features = ["json", "blocking"] }
|
||||||
anyhow = { version = "1.0.82" }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
sync = []
|
sync = []
|
|
@ -7,4 +7,3 @@ authors = ["Wynd"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
playerdb-rs = { path = "../../"}
|
playerdb-rs = { path = "../../"}
|
||||||
tokio = { version = "1.37", features = ["full"] }
|
tokio = { version = "1.37", features = ["full"] }
|
||||||
anyhow = { version = "1" }
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use playerdb_rs::PlayerDBApi;
|
use playerdb_rs::{error::Result, PlayerDBApi};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let api = PlayerDBApi::default();
|
let api = PlayerDBApi::default();
|
||||||
|
|
||||||
let res = api.get_minecraft_player("notch").await?;
|
let res = api.get_minecraft_player("notch").await?;
|
||||||
|
|
||||||
print!("{:#?}", res);
|
println!("{res:#?}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use playerdb_rs::sync::PlayerDBApi;
|
use playerdb_rs::{error::Result, sync::PlayerDBApi};
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<()> {
|
||||||
let api = PlayerDBApi::default();
|
let api = PlayerDBApi::default();
|
||||||
|
|
||||||
let res = api.get_minecraft_player("notch");
|
let res = api.get_minecraft_player("notch")?;
|
||||||
|
|
||||||
match res {
|
println!("{res:#?}");
|
||||||
Ok(x) => println!("{:#?}", x),
|
|
||||||
Err(e) => eprintln!("{e}"),
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
Other(String),
|
||||||
|
|
||||||
|
Reqwest(reqwest::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Error {
|
||||||
|
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
||||||
|
write!(fmt, "{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for Error {
|
||||||
|
fn from(val: &str) -> Self {
|
||||||
|
Self::Other(val.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<reqwest::Error> for Error {
|
||||||
|
fn from(err: reqwest::Error) -> Self {
|
||||||
|
Self::Reqwest(err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use crate::error::Result;
|
||||||
|
|
||||||
|
pub mod error;
|
||||||
pub mod minecraft;
|
pub mod minecraft;
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use crate::{error::Result, minecraft, APP_USER_AGENT, BASE_URI};
|
||||||
|
|
||||||
use crate::{minecraft, APP_USER_AGENT, BASE_URI};
|
|
||||||
|
|
||||||
pub struct PlayerDBApi {
|
pub struct PlayerDBApi {
|
||||||
agent: Arc<reqwest::blocking::Client>,
|
agent: Arc<reqwest::blocking::Client>,
|
||||||
|
|
Loading…
Reference in New Issue