generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async for I/O calls #372
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b51265
Decorate exact functions w/ async, disregard transitive effect
KendallWeihe dd8fd3c
Make all async inside web5 and web5_cli
KendallWeihe 590a492
Add async to uniffi crates
KendallWeihe 9791283
Add async to http-std
KendallWeihe fe565b4
Make all tests pass
KendallWeihe 6e71fb8
Use futures block_on at uniffi layer
KendallWeihe 79989c1
Add serde serialization to http types
KendallWeihe 0e6bcda
Fix linting
KendallWeihe fbad4fa
Fix kt tests
KendallWeihe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
6 changes: 4 additions & 2 deletions
6
bindings/web5_uniffi_wrapper/src/dids/resolution/resolution_result.rs
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,5 +1,15 @@ | ||
use errors::Result; | ||
use tokio::runtime::Runtime; | ||
use web5::errors::Web5Error; | ||
|
||
pub mod credentials; | ||
pub mod crypto; | ||
pub mod dids; | ||
|
||
pub mod errors; | ||
|
||
pub fn get_rt() -> Result<Runtime> { | ||
let rt = Runtime::new() | ||
.map_err(|e| Web5Error::Unknown(format!("unable to instantiate tokio runtime {}", e)))?; | ||
Ok(rt) | ||
} |
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
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,35 +1,54 @@ | ||
use crate::Result; | ||
use std::collections::HashMap; | ||
use crate::{Error, Result}; | ||
use async_trait::async_trait; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{collections::HashMap, fmt, str::FromStr}; | ||
|
||
#[async_trait] | ||
pub trait Client: Send + Sync { | ||
fn fetch(&self, url: &str, options: Option<FetchOptions>) -> Result<Response>; | ||
async fn fetch(&self, url: &str, options: Option<FetchOptions>) -> Result<Response>; | ||
} | ||
|
||
#[derive(Default)] | ||
#[derive(Default, Serialize, Deserialize)] | ||
pub struct FetchOptions { | ||
pub method: Option<Method>, | ||
pub headers: Option<HashMap<String, String>>, | ||
pub body: Option<Vec<u8>>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Response { | ||
pub status_code: u16, | ||
pub headers: HashMap<String, String>, | ||
pub body: Vec<u8>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub enum Method { | ||
Get, | ||
Post, | ||
Put, | ||
} | ||
|
||
impl ToString for Method { | ||
fn to_string(&self) -> String { | ||
match self { | ||
Method::Get => "GET".to_string(), | ||
Method::Post => "POST".to_string(), | ||
Method::Put => "PUT".to_string(), | ||
impl fmt::Display for Method { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let method_str = match self { | ||
Method::Get => "GET", | ||
Method::Post => "POST", | ||
Method::Put => "PUT", | ||
}; | ||
write!(f, "{}", method_str) | ||
} | ||
} | ||
|
||
impl FromStr for Method { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self> { | ||
match s.to_ascii_uppercase().as_ref() { | ||
"GET" => Ok(Method::Get), | ||
"POST" => Ok(Method::Post), | ||
"PUT" => Ok(Method::Put), | ||
_ => Err(Error::Parameter(format!("unknown method {}", s))), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean to change the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I learned that implementing
Display
is slightly preferable to implementingToString
because implementingDisplay
also implementsToString
plus you getformat!()
support