Warning
This post was published 36 days ago. The information described in this article may have changed.
struct Criterion {
// ...
}
// This trait definition will not compile unless I add a 'static bound to it,
// apparently because it doesn't want a &'static reference to a type that has
// a non-'static generic parameter (the argument to the function).
// This is an unacceptable limitation for my use case.
// Is there some workaround I can use?
trait SomeTrait {
const CASES: &[(Criterion, fn(Self) -> ReturnType)];
}
fn transform<T: SomeTrait>(value: T, request: String) -> ReturnType {
for (criterion, transform_func) in T::CASES {
if criterion.matches(&request) {
return (transform_func)(value);
}
}
ReturnType::default()
}
4 posts - 2 participants
🏷️ rust_feed