pub struct RequestHandler { /* private fields */ }Implementations§
Source§impl 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 Freeze for RequestHandler
impl !RefUnwindSafe for RequestHandler
impl Send for RequestHandler
impl Sync for RequestHandler
impl Unpin for RequestHandler
impl !UnwindSafe for RequestHandler
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