Async-graphql DataLoader lifetime problem
⚓ Rust 📅 2026-03-05 👤 surdeus 👁️ 4Hi,
I try to use DataLoader with async-graphq.
But I got a lifetime problem that I do not understand.
The profile of the function load is :
/// Trait for batch loading.
#[cfg_attr(feature = "boxed-trait", async_trait::async_trait)]
pub trait Loader<K: Send + Sync + Hash + Eq + Clone + 'static>: Send + Sync + 'static {
/// type of value.
type Value: Send + Sync + Clone + 'static;
/// Type of error.
type Error: Send + Clone + 'static;
/// Load the data set specified by the `keys`.
#[cfg(feature = "boxed-trait")]
async fn load(&self, keys: &[K]) -> Result<HashMap<K, Self::Value>, Self::Error>;
And I try to use String or SomeStruct(String) as keys...
#[async_trait]
impl Loader<String> for ParameteByIdLoader {
type Value = Parameter;
type Error = async_graphql::Error;
async fn load(
&self,
ids: &[String],
) -> Result<HashMap<String, Self::Value>, Self::Error> {
...
I have the following error :
error[E0195]: lifetime parameters or bounds on method `load` do not match the trait declaration
...
|
49 | async fn load(
| ______________^
50 | | &self,
51 | | ids: &[String],
52 | | ) -> Result<HashMap<String, Self::Value>, Self::Error> {
| |_____^ lifetimes do not match method in trait
Can you help me on what usage I am wrong, please ?
2 posts - 2 participants
🏷️ Rust_feed