-
-
Notifications
You must be signed in to change notification settings - Fork 127
fix(contacts): use fn items for LID mapping extractors so boxed futures compile #826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //! Compile-time regression guard for issue #825. | ||
| //! | ||
| //! Public async methods whose future type embeds a closure returning | ||
| //! references (e.g. an iterator adapter passed to a generic helper) fail with | ||
| //! "implementation of `FnOnce` is not general enough" ONLY when a downstream | ||
| //! caller boxes the future, which is exactly what `#[async_trait]` does. The | ||
| //! library's own tests never box that way, so this file reproduces the | ||
| //! consumer shape: if it compiles, the guard passes. | ||
|
|
||
| use async_trait::async_trait; | ||
| use std::sync::Arc; | ||
| use tokio::sync::RwLock; | ||
| use wacore_binary::Jid; | ||
| use whatsapp_rust::client::Client; | ||
|
|
||
| #[async_trait] | ||
| pub trait WhatsAppGateway: Send + Sync { | ||
| async fn check_phones(&self, phones: Vec<String>) -> Result<Vec<bool>, String>; | ||
| async fn statuses(&self, phones: Vec<String>) -> Result<Vec<Option<String>>, String>; | ||
| } | ||
|
|
||
| pub struct GatewayImpl { | ||
| client: RwLock<Option<Arc<Client>>>, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl WhatsAppGateway for GatewayImpl { | ||
| async fn check_phones(&self, phones: Vec<String>) -> Result<Vec<bool>, String> { | ||
| let guard = self.client.read().await; | ||
| let client = guard.as_ref().expect("client").clone(); | ||
| drop(guard); | ||
|
|
||
| let jids: Vec<Jid> = phones.iter().map(|p| Jid::pn(p.as_str())).collect(); | ||
| let results = client | ||
| .contacts() | ||
| .is_on_whatsapp(&jids) | ||
| .await | ||
| .map_err(|e| e.to_string())?; | ||
| Ok(results.into_iter().map(|r| r.is_registered).collect()) | ||
| } | ||
|
|
||
| async fn statuses(&self, phones: Vec<String>) -> Result<Vec<Option<String>>, String> { | ||
| let guard = self.client.read().await; | ||
| let client = guard.as_ref().expect("client").clone(); | ||
| drop(guard); | ||
|
|
||
| let jids: Vec<Jid> = phones.iter().map(|p| Jid::pn(p.as_str())).collect(); | ||
| let info = client | ||
| .contacts() | ||
| .get_user_info(&jids) | ||
| .await | ||
| .map_err(|e| e.to_string())?; | ||
| Ok(jids | ||
| .iter() | ||
| .map(|jid| info.get(jid).and_then(|i| i.status.clone())) | ||
| .collect()) | ||
| } | ||
| } | ||
|
|
||
| /// The guard is the compilation itself; this just keeps the test binary | ||
| /// non-empty and the trait impl reachable. | ||
| #[test] | ||
| fn async_trait_consumers_compile() { | ||
| fn assert_impl<T: WhatsAppGateway>() {} | ||
| assert_impl::<GatewayImpl>(); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AGENTS.md says, “When adding comments to the code, dont be so verbose, also only explain why, not what.” This new doc block explains the implementation mechanics and downstream compiler behavior in detail, including what fn items do, so it violates the local comment guidance and leaves commit/issue-level rationale in source. Please trim it to the minimal why, or move the longer explanation to external documentation.
Useful? React with 👍 / 👎.