Skip to content

Instantly share code, notes, and snippets.

@stella3d
Last active March 26, 2025 20:06
Show Gist options
  • Save stella3d/3a181e863e8610d2ccced3bfdf8daa4b to your computer and use it in GitHub Desktop.
Save stella3d/3a181e863e8610d2ccced3bfdf8daa4b to your computer and use it in GitHub Desktop.
Send not general error example
pub struct ExampleClient { }
impl ExampleClient {
// calling .iter().map(|s| s.as_str()) on a Vec<String>
// and passing it into the function with this signature causes a
// compile error in poem_openapi's macro that compiles the server,
// about Send's implementation not being general enough for &sqlx::Pool<_> and &ShardConfig,
// saying they're only implemented for some &'0 T
pub async fn get_with_str_iter<T>(
&self,
_a: &str,
_b: impl IntoIterator<Item = &str>,
) -> Vec<T> {
// real code calls out to redis using the strs as part of keys
todo!()
}
// passing the same Vec<String> into this version of the function,
// which otherwise does the exact same thing, works fine.
pub async fn get_with_vec<T>(&self, _a: &str, _b: Vec<String>) -> Vec<T> {
todo!()
}
// this one works when the first one failed, but not
// without the where clause, which feels a bit redundant?
pub async fn get_with_str_iter_new<'a, I: IntoIterator<Item = &'a str> + Send, T>(
&self,
_a: &str,
_b: I,
) -> Vec<T>
where
<I as IntoIterator>::IntoIter: Send,
{
todo!()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment