pub struct Uri<T> { /* private fields */ }
Expand description
An unresolved URI returned by the Scryfall API, or generated by this crate.
The fetch
method handles requesting the resource from the API endpoint,
and deserializing it into a T
object. If the type parameter is
List
<_>
, then additional methods fetch_iter
and fetch_all
are available, giving access to objects from all pages
of the collection.
Implementations§
source§impl<T: DeserializeOwned> Uri<T>
impl<T: DeserializeOwned> Uri<T>
sourcepub async fn fetch(&self) -> Result<T>
pub async fn fetch(&self) -> Result<T>
Fetches a resource from the Scryfall API and deserializes it into a type
T
.
§Example
let uri =
Uri::<Card>::try_from("https://api.scryfall.com/cards/named?exact=Lightning+Bolt").unwrap();
let bolt = uri.fetch().await.unwrap();
assert_eq!(bolt.mana_cost, Some("{R}".to_string()));
source§impl<T: DeserializeOwned + Send + Sync + Unpin> Uri<List<T>>
impl<T: DeserializeOwned + Send + Sync + Unpin> Uri<List<T>>
sourcepub async fn fetch_iter(&self) -> Result<ListIter<T>>
pub async fn fetch_iter(&self) -> Result<ListIter<T>>
Lazily iterate over items from all pages of a list. Following pages are requested once the previous page has been exhausted.
§Example
use futures::stream::StreamExt;
use futures::future;
let uri = Uri::<List<Card>>::try_from("https://api.scryfall.com/cards/search?q=zurgo").unwrap();
assert!(
uri.fetch_iter()
.await
.unwrap()
.into_stream()
.map(Result::unwrap)
.filter(|c| future::ready(c.name.contains("Bellstriker")))
.collect::<Vec<_>>()
.await
.len()
> 0
);
use futures::stream::StreamExt;
use futures::future;
let uri = Uri::<List<Card>>::try_from("https://api.scryfall.com/cards/search?q=zurgo").unwrap();
assert!(
uri.fetch_iter()
.await
.unwrap()
.into_stream_buffered(10)
.map(Result::unwrap)
.filter(|c| future::ready(c.name.contains("Bellstriker")))
.collect::<Vec<_>>()
.await
.len()
> 0
);
sourcepub async fn fetch_all(&self) -> Result<Vec<T>>
pub async fn fetch_all(&self) -> Result<Vec<T>>
Eagerly fetch items from all pages of a list. If any of the pages fail to load, returns an error.
§Example
let uri =
Uri::<List<Card>>::try_from("https://api.scryfall.com/cards/search?q=e:ddu&unique=prints")
.unwrap();
assert_eq!(uri.fetch_all().await.unwrap().len(), 76);
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for Uri<T>
impl<'de, T> Deserialize<'de> for Uri<T>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: PartialEq> PartialEq for Uri<T>
impl<T: PartialEq> PartialEq for Uri<T>
impl<T: Eq> Eq for Uri<T>
impl<T> StructuralPartialEq for Uri<T>
Auto Trait Implementations§
impl<T> Freeze for Uri<T>
impl<T> RefUnwindSafe for Uri<T>
impl<T> Send for Uri<T>
impl<T> Sync for Uri<T>
impl<T> Unpin for Uri<T>
impl<T> UnwindSafe for Uri<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.