Skip to content

Commit

Permalink
use default rustfmt settings (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl authored Dec 22, 2024
1 parent a3e29d9 commit ed29f1b
Show file tree
Hide file tree
Showing 17 changed files with 661 additions and 1,138 deletions.
3 changes: 1 addition & 2 deletions cargo-progenitor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

fn main() {
let src = project_root::get_project_root().unwrap();
let dst = std::path::Path::new(&std::env::var("OUT_DIR").unwrap())
.join("built.rs");
let dst = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("built.rs");
built::write_built_file_with_opts(Some(&src), &dst)
.expect("Failed to acquire build-time information");
}
15 changes: 7 additions & 8 deletions cargo-progenitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ fn reformat_code(input: String) -> String {
wrap_comments: Some(true),
..Default::default()
};
space_out_items(rustfmt_wrapper::rustfmt_config(config, input).unwrap())
.unwrap()
space_out_items(rustfmt_wrapper::rustfmt_config(config, input).unwrap()).unwrap()
}

fn save<P>(p: P, data: &str) -> Result<()>
Expand Down Expand Up @@ -162,9 +161,7 @@ fn main() -> Result<()> {
name, version, &args.license_name,
);
if let Some(registry_name) = args.registry_name {
tomlout.extend(
format!("publish = [\"{}\"]\n", registry_name).chars(),
);
tomlout.extend(format!("publish = [\"{}\"]\n", registry_name).chars());
}
tomlout.extend(
format!(
Expand Down Expand Up @@ -272,8 +269,7 @@ pub fn dependencies(builder: Generator, include_client: bool) -> Vec<String> {
} else {
built_info::PKG_VERSION
};
let client_version_dep =
format!("progenitor-client = \"{}\"", crate_version);
let client_version_dep = format!("progenitor-client = \"{}\"", crate_version);
deps.push(client_version_dep);
}

Expand All @@ -287,7 +283,10 @@ pub fn dependencies(builder: Generator, include_client: bool) -> Vec<String> {
));
}
if type_space.uses_chrono() {
deps.push(format!("chrono = {{ version = \"{}\", default-features=false, features = [\"serde\"] }}", DEPENDENCIES.chrono));
deps.push(format!(
"chrono = {{ version = \"{}\", default-features=false, features = [\"serde\"] }}",
DEPENDENCIES.chrono
));
}
if builder.uses_futures() {
deps.push(format!("futures = \"{}\"", DEPENDENCIES.futures));
Expand Down
53 changes: 16 additions & 37 deletions progenitor-client/src/progenitor_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ use reqwest::RequestBuilder;
use serde::{de::DeserializeOwned, Serialize};

#[cfg(not(target_arch = "wasm32"))]
type InnerByteStream =
std::pin::Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send + Sync>>;
type InnerByteStream = std::pin::Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send + Sync>>;

#[cfg(target_arch = "wasm32")]
type InnerByteStream =
std::pin::Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>>>>;
type InnerByteStream = std::pin::Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>>>>;

/// Untyped byte stream used for both success and error responses.
pub struct ByteStream(InnerByteStream);
Expand Down Expand Up @@ -63,14 +61,12 @@ pub struct ResponseValue<T> {

impl<T: DeserializeOwned> ResponseValue<T> {
#[doc(hidden)]
pub async fn from_response<E>(
response: reqwest::Response,
) -> Result<Self, Error<E>> {
pub async fn from_response<E>(response: reqwest::Response) -> Result<Self, Error<E>> {
let status = response.status();
let headers = response.headers().clone();
let full = response.bytes().await.map_err(Error::ResponseBodyError)?;
let inner = serde_json::from_slice(&full)
.map_err(|e| Error::InvalidResponsePayload(full, e))?;
let inner =
serde_json::from_slice(&full).map_err(|e| Error::InvalidResponsePayload(full, e))?;

Ok(Self {
inner,
Expand All @@ -89,8 +85,7 @@ impl ResponseValue<reqwest::Upgraded> {
let status = response.status();
let headers = response.headers().clone();
if status == reqwest::StatusCode::SWITCHING_PROTOCOLS {
let inner =
response.upgrade().await.map_err(Error::InvalidUpgrade)?;
let inner = response.upgrade().await.map_err(Error::InvalidUpgrade)?;

Ok(Self {
inner,
Expand Down Expand Up @@ -135,11 +130,7 @@ impl<T> ResponseValue<T> {
/// Creates a [`ResponseValue`] from the inner type, status, and headers.
///
/// Useful for generating test fixtures.
pub fn new(
inner: T,
status: reqwest::StatusCode,
headers: reqwest::header::HeaderMap,
) -> Self {
pub fn new(inner: T, status: reqwest::StatusCode, headers: reqwest::header::HeaderMap) -> Self {
Self {
inner,
status,
Expand Down Expand Up @@ -174,10 +165,7 @@ impl<T> ResponseValue<T> {
}

#[doc(hidden)]
pub fn map<U: std::fmt::Debug, F, E>(
self,
f: F,
) -> Result<ResponseValue<U>, E>
pub fn map<U: std::fmt::Debug, F, E>(self, f: F) -> Result<ResponseValue<U>, E>
where
F: FnOnce(T) -> U,
{
Expand Down Expand Up @@ -300,9 +288,7 @@ impl<E> Error<E> {
}),
Error::InvalidUpgrade(e) => Error::InvalidUpgrade(e),
Error::ResponseBodyError(e) => Error::ResponseBodyError(e),
Error::InvalidResponsePayload(b, e) => {
Error::InvalidResponsePayload(b, e)
}
Error::InvalidResponsePayload(b, e) => Error::InvalidResponsePayload(b, e),
Error::UnexpectedResponse(r) => Error::UnexpectedResponse(r),
}
}
Expand Down Expand Up @@ -441,26 +427,19 @@ pub fn encode_path(pc: &str) -> String {

#[doc(hidden)]
pub trait RequestBuilderExt<E> {
fn form_urlencoded<T: Serialize + ?Sized>(
self,
body: &T,
) -> Result<RequestBuilder, Error<E>>;
fn form_urlencoded<T: Serialize + ?Sized>(self, body: &T) -> Result<RequestBuilder, Error<E>>;
}

impl<E> RequestBuilderExt<E> for RequestBuilder {
fn form_urlencoded<T: Serialize + ?Sized>(
self,
body: &T,
) -> Result<Self, Error<E>> {
fn form_urlencoded<T: Serialize + ?Sized>(self, body: &T) -> Result<Self, Error<E>> {
Ok(self
.header(
reqwest::header::CONTENT_TYPE,
reqwest::header::HeaderValue::from_static(
"application/x-www-form-urlencoded",
),
reqwest::header::HeaderValue::from_static("application/x-www-form-urlencoded"),
)
.body(serde_urlencoded::to_string(body).map_err(|_| {
Error::InvalidRequest("failed to serialize body".to_string())
})?))
.body(
serde_urlencoded::to_string(body)
.map_err(|_| Error::InvalidRequest("failed to serialize body".to_string()))?,
))
}
}
Loading

0 comments on commit ed29f1b

Please sign in to comment.