Struct hypixel_api::RequestHandler
source · [−]pub struct RequestHandler { /* private fields */ }Implementations
sourceimpl RequestHandler
impl RequestHandler
sourcepub fn new(api_key: Uuid) -> Self
pub fn new(api_key: Uuid) -> Self
Creates a new RequestHandler instance using an api_key obtained from Hypixel.
RequestHandler::request can be used to queue as many
requests as required for execution without ever going over
the limit set by Hypixel’s API. This limit is derived
automatically and thus can be completely avoided by user code.
Examples
use hypixel_api::RequestHandler;
let api_key = Uuid::from_str(env!("HYPIXEL_API_KEY")).unwrap();
let request_handler = RequestHandler::new(api_key);
// Send requests ...sourcepub fn request<T: DeserializeOwned + Send + 'static>(
&self,
path: &str,
authenticated: bool
) -> JoinHandle<Result<T, HypixelApiError>>
pub fn request<T: DeserializeOwned + Send + 'static>(
&self,
path: &str,
authenticated: bool
) -> JoinHandle<Result<T, HypixelApiError>>
Queues a new request for execution and returns a JoinHandle to it.
Arguments
path should be a relative path to the API (without leading /), such as "key"
or "status?uuid=...". See the API.
If authenticated is true then the API key will be sent along as a header.
Errors
If any part of the execution process fails, a HypixelApiError will be returned.
Examples
use hypixel_api::RequestHandler;
let api_key = Uuid::from_str(env!("HYPIXEL_API_KEY")).unwrap();
let request_handler = RequestHandler::new(api_key);
let request1 = request_handler.request::<StatusReply>("status?uuid=069a79f4-44e9-4726-a5be-fca90e38aaf5", true);
// send more requests ...
let reply: StatusReply = request1.await.unwrap().unwrap();
// use reply ...Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for RequestHandler
impl Send for RequestHandler
impl Sync for RequestHandler
impl Unpin for RequestHandler
impl !UnwindSafe for RequestHandler
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more