tokio-tun
tokio-tun copied to clipboard
Send + Sync bounds on the Error type seem to be unnecessary
I started building a small project using this crate and quickly found that the bounds on the return type from TunBuilder::try_build
were slowly spreading throughout my project so I dove in to see why it was necessary.
I took Send + Sync
from Error
here: https://github.com/yaa110/tokio-tun/blob/master/src/result.rs#L2 and the crate builds fine. Is there a particular reason to require these traits?
My main issue is that it cannot be trivially converted to and from std::result::Result<T, Box<dyn std::error::Error>>
so it ends up spreading throughout.
If I try to return it in a function that returns Result<(), Box<dyn std::error::Error>>
, I get this error:
error[E0277]: the size for values of type `dyn std::error::Error + Sync + std::marker::Send` cannot be known at compilation time
--> src/bin/main.rs:11:45
|
11 | let mut netty = NettyStack::new(if_name)?;
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn std::error::Error + Sync + std::marker::Send`
= note: required because of the requirements on the impl of `std::error::Error` for `Box<dyn std::error::Error + Sync + std::marker::Send>`
= note: required because of the requirements on the impl of `From<Box<dyn std::error::Error + Sync + std::marker::Send>>` for `Box<dyn std::error::Error>`
= note: required because of the requirements on the impl of `FromResidual<Result<Infallible, Box<dyn std::error::Error + Sync + std::marker::Send>>>` for `Result<(), Box<dyn std::error::Error>>`
If I try to return Result<T, Box<dyn std::error::Error>>
in a function that returns Result<T, Box<dyn std::error::Error + Send + Sync>>
:
error[E0277]: the size for values of type `dyn std::error::Error` cannot be known at compilation time
--> src/bin/main.rs:15:74
|
15 | add_address(if_name, Ipv4Addr::new(10, 0, 0, 1).into(), handle).await?;
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn std::error::Error`
= note: required because of the requirements on the impl of `std::error::Error` for `Box<dyn std::error::Error>`
= note: required because of the requirements on the impl of `From<Box<dyn std::error::Error>>` for `Box<dyn std::error::Error + Sync + std::marker::Send>`
= note: required because of the requirements on the impl of `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>` for `Result<(), Box<dyn std::error::Error + Sync + std::marker::Send>>`