Skip to content

Commit

Permalink
rustfmt everything except generated code
Browse files Browse the repository at this point in the history
I personally disagree with several of rustfmt's decisions, but it's better to be consistent.

Generated code isn't being formatted because
1) it would have to get reformatted every time it gets generated; I'm
   not going to make the generator emit it so it matches rustfmt
2) rustfmt currently chokes on some of the generated code
  • Loading branch information
wfraser committed Jan 13, 2025
1 parent 7ad219f commit abe5753
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 341 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/cargo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ jobs:
with:
submodules: true

- name: Install nightly toolchain
run: |
rustup install nightly --profile minimal
rustup component add clippy --toolchain nightly
rustup component add rustfmt --toolchain nightly
- name: Run rustfmt
# Delete the generated code so it doesn't get formatted.
# We'll be re-running the generator later, so this is okay.
run: |
rm -rf src/generated
echo "// empty module for rustfmt" > src/generated.rs
echo "// empty module for rustfmt" > tests/generated.rs
rustup run nightly cargo fmt --check
rm src/generated.rs
rm tests/generated.rs
- name: Set up Python
uses: actions/[email protected]
with:
Expand All @@ -34,11 +51,6 @@ jobs:
- name: Run cargo test
run: rustup run 1.75.0 cargo test --all-features

- name: Install nightly toolchain
run: |
rustup install nightly --profile minimal
rustup component add clippy --toolchain nightly
- name: Run clippy
run: rustup run nightly cargo clippy --all-targets --all-features -- --deny warnings

Expand Down
23 changes: 15 additions & 8 deletions examples/demo-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! This example illustrates a few basic Dropbox API operations: getting an OAuth2 token, listing
//! the contents of a folder recursively, and fetching a file given its path.
use tokio_util::compat::FuturesAsyncReadCompatExt;
use dropbox_sdk::default_async_client::{NoauthDefaultClient, UserAuthDefaultClient};
use dropbox_sdk::async_routes::files;
use dropbox_sdk::default_async_client::{NoauthDefaultClient, UserAuthDefaultClient};
use tokio_util::compat::FuturesAsyncReadCompatExt;

enum Operation {
Usage,
Expand Down Expand Up @@ -68,7 +68,9 @@ async fn main() {

let mut auth = dropbox_sdk::oauth2::get_auth_from_env_or_prompt();
if auth.save().is_none() {
auth.obtain_access_token_async(NoauthDefaultClient::default()).await.unwrap();
auth.obtain_access_token_async(NoauthDefaultClient::default())
.await
.unwrap();
eprintln!("Next time set these environment variables to reuse this authorization:");
eprintln!(" DBX_CLIENT_ID={}", auth.client_id());
eprintln!(" DBX_OAUTH={}", auth.save().unwrap());
Expand All @@ -84,10 +86,11 @@ async fn main() {
match files::download(&client, &files::DownloadArg::new(path), None, None).await {
Ok(result) => {
match tokio::io::copy(
&mut result.body.expect("there must be a response body")
.compat(),
&mut result.body.expect("there must be a response body").compat(),
&mut tokio::io::stdout(),
).await {
)
.await
{
Ok(n) => {
eprintln!("Downloaded {n} bytes");
}
Expand All @@ -112,7 +115,9 @@ async fn main() {
let mut result = match files::list_folder(
&client,
&files::ListFolderArg::new(path).with_recursive(true),
).await {
)
.await
{
Ok(result) => result,
Err(e) => {
eprintln!("Error from files/list_folder: {e}");
Expand Down Expand Up @@ -145,7 +150,9 @@ async fn main() {
result = match files::list_folder_continue(
&client,
&files::ListFolderContinueArg::new(result.cursor),
).await {
)
.await
{
Ok(result) => {
num_pages += 1;
num_entries += result.entries.len();
Expand Down
3 changes: 2 additions & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ fn main() {

let mut auth = dropbox_sdk::oauth2::get_auth_from_env_or_prompt();
if auth.save().is_none() {
auth.obtain_access_token(NoauthDefaultClient::default()).unwrap();
auth.obtain_access_token(NoauthDefaultClient::default())
.unwrap();
eprintln!("Next time set these environment variables to reuse this authorization:");
eprintln!(" DBX_CLIENT_ID={}", auth.client_id());
eprintln!(" DBX_OAUTH={}", auth.save().unwrap());
Expand Down
Loading

0 comments on commit abe5753

Please sign in to comment.