twitter - 使用 egg_mode crate 迭代 Twitter 推文的用户时间线
问题描述
我正在使用 rust egg_mode crate 迭代用户的推文时间线,并查看他们是否发布了所需的推文。现在我几乎已经完成了所有工作,但是我无法锻炼如何在循环中处理此代码。
我可能没有正确使用 egg_mode api,但不确定。
let (timeline, feed) = timeline.start().await?;
loop {
for tweet in feed.iter() {
let (tfound, mfound) = check_tweet(tweet).await?;
tweets_checked += 1;
// Return if both are found.
if tweet_found && media_found {
let id = tweet.id as i64;
return Ok((tweet_found, media_found, id, tweets_checked));
}
}
let (timeline, feed) = &timeline.older(None).await?;
}
这给了我以下错误:
error[E0382]: use of moved value: `timeline`
--> src/check_twitter/main.rs:145:33
|
125 | let (timeline, feed) = timeline.start().await?;
| -------- move occurs because `timeline` has type `egg_mode::tweet::Timeline`, which does not implement the `Copy` trait
...
145 | let (timeline, feed) = &timeline.older(None).await?;
| ^^^^^^^^ ----------- `timeline` moved due to this method call, in previous iteration of loop
|
note: this function takes ownership of the receiver `self`, which moves `timeline`
--> /home/utx0/.cargo/git/checkouts/egg-mode-01a8f29f644cee57/6b81073/src/tweet/mod.rs:520:18
|
520 | pub fn older(self, since_id: Option<u64>) -> TimelineFuture {
| ^^^^
解决方案
我修好了它。工作解决方案是:
let (mut timeline, mut feed) = timeline.start().await?;
loop {
let mut id: u64 = 0;
for tweet in feed.iter() {
let (tfound, mfound) = check_tweet(tweet).await?;
tweets_checked += 1;
id = tweet.id;
if tfound == true {
tweet_found = tfound;
tweet_id = tweet.id as i64;
}
if mfound == true {
media_found = mfound;
}
// Return if both are found.
if tweet_found && media_found {
let id = tweet.id as i64;
return Ok((tweet_found, media_found, id, tweets_checked));
}
}
let (ntimeline, nfeed) = timeline.older(Some(id)).await?;
timeline = ntimeline;
feed = nfeed;
}
推荐阅读
- dart - 自定义 Flutter TextField 文本选择按钮
- java - 如何将 Java 变量传递给 HTML 标签?
- php -
- Foreach 循环显示所有内容
- Foreach 循环显示所有内容
- javascript - 在 Node JS 中将括号 (][) 替换为 ','
- flash - 在 adobe animate CC 中无法获得帧准确的时间码
- javascript - Create-React-App Chrome 扩展 - 有第二个 HTML 和 JS 文件吗?
- c - 查找元音的程序,如果语句没有分配正确的值
- android - 构建 Android APK 文件时出现外部库错误
- java - 当 minifyEnabled 为 true 时,Android 应用程序崩溃
- three.js - 如何通过制服将鼠标位置从 JS 传递到着色器?