Hello fellow Rustaceans.
I'm struggling to get certain traits to work correctly, and it'll be great if someone could point me to the right direction on how to handle this appropriately.
pub struct ServableFn<F, T>
where
F: Fn(Input<T>) -> Result<Box<dyn Any>, String>,
T: Serialize,
{
pub opts: FunctionOps,
pub trigger: Trigger,
pub func: F,
}
I have this struct where I want func
to be a closure where it accepts an Input<T>
which is a generic struct.
Here's what Input<T>
looks like:
#[derive(Deserialize)]
pub struct Input<T> {
pub event: T,
pub events: Vec<T>,
pub ctx: InputCtx,
}
#[derive(Deserialize)]
pub struct InputCtx {
pub fn_id: String,
pub run_id: String,
// pub step_id: String,
}
The error I'm getting from the compiler is this.
error[E0392]: parameter `T` is never used
--> src/function.rs:57:26
|
57 | pub struct ServableFn<F, T>
| ^ unused parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
For more information about this error, try `rustc --explain E0392`.
Which rightfully claims that T
is not used. However, if I remove T
from the struct signature,
Fn(Input<T>) -> Result<Box<dyn Any>, String>,
will now start failing because it can't see T
in scope anymore.
I gave PhantomData
a try but it makes the code unnecessarily more complicated, and that field is not going to be used so I rather not have it.
How would one approach this issue?
Code is available here.
And this is the unsuccessful changes so far.
Any guidance are appreciated.
Thank you!