types
This commit is contained in:
parent
e7e9321080
commit
c118fc7d0a
@ -1,4 +1,5 @@
|
||||
use crate::util::{serialize_u64,deserialize_u64,response_ok,ResponseError,MaybeGzippedBytes};
|
||||
use crate::util::{serialize_u64,deserialize_u64,response_ok};
|
||||
use crate::types::{ResponseError,MaybeGzippedBytes};
|
||||
|
||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::util::{response_ok,ResponseError,MaybeGzippedBytes};
|
||||
use crate::util::response_ok;
|
||||
use crate::types::{ResponseError,MaybeGzippedBytes};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PostError{
|
||||
|
@ -1,3 +1,4 @@
|
||||
pub mod cloud;
|
||||
pub mod cookie;
|
||||
mod util;
|
||||
pub mod types;
|
||||
|
18
rbx_asset/src/types.rs
Normal file
18
rbx_asset/src/types.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct StatusCodeWithUrlAndBody{
|
||||
pub status_code:reqwest::StatusCode,
|
||||
pub url:url::Url,
|
||||
pub body:String,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum ResponseError{
|
||||
Reqwest(reqwest::Error),
|
||||
StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody),
|
||||
}
|
||||
impl std::fmt::Display for ResponseError{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ResponseError{}
|
@ -1,21 +1,5 @@
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct StatusCodeWithUrlAndBody{
|
||||
pub status_code:reqwest::StatusCode,
|
||||
pub url:url::Url,
|
||||
pub body:String,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum ResponseError{
|
||||
Reqwest(reqwest::Error),
|
||||
StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody),
|
||||
}
|
||||
impl std::fmt::Display for ResponseError{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ResponseError{}
|
||||
use crate::types::{ResponseError,StatusCodeWithUrlAndBody};
|
||||
|
||||
// lazy function to draw out meaningful info from http response on failure
|
||||
pub(crate) async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,ResponseError>{
|
||||
let status_code=response.status();
|
||||
@ -97,10 +81,10 @@ impl serde::de::Visitor<'_> for U64StringVisitor{
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_u64<'de,D:Deserializer<'de>>(deserializer:D)->Result<u64,D::Error>{
|
||||
pub(crate) fn deserialize_u64<'de,D:Deserializer<'de>>(deserializer:D)->Result<u64,D::Error>{
|
||||
deserializer.deserialize_any(U64StringVisitor)
|
||||
}
|
||||
|
||||
pub fn serialize_u64<S:Serializer>(v:&u64,serializer:S)->Result<S::Ok,S::Error>{
|
||||
pub(crate) fn serialize_u64<S:Serializer>(v:&u64,serializer:S)->Result<S::Ok,S::Error>{
|
||||
serializer.serialize_str(v.to_string().as_str())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user