Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
emreyalvac committed Dec 22, 2021
1 parent 0216f7a commit 11182ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
37 changes: 16 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use reqwest::{StatusCode};
use reqwest::StatusCode;
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde_json::Value;
use std::fmt::Debug;
use url::Url;

use constants::{Method, Response, AUTH};
use errors::{RequestError, UrlParseError, UrlParseResult};
use errors::{RequestError, RequestResult, UrlParseError, UrlParseResult};
use params::Params;
use utils::check_uri;
use crate::errors::RequestResult;

mod constants;
mod errors;
Expand All @@ -27,8 +26,8 @@ impl Firebase {
// let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
/// ```
pub fn new(uri: &str) -> UrlParseResult<Self>
where
Self: Sized,
where
Self: Sized,
{
match check_uri(&uri) {
Ok(uri) => Ok(Self { uri }),
Expand All @@ -41,8 +40,8 @@ impl Firebase {
// let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap();
/// ```
pub fn auth(uri: &str, auth_key: &str) -> UrlParseResult<Self>
where
Self: Sized,
where
Self: Sized,
{
match check_uri(&uri) {
Ok(mut uri) => {
Expand Down Expand Up @@ -101,11 +100,7 @@ impl Firebase {
self.uri.to_string()
}

async fn request(
&self,
method: Method,
data: Option<Value>,
) -> RequestResult<Response> {
async fn request(&self, method: Method, data: Option<Value>) -> RequestResult<Response> {
let client = reqwest::Client::new();

return match method {
Expand Down Expand Up @@ -171,8 +166,8 @@ impl Firebase {
}

async fn request_generic<T>(&self, method: Method) -> RequestResult<T>
where
T: Serialize + DeserializeOwned + Debug,
where
T: Serialize + DeserializeOwned + Debug,
{
let request = self.request(method, None).await;

Expand All @@ -198,8 +193,8 @@ impl Firebase {
// let users = firebase.set(&user).await;
/// ```
pub async fn set<T>(&self, data: &T) -> RequestResult<Response>
where
T: Serialize + DeserializeOwned + Debug,
where
T: Serialize + DeserializeOwned + Debug,
{
let data = serde_json::to_value(&data).unwrap();
self.request(Method::POST, Some(data)).await
Expand Down Expand Up @@ -230,8 +225,8 @@ impl Firebase {
// let user = firebase.get_generic::<HashMap<String, User>>().await;
/// ```
pub async fn get<T>(&self) -> RequestResult<T>
where
T: Serialize + DeserializeOwned + Debug,
where
T: Serialize + DeserializeOwned + Debug,
{
self.request_generic::<T>(Method::GET).await
}
Expand All @@ -257,8 +252,8 @@ impl Firebase {
// let users = firebase.update(&user).await;
/// ```
pub async fn update<T>(&self, data: &T) -> RequestResult<Response>
where
T: DeserializeOwned + Serialize + Debug,
where
T: DeserializeOwned + Serialize + Debug,
{
let value = serde_json::to_value(&data).unwrap();
self.request(Method::PATCH, Some(value)).await
Expand Down Expand Up @@ -296,4 +291,4 @@ mod tests {
firebase.get_uri()
);
}
}
}
7 changes: 5 additions & 2 deletions src/params.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::constants::{
END_AT, EQUAL_TO, EXPORT, FORMAT, LIMIT_TO_FIRST, LIMIT_TO_LAST, ORDER_BY, SHALLOW, START_AT,
};
use crate::{Firebase};
use crate::Firebase;
use std::collections::HashMap;
use url::Url;

Expand All @@ -24,7 +24,10 @@ impl Params {
}
}

pub fn add_param<T>(&mut self, key: &str, value: T) -> &mut Self where T: ToString {
pub fn add_param<T>(&mut self, key: &str, value: T) -> &mut Self
where
T: ToString,
{
self.params.insert(key.to_string(), value.to_string());
self.set_params();

Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use url::Url;
use crate::errors::UrlParseResult;
use crate::UrlParseError;
use url::Url;

pub fn check_uri(uri: &str) -> UrlParseResult<Url> {
let uri = Url::parse(uri);
Expand Down

0 comments on commit 11182ed

Please sign in to comment.