struct Test;
impl DraxTransport for Test {
fn write_to_transport(
&self,
context: &mut drax::transport::TransportProcessorContext,
writer: &mut Vec<u8>,
) -> drax::transport::Result<()> {
todo!()
}
fn read_from_transport<R: std::io::Read>(
context: &mut drax::transport::TransportProcessorContext,
read: &mut R,
) -> drax::transport::Result<Self>
where
Self: Sized,
{
todo!()
}
fn precondition_size(
&self,
context: &mut drax::transport::TransportProcessorContext,
) -> drax::transport::Result<usize> {
todo!()
}
}
async fn some_async_fn(prim: Test) {}
fn test() {
let wrapped = WrappedMappingProcessor::<()>::from(some_async_fn);
}
pub struct WrappedMappingProcessor<O> {
boxed_inner: Box<
dyn Fn(
&mut drax::transport::TransportProcessorContext,
Cursor<Vec<u8>>,
) -> drax::transport::Result<Box<dyn Future<Output = O>>>,
>,
}
impl<T: DraxTransport, O, F: Future<Output = O>> From<fn(T) -> F> for WrappedMappingProcessor<O> {
fn from(inner: fn(T) -> F) -> Self {
WrappedMappingProcessor {
boxed_inner: Box::new(move |context, mut cursor| {
let packet = T::read_from_transport(context, &mut cursor)?;
Ok(Box::new((inner)(packet)))
}),
}
}
}``` The error comes from:
```rust
let wrapped = WrappedMappingProcessor::<()>::from(some_async_fn);``` which just says:
```rust
error[E0277]: the trait bound `WrappedMappingProcessor<()>: From<fn(Test) -> impl Future<Output = ()> {some_async_fn}>` is not satisfied
--> src/registry.rs:45:55
|
45 | let wrapped = WrappedMappingProcessor::<()>::from(some_async_fn);
| ----------------------------------- ^^^^^^^^^^^^^ the trait `From<fn(Test) -> impl Future<Output = ()> {some_async_fn}>` is not implemented for `WrappedMappingProcessor<()>`
| |
| required by a bound introduced by this call
|
= help: the trait `From<fn(T) -> F>` is implemented for `WrappedMappingProcessor<O>\```` So I'm a bit confused on where this is coming from. Everything seems to match up properly.
#Trait bounds aren't matching when they seem to match.
5 messages · Page 1 of 1 (latest)
Definitely seems like all of the bound constraints are matched, even in the error it says From<fn(T) -> F> is implemented but Test: DraxTransport is true as shown, and F: Future<Output = ()> matches the O constraint which ties WrappedProcessorContext<O> which is shown in the error message as well
very confused
I feel like it definitely has to do with the T generic being weird, but no clue really
fn some_async_fn(prim: Test) {
}
fn test() {
let wrapped = WrappedMappingProcessor::<()>::from(some_async_fn);
}
pub struct WrappedMappingProcessor<O> {
boxed_inner: Box<
dyn Fn(
&mut drax::transport::TransportProcessorContext,
Cursor<Vec<u8>>,
) -> drax::transport::Result<Box<dyn Future<Output = O>>>,
>,
}
impl<T, O> From<fn(T) -> O> for WrappedMappingProcessor<O> {
fn from(inner: fn(T) -> O) -> Self {
WrappedMappingProcessor {
boxed_inner: Box::new(move |context, mut cursor| {
// let packet = T::read_from_transport(context, &mut cursor)?;
drax::transport::Error::cause("todo")
// Ok(Box::new((inner)(packet)))
}),
}
}
}``` even this fails