From c118fc7d0a38e4d02b905a2c29b674ed36ed0edd Mon Sep 17 00:00:00 2001 From: Quaternions <krakow20@gmail.com> Date: Thu, 10 Apr 2025 16:57:13 -0700 Subject: [PATCH] types --- rbx_asset/src/cloud.rs | 3 ++- rbx_asset/src/cookie.rs | 3 ++- rbx_asset/src/lib.rs | 1 + rbx_asset/src/types.rs | 18 ++++++++++++++++++ rbx_asset/src/util.rs | 24 ++++-------------------- 5 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 rbx_asset/src/types.rs diff --git a/rbx_asset/src/cloud.rs b/rbx_asset/src/cloud.rs index 18e985b..71f4a9e 100644 --- a/rbx_asset/src/cloud.rs +++ b/rbx_asset/src/cloud.rs @@ -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)] diff --git a/rbx_asset/src/cookie.rs b/rbx_asset/src/cookie.rs index cbc56d3..efee3dc 100644 --- a/rbx_asset/src/cookie.rs +++ b/rbx_asset/src/cookie.rs @@ -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{ diff --git a/rbx_asset/src/lib.rs b/rbx_asset/src/lib.rs index 6cd6619..f033e93 100644 --- a/rbx_asset/src/lib.rs +++ b/rbx_asset/src/lib.rs @@ -1,3 +1,4 @@ pub mod cloud; pub mod cookie; mod util; +pub mod types; diff --git a/rbx_asset/src/types.rs b/rbx_asset/src/types.rs new file mode 100644 index 0000000..b9ef790 --- /dev/null +++ b/rbx_asset/src/types.rs @@ -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{} diff --git a/rbx_asset/src/util.rs b/rbx_asset/src/util.rs index 3c37784..6b2b23e 100644 --- a/rbx_asset/src/util.rs +++ b/rbx_asset/src/util.rs @@ -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()) }