Skip to content

Commit

Permalink
reintroduce a few Cows
Browse files Browse the repository at this point in the history
  • Loading branch information
adwhit committed Mar 14, 2020
1 parent c2b556f commit 1366186
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn main() {
users.push(config.user_id.into());
users.push("SwiftOnSecurity".into());

for user in user::lookup(&users, &config.token)
for user in user::lookup(users, &config.token)
.await
.unwrap()
.response
Expand Down
2 changes: 1 addition & 1 deletion examples/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() {
let convos = convos.newest().await.unwrap();

for (id, convo) in &convos.conversations {
let user = egg_mode::user::show(id, &c.token).await.unwrap();
let user = egg_mode::user::show(*id, &c.token).await.unwrap();
println!("-----");
println!("Conversation with @{}:", user.screen_name);
for msg in convo {
Expand Down
2 changes: 1 addition & 1 deletion examples/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() {

println!("Lists curated by user @Scobleizer:");
let lists = list::list("Scobleizer", true, &config.token).await.unwrap();
for list in lists {
for list in lists.iter() {
if list.user.screen_name == "Scobleizer" {
println!(" {} ({})", list.name, list.slug);
}
Expand Down
15 changes: 8 additions & 7 deletions examples/reciprocal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ async fn main() {

println!("");
let mut friends = HashSet::new();
user::friends_ids(config.user_id, &config.token)
let mut friends: HashSet<u64> = user::friends_ids(config.user_id, &config.token)
.map(|r| r.unwrap().response)
.for_each(|id| {
friends.insert(id);
future::ready(())
})
.await;
.await
.collect();

let mut followers = HashSet::new();
user::followers_ids(config.user_id, &config.token)
Expand All @@ -46,7 +43,11 @@ async fn main() {
);

if reciprocals_ct > 0 {
for user in user::lookup(&reciprocals, &config.token).await.unwrap() {
for user in user::lookup(reciprocals, &config.token)
.await
.unwrap()
.iter()
{
println!("{} (@{})", user.name, user.screen_name);
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/tweets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn main() {
println!("Loading the user's home timeline:");
let home = egg_mode::tweet::home_timeline(&config.token).with_page_size(5);
let (_home, feed) = home.start().await.unwrap();
for status in feed {
for status in feed.iter() {
common::print_tweet(&status);
println!("");
}
Expand All @@ -40,7 +40,7 @@ async fn main() {
println!("Loading the user's mentions timeline:");
let mentions = egg_mode::tweet::mentions_timeline(&config.token).with_page_size(5);
let (_mentions, feed) = mentions.start().await.unwrap();
for status in feed {
for status in feed.iter() {
common::print_tweet(&status);
println!("");
}
Expand All @@ -50,7 +50,7 @@ async fn main() {
let user =
egg_mode::tweet::user_timeline(config.user_id, true, true, &config.token).with_page_size(5);
let (_user, feed) = user.start().await.unwrap();
for status in feed {
for status in feed.iter() {
common::print_tweet(&status);
println!("");
}
Expand Down
21 changes: 5 additions & 16 deletions src/common/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use serde_json;

use std::convert::TryFrom;
use std::future::Future;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{io, mem};
Expand Down Expand Up @@ -63,11 +62,15 @@ fn rate_limit_reset(headers: &Headers) -> Result<Option<i32>> {
///
///As this implements `Deref` and `DerefMut`, you can transparently use the contained `response`'s
///methods as if they were methods on this struct.
#[derive(Debug, Deserialize, derive_more::Constructor)]
#[derive(
Debug, Deserialize, derive_more::Constructor, derive_more::Deref, derive_more::DerefMut,
)]
pub struct Response<T> {
/// Latest rate lime status
pub rate_limit_status: RateLimit,
///The decoded response from the request.
#[deref]
#[deref_mut]
pub response: T,
}

Expand Down Expand Up @@ -97,20 +100,6 @@ impl<T> Response<T> {
}
}

impl<T> Deref for Response<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.response
}
}

impl<T> DerefMut for Response<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.response
}
}

pub fn get_response(request: Request<Body>) -> ResponseFuture {
// TODO: num-cpus?
let connector = HttpsConnector::new();
Expand Down
2 changes: 1 addition & 1 deletion src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ where
///implementation. It is made available for those who wish to manually manage network calls and
///pagination.
pub next_cursor: i64,
loader: Option<Pin<Box<dyn Future<Output = Result<Response<T>>>>>>,
loader: Option<FutureResponse<T>>,
iter: Option<VecIter<T::Item>>,
}

Expand Down
4 changes: 2 additions & 2 deletions src/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub enum ListID {

impl ListID {
///Make a new `ListID` by supplying its owner and name.
pub fn from_slug<T: Into<user::UserID>>(owner: T, list_name: CowStr) -> ListID {
ListID::Slug(owner.into(), list_name)
pub fn from_slug<T: Into<user::UserID>>(owner: T, list_name: impl Into<CowStr>) -> ListID {
ListID::Slug(owner.into(), list_name.into())
}

///Make a new `ListID` by supplying its numeric ID.
Expand Down
1 change: 0 additions & 1 deletion src/media/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ impl MediaHandle {
/// Returns whether media is still valid to be used in API calls.
///
/// Under hood it is `Instant::now() < handle.valid_until`.
#[inline]
pub fn is_valid(&self) -> bool {
Instant::now() < self.valid_until
}
Expand Down
8 changes: 4 additions & 4 deletions src/place/fun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ pub fn search_point(latitude: f64, longitude: f64) -> SearchBuilder {
/// assert!(result.results.iter().any(|pl| pl.full_name == "British Columbia, Canada"));
/// # }
/// ```
pub fn search_query(query: String) -> SearchBuilder {
SearchBuilder::new(PlaceQuery::Query(query))
pub fn search_query(query: impl Into<CowStr>) -> SearchBuilder {
SearchBuilder::new(PlaceQuery::Query(query.into()))
}

///Begins building a location search via an IP address.
pub fn search_ip(query: String) -> SearchBuilder {
SearchBuilder::new(PlaceQuery::IPAddress(query))
pub fn search_ip(query: impl Into<CowStr>) -> SearchBuilder {
SearchBuilder::new(PlaceQuery::IPAddress(query.into()))
}

///From a URL given with the result of any `search_*` function, perform the same location search.
Expand Down
4 changes: 2 additions & 2 deletions src/place/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ impl GeocodeBuilder {

enum PlaceQuery {
LatLon(f64, f64),
Query(String),
IPAddress(String),
Query(CowStr),
IPAddress(CowStr),
}

///Represents a location search query before it is sent.
Expand Down
2 changes: 1 addition & 1 deletion src/tweet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ impl Timeline {
#[must_use = "futures do nothing unless polled"]
pub struct TimelineFuture {
timeline: Option<Timeline>,
loader: Pin<Box<dyn Future<Output = Result<Response<Vec<Tweet>>>>>>,
loader: FutureResponse<Vec<Tweet>>,
}

impl Future for TimelineFuture {
Expand Down
3 changes: 1 addition & 2 deletions src/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ pub struct UserSearch {
pub page_num: i32,
/// The number of user records per page of results. Defaults to 10, maximum of 20.
pub page_size: i32,
current_loader:
Option<Pin<Box<dyn Future<Output = error::Result<Response<Vec<TwitterUser>>>>>>>,
current_loader: Option<FutureResponse<Vec<TwitterUser>>>,
current_results: Option<VecIter<TwitterUser>>,
}

Expand Down

0 comments on commit 1366186

Please sign in to comment.