Skip to content
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

rust: Use nightly rustfmt to control comment wrapping and import formatting #1268

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/rust-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ env:
CARGO_TERM_COLOR: always

jobs:
check-fmt:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: rustfmt
run: cargo fmt -- --check
working-directory: rust

test-versions:
name: Rust Lint
runs-on: ubuntu-latest
Expand All @@ -41,7 +55,7 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
components: clippy

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -56,10 +70,6 @@ jobs:
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: rust

- name: rustfmt
run: cargo fmt -- --check
working-directory: rust

- name: Run tests
run: cargo test --all
working-directory: rust
2 changes: 2 additions & 0 deletions rust/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
wrap_comments = true
imports_granularity = "Crate"
21 changes: 11 additions & 10 deletions rust/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use hyper_util::client::legacy::Client as HyperClient;
use hyper_util::rt::TokioExecutor;

use crate::apis::{
application_api, authentication_api, background_tasks_api, endpoint_api, event_type_api,
integration_api, message_api, message_attempt_api, statistics_api,
use hyper_util::{client::legacy::Client as HyperClient, rt::TokioExecutor};

use crate::{
apis::{
application_api, authentication_api, background_tasks_api, endpoint_api, event_type_api,
integration_api, message_api, message_attempt_api, statistics_api,
},
error::Result,
Configuration,
};
use crate::error::Result;
pub use crate::models::*;
use crate::Configuration;

#[cfg(feature = "svix_beta")]
pub use message_api::{V1MessageStreamError, V1MessageStreamParams};
pub use crate::apis::message_api::{V1MessageStreamError, V1MessageStreamParams};
pub use crate::models::*;

const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down
3 changes: 2 additions & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ fn default_connector() -> Connector {
}
}

/// Convert a `StatusCode` from the http crate v1 to one from the http crate v0.2.
/// Convert a `StatusCode` from the http crate v1 to one from the http crate
/// v0.2.
fn http1_to_02_status_code(code: http1::StatusCode) -> http02::StatusCode {
http02::StatusCode::from_u16(code.as_u16())
.expect("both versions of the http crate enforce the same numerical limits for StatusCode")
Expand Down
15 changes: 8 additions & 7 deletions rust/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Modified version of the file openapi-generator would usually put in apis/request.rs
// Modified version of the file openapi-generator would usually put in
// apis/request.rs

use std::collections::HashMap;

Expand All @@ -14,9 +15,9 @@ pub(crate) enum Auth {
Bearer,
}

/// If the authorization type is unspecified then it will be automatically detected based
/// on the configuration. This functionality is useful when the OpenAPI definition does not
/// include an authorization scheme.
/// If the authorization type is unspecified then it will be automatically
/// detected based on the configuration. This functionality is useful when the
/// OpenAPI definition does not include an authorization scheme.
pub(crate) struct Request {
auth: Option<Auth>,
method: http1::Method,
Expand Down Expand Up @@ -93,9 +94,9 @@ impl Request {

let mut uri = format!("{}{}", conf.base_path, path);

// Work around rustc issue - we need to make sure that `query_string` is not captured
// by the outer `async` generator. Using `drop(query_string)` is insufficient, so we
// create a new scope
// Work around rustc issue - we need to make sure that `query_string` is
// not captured by the outer `async` generator. Using
// `drop(query_string)` is insufficient, so we create a new scope
{
let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned());
for (key, val) in self.query_params {
Expand Down
5 changes: 3 additions & 2 deletions rust/src/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ impl Webhook {
}
}

/// Trait to abstract over the `HeaderMap` types from both v0.2 and v1.0 of the `http` crate.
/// Trait to abstract over the `HeaderMap` types from both v0.2 and v1.0 of the
/// `http` crate.
pub trait HeaderMap: private::HeaderMapSealed {}

impl HeaderMap for http02::HeaderMap {}
Expand Down Expand Up @@ -186,9 +187,9 @@ mod private {

#[cfg(test)]
mod tests {
use http02::HeaderMap;

use super::*;
use http02::HeaderMap;

fn get_svix_headers(msg_id: &str, signature: &str) -> HeaderMap {
let mut headers = HeaderMap::new();
Expand Down