I'm using the twitter_stream
crate to pull data from Twitter. The API supports filtering the data by some parameter; in my case I am trying to filter using a bounding box location. The library takes an Option<((f64, f64), (f64, f64))>
, so I create a tuple in that form:
let bounds = ((0.59 as f64, 0.59 as f64), (0.59 as f64, 0.59 as f64));
When I do Some(bounds)
to wrap this in an Option
, I appear to end up with the type Option<&[((f64, f64), (f64, f64))]>
This adds a &[]
around my tuple, and I don't understand what that means or why it's there. My best guess is it means that there's now a borrowed array with one element around the tuple, but I don't understand why there would be an array, and I tried adding .to_owned()
everywhere and it didn't change a thing, so I feel like I am way off base.
Code:
extern crate twitter_stream;
use twitter_stream::rt::{self, Future, Stream};
use twitter_stream::{Token, TwitterStreamBuilder};
fn main() {
let bounds = ((0.59 as f64, 0.59 as f64), (0.59 as f64, 0.59 as f64));
let future = TwitterStreamBuilder::filter(Token::new(
"consumer_key",
"consumer_secret",
"access_token",
"access_secret",
))
.locations(Some(bounds))
.listen()
.unwrap()
.flatten_stream()
.for_each(|json| {
println!("{}", json);
Ok(())
})
.map_err(|e| println!("error: {}", e));
rt::run(future);
}
Error:
error[E0277]: the trait bound `std::option::Option<&[((f64, f64), (f64, f64))]>: std::convert::From<std::option::Option<((f64, f64), (f64, f64))>>` is not satisfied
--> src/main.rs:9:14
|
9 | .locations(Some(bounds))
| ^^^^^^^^^ the trait `std::convert::From<std::option::Option<((f64, f64), (f64, f64))>>` is not implemented for `std::option::Option<&[((f64, f64), (f64, f64))]>`
|
= help: the following implementations were found:
<std::option::Option<&'a T> as std::convert::From<&'a std::option::Option<T>>>
<std::option::Option<&'a mut T> as std::convert::From<&'a mut std::option::Option<T>>>
<std::option::Option<T> as std::convert::From<T>>
= note: required because of the requirements on the impl of `std::convert::Into<std::option::Option<&[((f64, f64), (f64, f64))]>>` for `std::option::Option<((f64, f64), (f64, f64))>`