Skip to content

Commit 8d96c1a

Browse files
remove anyhow requirement
1 parent 4a17f12 commit 8d96c1a

File tree

7 files changed

+138
-90
lines changed

7 files changed

+138
-90
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ categories = ["embedded", "no-std", "network-programming"]
1111
readme = "README.md"
1212

1313
[dependencies]
14-
anyhow = "1.0.58"
1514
async-std = { version = "1.12.0", optional = true }
15+
async-trait = { version = "0.1.56", optional = true }
1616
base64 = { version = "0.13.0", default-features = false }
1717
base64-simd = { version = "0.5.0", default-features = false, optional = true }
1818
byteorder = { version = "1.4.3", default-features = false }
@@ -43,7 +43,7 @@ tokio-stream = { version = "0.1.9", features = ["net"] }
4343
default = ["std"]
4444
# default = []
4545
std = []
46-
async = ["std"]
46+
async = ["std", "async-trait"]
4747
tokio = ["dep:tokio", "async"]
4848
futures = ["dep:futures", "async"]
4949
smol = ["dep:smol", "async"]

examples/client/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ use embedded_websocket::{
1313
framer::{Framer, FramerError, ReadResult},
1414
WebSocketClient, WebSocketCloseStatusCode, WebSocketOptions, WebSocketSendMessageType,
1515
};
16-
use std::net::TcpStream;
16+
use std::{error::Error, net::TcpStream};
1717

18-
fn main() -> Result<(), FramerError> {
18+
fn main() -> Result<(), FramerError<impl Error>> {
1919
// open a TCP stream to localhost port 1337
2020
let address = "127.0.0.1:1337";
2121
println!("Connecting to: {}", address);
22-
let mut stream = TcpStream::connect(address)
23-
.map_err(anyhow::Error::new)
24-
.map_err(FramerError::Io)?;
22+
let mut stream = TcpStream::connect(address).map_err(FramerError::Io)?;
2523
println!("Connected.");
2624

2725
let mut read_buf = [0; 4000];

examples/client_async/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use embedded_websocket::{
1313
framer::{Framer, FramerError, ReadResult},
1414
WebSocketClient, WebSocketCloseStatusCode, WebSocketOptions, WebSocketSendMessageType,
1515
};
16+
use std::error::Error;
1617

1718
cfg_if::cfg_if! {
1819
if #[cfg(feature = "tokio")] {
@@ -27,14 +28,11 @@ cfg_if::cfg_if! {
2728
#[cfg_attr(feature = "async-std", async_std::main)]
2829
#[cfg_attr(feature = "tokio", tokio::main)]
2930
#[cfg_attr(feature = "smol", smol_potat::main)]
30-
async fn main() -> Result<(), FramerError> {
31+
async fn main() -> Result<(), FramerError<impl Error>> {
3132
// open a TCP stream to localhost port 1337
3233
let address = "127.0.0.1:1337";
3334
println!("Connecting to: {}", address);
34-
let mut stream = TcpStream::connect(address)
35-
.await
36-
.map_err(anyhow::Error::new)
37-
.map_err(FramerError::Io)?;
35+
let mut stream = TcpStream::connect(address).await.map_err(FramerError::Io)?;
3836
println!("Connected.");
3937

4038
let mut read_buf = [0; 4000];

examples/server/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Result<T> = std::result::Result<T, WebServerError>;
2727
#[derive(Debug)]
2828
pub enum WebServerError {
2929
Io(std::io::Error),
30-
Framer(FramerError),
30+
Framer(FramerError<std::io::Error>),
3131
WebSocket(ws::Error),
3232
HttpError(String),
3333
Utf8Error,
@@ -39,8 +39,8 @@ impl From<std::io::Error> for WebServerError {
3939
}
4040
}
4141

42-
impl From<FramerError> for WebServerError {
43-
fn from(err: FramerError) -> WebServerError {
42+
impl From<FramerError<std::io::Error>> for WebServerError {
43+
fn from(err: FramerError<std::io::Error>) -> WebServerError {
4444
WebServerError::Framer(err)
4545
}
4646
}

examples/server_async/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cfg_if::cfg_if! {
4747
#[derive(Debug)]
4848
pub enum WebServerError {
4949
Io(std::io::Error),
50-
Framer(FramerError),
50+
Framer(FramerError<std::io::Error>),
5151
WebSocket(ws::Error),
5252
HttpError(String),
5353
Utf8Error,
@@ -59,8 +59,8 @@ impl From<std::io::Error> for WebServerError {
5959
}
6060
}
6161

62-
impl From<FramerError> for WebServerError {
63-
fn from(err: FramerError) -> WebServerError {
62+
impl From<FramerError<std::io::Error>> for WebServerError {
63+
fn from(err: FramerError<std::io::Error>) -> WebServerError {
6464
WebServerError::Framer(err)
6565
}
6666
}

0 commit comments

Comments
 (0)