Struct scryfall::uri::Uri

source ·
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>

source

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>>

source

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
);
source

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<T: Clone> Clone for Uri<T>

source§

fn clone(&self) -> Uri<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Uri<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, T> Deserialize<'de> for Uri<T>

source§

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> From<Url> for Uri<T>

source§

fn from(url: Url) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for Uri<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: PartialEq> PartialEq for Uri<T>

source§

fn eq(&self, other: &Uri<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for Uri<T>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> TryFrom<&str> for Uri<T>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(url: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: Eq> Eq for Uri<T>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,