-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(wasm): move wasm_bindgen support to js folder
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com> refactor(wasm): add wasm mod Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
- Loading branch information
1 parent
646b1f8
commit 5184c74
Showing
7 changed files
with
63 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use wasm_bindgen::JsCast; | ||
use web_sys::{AbortController, AbortSignal}; | ||
|
||
mod body; | ||
mod client; | ||
/// TODO | ||
#[cfg(feature = "multipart")] | ||
pub mod multipart; | ||
mod request; | ||
mod response; | ||
|
||
pub use self::body::Body; | ||
pub use self::client::{Client, ClientBuilder}; | ||
pub use self::request::{Request, RequestBuilder}; | ||
pub use self::response::Response; | ||
|
||
async fn promise<T>(promise: js_sys::Promise) -> Result<T, crate::error::BoxError> | ||
where | ||
T: JsCast, | ||
{ | ||
use wasm_bindgen_futures::JsFuture; | ||
|
||
let js_val = JsFuture::from(promise).await.map_err(crate::error::wasm)?; | ||
|
||
js_val | ||
.dyn_into::<T>() | ||
.map_err(|_js_val| "promise resolved to unexpected type".into()) | ||
} | ||
|
||
/// A guard that cancels a fetch request when dropped. | ||
struct AbortGuard { | ||
ctrl: AbortController, | ||
} | ||
|
||
impl AbortGuard { | ||
fn new() -> crate::Result<Self> { | ||
Ok(AbortGuard { | ||
ctrl: AbortController::new() | ||
.map_err(crate::error::wasm) | ||
.map_err(crate::error::builder)?, | ||
}) | ||
} | ||
|
||
fn signal(&self) -> AbortSignal { | ||
self.ctrl.signal() | ||
} | ||
} | ||
|
||
impl Drop for AbortGuard { | ||
fn drop(&mut self) { | ||
self.ctrl.abort(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,2 @@ | ||
use wasm_bindgen::JsCast; | ||
use web_sys::{AbortController, AbortSignal}; | ||
|
||
mod body; | ||
mod client; | ||
/// TODO | ||
#[cfg(feature = "multipart")] | ||
pub mod multipart; | ||
mod request; | ||
mod response; | ||
|
||
pub use self::body::Body; | ||
pub use self::client::{Client, ClientBuilder}; | ||
pub use self::request::{Request, RequestBuilder}; | ||
pub use self::response::Response; | ||
|
||
async fn promise<T>(promise: js_sys::Promise) -> Result<T, crate::error::BoxError> | ||
where | ||
T: JsCast, | ||
{ | ||
use wasm_bindgen_futures::JsFuture; | ||
|
||
let js_val = JsFuture::from(promise).await.map_err(crate::error::wasm)?; | ||
|
||
js_val | ||
.dyn_into::<T>() | ||
.map_err(|_js_val| "promise resolved to unexpected type".into()) | ||
} | ||
|
||
/// A guard that cancels a fetch request when dropped. | ||
struct AbortGuard { | ||
ctrl: AbortController, | ||
} | ||
|
||
impl AbortGuard { | ||
fn new() -> crate::Result<Self> { | ||
Ok(AbortGuard { | ||
ctrl: AbortController::new() | ||
.map_err(crate::error::wasm) | ||
.map_err(crate::error::builder)?, | ||
}) | ||
} | ||
|
||
fn signal(&self) -> AbortSignal { | ||
self.ctrl.signal() | ||
} | ||
} | ||
|
||
impl Drop for AbortGuard { | ||
fn drop(&mut self) { | ||
self.ctrl.abort(); | ||
} | ||
} | ||
pub mod js; | ||
pub use js::*; |