diff --git a/Cargo.toml b/Cargo.toml index 195f60d..66d764b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["bevy", "http", "plugin", "wasm"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.14.0-rc.3", default-features = false, features = ["multi_threaded"] } +bevy = { version = "0.14.0", default-features = false, features = ["multi_threaded"] } crossbeam-channel = "0.5.11" ehttp = { version = "0.5.0", features = ["native-async", "json"] } serde = { version = "1.0", features = ["derive"] } diff --git a/examples/ipinfo.rs b/examples/ipinfo.rs index 22ea383..4a6bbd1 100644 --- a/examples/ipinfo.rs +++ b/examples/ipinfo.rs @@ -1,4 +1,5 @@ use bevy::{prelude::*, time::common_conditions::on_timer}; + use bevy_http_client::prelude::*; fn main() { diff --git a/src/lib.rs b/src/lib.rs index dac16ac..7bf46e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,10 @@ #![doc = include_str!("../README.md")] -use bevy::ecs::world::CommandQueue; -use bevy::prelude::*; -use bevy::tasks::IoTaskPool; +use bevy::{ecs::world::CommandQueue, prelude::*, tasks::IoTaskPool}; use crossbeam_channel::Receiver; +use ehttp::{Headers, Request, Response}; use crate::prelude::TypedRequest; -use ehttp::{Headers, Request, Response}; pub mod prelude; mod typed; @@ -133,7 +131,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP request will be sent. + /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP + /// request will be sent. /// /// # Returns /// @@ -154,7 +153,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP request will be sent. + /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP + /// request will be sent. /// /// # Returns /// @@ -175,7 +175,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP request will be sent. + /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP + /// request will be sent. /// /// # Returns /// @@ -196,7 +197,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP request will be sent. + /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP + /// request will be sent. /// /// # Returns /// @@ -217,7 +219,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP request will be sent. + /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP + /// request will be sent. /// /// # Returns /// @@ -238,7 +241,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP request will be sent. + /// * `url` - A value that can be converted into a string. This is the URL to which the HTTP + /// request will be sent. /// /// # Returns /// @@ -259,7 +263,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `headers` - A slice of tuples where each tuple represents a header. The first element of the tuple is the header name and the second element is the header value. + /// * `headers` - A slice of tuples where each tuple represents a header. The first element of + /// the tuple is the header name and the second element is the header value. /// /// # Returns /// @@ -281,7 +286,8 @@ impl HttpClient { /// /// # Arguments /// - /// * `body` - A reference to any type that implements the `serde::Serialize` trait. This is the data that will be serialized to JSON and set as the body of the HTTP request. + /// * `body` - A reference to any type that implements the `serde::Serialize` trait. This is the + /// data that will be serialized to JSON and set as the body of the HTTP request. /// /// # Returns /// @@ -311,12 +317,14 @@ impl HttpClient { self } - /// This method is used to set the properties of the `HttpClient` instance using an `Request` instance. - /// This version of the method is used when the target architecture is not `wasm32`. + /// This method is used to set the properties of the `HttpClient` instance using an `Request` + /// instance. This version of the method is used when the target architecture is not + /// `wasm32`. /// /// # Arguments /// - /// * `request` - An instance of `Request` which includes the HTTP method, URL, body, and headers. + /// * `request` - An instance of `Request` which includes the HTTP method, URL, body, and + /// headers. /// /// # Returns /// @@ -345,7 +353,8 @@ impl HttpClient { /// Associates an `Entity` with the `HttpClient`. /// - /// This method is used to associate an `Entity` with the `HttpClient`. This can be useful when you want to track which entity initiated the HTTP request. + /// This method is used to associate an `Entity` with the `HttpClient`. This can be useful when + /// you want to track which entity initiated the HTTP request. /// /// # Parameters /// @@ -366,12 +375,13 @@ impl HttpClient { self } - /// This method is used to set the properties of the `HttpClient` instance using an `Request` instance. - /// This version of the method is used when the target architecture is `wasm32`. + /// This method is used to set the properties of the `HttpClient` instance using an `Request` + /// instance. This version of the method is used when the target architecture is `wasm32`. /// /// # Arguments /// - /// * `request` - An instance of `Request` which includes the HTTP method, URL, body, headers, and mode. + /// * `request` - An instance of `Request` which includes the HTTP method, URL, body, headers, + /// and mode. /// /// # Returns /// @@ -402,15 +412,19 @@ impl HttpClient { /// Builds an `HttpRequest` from the `HttpClient` instance. /// - /// This method is used to construct an `HttpRequest` from the current state of the `HttpClient` instance. The resulting `HttpRequest` includes the HTTP method, URL, body, headers, and mode (only available on wasm builds). + /// This method is used to construct an `HttpRequest` from the current state of the `HttpClient` + /// instance. The resulting `HttpRequest` includes the HTTP method, URL, body, headers, and mode + /// (only available on wasm builds). /// /// # Returns /// - /// An `HttpRequest` instance which includes the HTTP method, URL, body, headers, and mode (only available on wasm builds). + /// An `HttpRequest` instance which includes the HTTP method, URL, body, headers, and mode (only + /// available on wasm builds). /// /// # Panics /// - /// This method will panic if the HTTP method, URL, or headers are not set in the `HttpClient` instance. + /// This method will panic if the HTTP method, URL, or headers are not set in the `HttpClient` + /// instance. /// /// # Examples /// @@ -423,7 +437,8 @@ impl HttpClient { /// /// # Note /// - /// This method consumes the `HttpClient` instance, meaning it can only be called once per instance. + /// This method consumes the `HttpClient` instance, meaning it can only be called once per + /// instance. pub fn build(self) -> HttpRequest { HttpRequest { from_entity: self.from_entity, diff --git a/src/prelude.rs b/src/prelude.rs index ece5707..b25af28 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,5 +1,5 @@ -pub use super::typed::{HttpTypedRequestTrait, TypedRequest, TypedResponse, TypedResponseError}; pub use super::{ + typed::{HttpTypedRequestTrait, TypedRequest, TypedResponse, TypedResponseError}, HttpClient, HttpClientPlugin, HttpClientSetting, HttpRequest, HttpResponse, HttpResponseError, RequestTask, }; diff --git a/src/typed.rs b/src/typed.rs index 8382e73..60ef6b7 100644 --- a/src/typed.rs +++ b/src/typed.rs @@ -1,10 +1,12 @@ use std::marker::PhantomData; -use bevy::app::{App, PreUpdate}; -use bevy::ecs::world::CommandQueue; -use bevy::hierarchy::DespawnRecursiveExt; -use bevy::prelude::{Commands, Deref, Entity, Event, EventReader, Events, ResMut, World}; -use bevy::tasks::IoTaskPool; +use bevy::{ + app::{App, PreUpdate}, + ecs::world::CommandQueue, + hierarchy::DespawnRecursiveExt, + prelude::{Commands, Deref, Entity, Event, EventReader, Events, ResMut, World}, + tasks::IoTaskPool, +}; use ehttp::{Request, Response}; use serde::Deserialize; @@ -13,7 +15,10 @@ use crate::{HttpClientSetting, RequestTask}; pub trait HttpTypedRequestTrait { /// Registers a new request type `T` to the application. /// - /// This method is used to register a new request type `T` to the application. The request type `T` must implement the `Deserialize` trait, and be `Send` and `Sync`. This is necessary for the request type to be safely shared across threads and for it to be deserialized from a HTTP response. + /// This method is used to register a new request type `T` to the application. The request type + /// `T` must implement the `Deserialize` trait, and be `Send` and `Sync`. This is necessary for + /// the request type to be safely shared across threads and for it to be deserialized from a + /// HTTP response. /// /// # Type Parameters /// @@ -47,11 +52,14 @@ impl HttpTypedRequestTrait for App { /// A struct that represents a typed HTTP request. /// -/// This struct is used to represent a typed HTTP request. The type `T` is the type of the data that is expected to be returned by the HTTP request. The `Request` is the actual HTTP request that will be sent. +/// This struct is used to represent a typed HTTP request. The type `T` is the type of the data that +/// is expected to be returned by the HTTP request. The `Request` is the actual HTTP request that +/// will be sent. /// /// # Type Parameters /// -/// * `T`: The type of the data that is expected to be returned by the HTTP request. This type must implement `Deserialize`. +/// * `T`: The type of the data that is expected to be returned by the HTTP request. This type must +/// implement `Deserialize`. /// /// # Fields /// @@ -86,11 +94,14 @@ impl serde::Deserialize<'a>> TypedRequest { /// A struct that represents a typed HTTP response. /// -/// This struct is used to represent a typed HTTP response. The type `T` is the type of the data that is expected to be contained in the HTTP response. The `inner` field is the actual data contained in the HTTP response. +/// This struct is used to represent a typed HTTP response. The type `T` is the type of the data +/// that is expected to be contained in the HTTP response. The `inner` field is the actual data +/// contained in the HTTP response. /// /// # Type Parameters /// -/// * `T`: The type of the data that is expected to be contained in the HTTP response. This type must implement `Deserialize`. +/// * `T`: The type of the data that is expected to be contained in the HTTP response. This type +/// must implement `Deserialize`. /// /// # Fields ///