Remove direct dependency on thiserror
Thiserror is still a transitive dependency due to tungstenite.
This commit is contained in:
parent
34eda3dbd1
commit
547256b842
4 changed files with 58 additions and 16 deletions
|
|
@ -6,7 +6,6 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.147", features = ["derive"] }
|
serde = { version = "1.0.147", features = ["derive"] }
|
||||||
serde_json = "1.0.87"
|
serde_json = "1.0.87"
|
||||||
thiserror = "1.0.37"
|
|
||||||
time = { version = "0.3.15", features = ["serde"] }
|
time = { version = "0.3.15", features = ["serde"] }
|
||||||
tokio = { version = "1.21.2", features = ["time", "sync", "macros", "rt"] }
|
tokio = { version = "1.21.2", features = ["time", "sync", "macros", "rt"] }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
// so I'm turning it off for the entire module.
|
// so I'm turning it off for the entire module.
|
||||||
#![allow(clippy::use_self)]
|
#![allow(clippy::use_self)]
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::{error, fmt};
|
||||||
|
|
||||||
use serde::{de, ser, Deserialize, Serialize};
|
use serde::{de, ser, Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
@ -324,12 +324,36 @@ impl fmt::Display for Snowflake {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug)]
|
||||||
pub enum ParseSnowflakeError {
|
pub enum ParseSnowflakeError {
|
||||||
#[error("invalid length: expected 13 bytes, got {0}")]
|
|
||||||
InvalidLength(usize),
|
InvalidLength(usize),
|
||||||
#[error("{0}")]
|
ParseIntError(ParseIntError),
|
||||||
ParseIntError(#[from] ParseIntError),
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ParseSnowflakeError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::InvalidLength(l) => {
|
||||||
|
write!(f, "invalid length: expected 13 bytes, got {l}")
|
||||||
|
}
|
||||||
|
Self::ParseIntError(from) => write!(f, "{from}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl error::Error for ParseSnowflakeError {
|
||||||
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||||
|
match self {
|
||||||
|
Self::InvalidLength(_) => None,
|
||||||
|
Self::ParseIntError(from) => Some(from),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParseIntError> for ParseSnowflakeError {
|
||||||
|
fn from(err: ParseIntError) -> Self {
|
||||||
|
Self::ParseIntError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Snowflake {
|
impl FromStr for Snowflake {
|
||||||
|
|
|
||||||
21
src/conn.rs
21
src/conn.rs
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::error;
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::{error, fmt};
|
||||||
|
|
||||||
use futures::channel::oneshot;
|
use futures::channel::oneshot;
|
||||||
use futures::stream::{SplitSink, SplitStream};
|
use futures::stream::{SplitSink, SplitStream};
|
||||||
|
|
@ -25,18 +25,27 @@ use crate::replies::{self, PendingReply, Replies};
|
||||||
|
|
||||||
pub type WsStream = WebSocketStream<MaybeTlsStream<TcpStream>>;
|
pub type WsStream = WebSocketStream<MaybeTlsStream<TcpStream>>;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("connection closed")]
|
|
||||||
ConnectionClosed,
|
ConnectionClosed,
|
||||||
#[error("packet timed out")]
|
|
||||||
TimedOut,
|
TimedOut,
|
||||||
#[error("incorrect reply type")]
|
|
||||||
IncorrectReplyType,
|
IncorrectReplyType,
|
||||||
#[error("{0}")]
|
|
||||||
Euph(String),
|
Euph(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::ConnectionClosed => write!(f, "connection closed"),
|
||||||
|
Self::TimedOut => write!(f, "packet timed out"),
|
||||||
|
Self::IncorrectReplyType => write!(f, "incorrect reply type"),
|
||||||
|
Self::Euph(error_msg) => write!(f, "{error_msg}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl error::Error for Error {}
|
||||||
|
|
||||||
type InternalResult<T> = Result<T, Box<dyn error::Error>>;
|
type InternalResult<T> = Result<T, Box<dyn error::Error>>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,29 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::result;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::{error, result};
|
||||||
|
|
||||||
use tokio::sync::oneshot::{self, Receiver, Sender};
|
use tokio::sync::oneshot::{self, Receiver, Sender};
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("timed out")]
|
|
||||||
TimedOut,
|
TimedOut,
|
||||||
#[error("canceled")]
|
|
||||||
Canceled,
|
Canceled,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::TimedOut => write!(f, "timed out"),
|
||||||
|
Self::Canceled => write!(f, "canceled"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl error::Error for Error {}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue