Skip to content

Commit

Permalink
[rust] Format imports using rustfmt
Browse files Browse the repository at this point in the history
Set `imports_granularity = "Module"` in our rustfmt config, and format
all files using `fx format-code --all -- "*.rs"`.

This change allows for a consistent style across our codebase, and
provides format-on-save functionality for imports. The "Module" option
has a good balance of verbosity vs resistance to merge conflicts.

See the linked bug for additional rationale on this option.

Bug: 340943530
Change-Id: I17453ca5060efa5b5a4622141a553d2b995dff5f
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1061833
Owners-Override: Benjamin Lerman <[email protected]>
Commit-Queue: Marc Khouri <[email protected]>
Reviewed-by: Tyler Mandry <[email protected]>
  • Loading branch information
mnkhouri authored and CQ Bot committed Jun 11, 2024
1 parent b049302 commit 4fcdaf5
Show file tree
Hide file tree
Showing 4,639 changed files with 42,799 additions and 52,514 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 5 additions & 2 deletions build/sdk/meta/src/product_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use anyhow::{anyhow, bail, Context, Result};
use camino::{Utf8Path, Utf8PathBuf};
use fuchsia_repo::repository::FileSystemRepository;
use serde::{Deserialize, Serialize};
use std::{fs::File, io::Read, ops::Deref};
use std::fs::File;
use std::io::Read;
use std::ops::Deref;
use v2::Canonicalizer;
use zip::read::ZipArchive;

Expand Down Expand Up @@ -276,7 +278,8 @@ mod tests {
use serde_json::json;
use std::io::Write;
use tempfile::TempDir;
use zip::{write::FileOptions, CompressionMethod, ZipWriter};
use zip::write::FileOptions;
use zip::{CompressionMethod, ZipWriter};

fn make_sample_pbv1(name: &str) -> serde_json::Value {
json!({
Expand Down
6 changes: 4 additions & 2 deletions build/sdk/meta/src/product_bundle/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ use assembly_manifest::Image;
use assembly_partitions_config::PartitionsConfig;
use camino::{Utf8Path, Utf8PathBuf};
use fuchsia_merkle::Hash;
use fuchsia_repo::{repo_client::RepoClient, repository::FileSystemRepository};
use fuchsia_repo::repo_client::RepoClient;
use fuchsia_repo::repository::FileSystemRepository;
use pathdiff::diff_utf8_paths;
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::collections::HashSet;
use std::str::FromStr;
use std::{cell::RefCell, collections::HashSet};

/// Description of the data needed to set up (flash) a device.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
Expand Down
15 changes: 5 additions & 10 deletions build/sdk/meta/src/virtual_device/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

//! Representation of the virtual_device metadata.
use {
crate::{
common::{
AudioModel, CpuArchitecture, DataUnits, ElementType, Envelope, PointingDevice,
ScreenUnits,
},
json::{schema, JsonObject},
},
serde::{Deserialize, Serialize},
std::collections::HashMap,
use crate::common::{
AudioModel, CpuArchitecture, DataUnits, ElementType, Envelope, PointingDevice, ScreenUnits,
};
use crate::json::{schema, JsonObject};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Specifics for a CPU.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
Expand Down
3 changes: 1 addition & 2 deletions build/tools/formatjson5/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@

use anyhow::Result;
use json5format::*;
use std::fs;
use std::io;
use std::io::{Read, Write};
use std::path::PathBuf;
use std::{fs, io};
use structopt::StructOpt;

/// Parses each file in the given `files` vector and returns a parsed object for each JSON5
Expand Down
6 changes: 3 additions & 3 deletions examples/components/dictionaries/provider/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use fidl::endpoints;
use fidl_fidl_examples_routing_echo::{EchoMarker, EchoRequest, EchoRequestStream};
use fidl_fuchsia_component_sandbox as fsandbox;
use fuchsia_async as fasync;
use fuchsia_component::{client, server::ServiceFs};
use fuchsia_component::client;
use fuchsia_component::server::ServiceFs;
use futures::{StreamExt, TryStreamExt};
use tracing::*;
use {fidl_fuchsia_component_sandbox as fsandbox, fuchsia_async as fasync};

enum IncomingRequest {
Router(fsandbox::RouterRequestStream),
Expand Down
13 changes: 6 additions & 7 deletions examples/components/lifecycle/rust/src/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {
fidl::{handle::AsyncChannel, prelude::*},
fuchsia_runtime::{HandleInfo, HandleType},
futures_util::stream::TryStreamExt,
std::process,
tracing::{error, info},
};
use fidl::handle::AsyncChannel;
use fidl::prelude::*;
use fuchsia_runtime::{HandleInfo, HandleType};
use futures_util::stream::TryStreamExt;
use std::process;
use tracing::{error, info};

// [START imports]
use fidl_fuchsia_process_lifecycle::{LifecycleRequest, LifecycleRequestStream};
Expand Down
4 changes: 3 additions & 1 deletion examples/components/lifecycle/rust/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {fidl_fidl_examples_routing_echo::EchoMarker, fuchsia_component::client, tracing::info};
use fidl_fidl_examples_routing_echo::EchoMarker;
use fuchsia_component::client;
use tracing::info;

// [START imports]
use fidl_fuchsia_component::{BinderMarker, CreateChildArgs, RealmMarker};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// found in the LICENSE file.

// [START example_snippet]
use {anyhow::Error, fidl_fidl_examples_routing_echo as fecho, fuchsia_component::client};
use anyhow::Error;
use fidl_fidl_examples_routing_echo as fecho;
use fuchsia_component::client;

#[fuchsia::test]
async fn echo_integration_test() -> Result<(), Error> {
Expand Down
3 changes: 2 additions & 1 deletion examples/components/routing/rust/echo_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use anyhow::Context;
use fidl_fidl_examples_routing_echo::{EchoRequest, EchoRequestStream};
use fuchsia_component::server::ServiceFs;
use fuchsia_inspect::{component, health::Reporter};
use fuchsia_inspect::component;
use fuchsia_inspect::health::Reporter;
use futures::prelude::*;
// [END imports]

Expand Down
8 changes: 4 additions & 4 deletions examples/components/routing_failed/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {
assert_matches::assert_matches, fidl_fidl_examples_routing_echo as fecho,
fuchsia_component::client, fuchsia_zircon as zx, tracing::info,
};
use assert_matches::assert_matches;
use fuchsia_component::client;
use tracing::info;
use {fidl_fidl_examples_routing_echo as fecho, fuchsia_zircon as zx};

#[fuchsia::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

#![cfg(test)]

use fidl_fuchsia_component as fcomponent;
use fidl_fuchsia_component_decl as fdecl;
use fidl_fuchsia_examples_colocated as fcolocated;
use fidl_fuchsia_memory_attribution as fattribution;
use fidl_fuchsia_process::HandleInfo;
use fuchsia_async as fasync;
use fuchsia_component_test::{
Capability, ChildOptions, RealmBuilder, RealmBuilderParams, Ref, Route,
};
use fuchsia_runtime::HandleType;
use fuchsia_zircon as zx;
use futures_util::{FutureExt, StreamExt};
use std::sync::Arc;
use {
fidl_fuchsia_component as fcomponent, fidl_fuchsia_component_decl as fdecl,
fidl_fuchsia_examples_colocated as fcolocated, fidl_fuchsia_memory_attribution as fattribution,
fuchsia_async as fasync, fuchsia_zircon as zx,
};

#[fuchsia::test]
async fn test_attribute_memory() {
Expand Down
25 changes: 9 additions & 16 deletions examples/components/runner/colocated/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@

use anyhow::{Context, Result};
use attribution::{AttributionServer, AttributionServerHandle, Observer, Publisher};
use fidl::endpoints::ControlHandle;
use fidl::endpoints::RequestStream;
use fidl_fuchsia_component as fcomponent;
use fidl_fuchsia_component_runner as fcrunner;
use fidl_fuchsia_memory_attribution as fattribution;
use fuchsia_async as fasync;
use fidl::endpoints::{ControlHandle, RequestStream};
use fuchsia_component::server::ServiceFs;
use fuchsia_sync::Mutex;
use fuchsia_zircon as zx;
use futures::{StreamExt, TryStreamExt};
use runner::component::{ChannelEpitaph, Controllable, Controller};
use std::{
collections::HashMap,
future::Future,
sync::{
atomic::{AtomicU64, Ordering},
Arc,
},
use std::collections::HashMap;
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use {
fidl_fuchsia_component as fcomponent, fidl_fuchsia_component_runner as fcrunner,
fidl_fuchsia_memory_attribution as fattribution, fuchsia_async as fasync, fuchsia_zircon as zx,
};

use tracing::{info, warn};
Expand Down Expand Up @@ -225,10 +219,9 @@ fn start(
mod tests {
use super::*;
use fidl::endpoints::Proxy;
use fidl_fuchsia_component_decl as fdecl;
use fidl_fuchsia_examples_colocated as fcolocated;
use fidl_fuchsia_process::HandleInfo;
use fuchsia_runtime::HandleType;
use {fidl_fuchsia_component_decl as fdecl, fidl_fuchsia_examples_colocated as fcolocated};

#[fuchsia::test]
async fn test_start_stop_component() {
Expand Down
6 changes: 3 additions & 3 deletions examples/components/runner/colocated/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
use async_lock::OnceCell;
use async_trait::async_trait;
use fidl::endpoints::RequestStream;
use fidl_fuchsia_examples_colocated as fcolocated;
use fidl_fuchsia_process::HandleInfo;
use fuchsia_async as fasync;
use fuchsia_runtime::HandleType;
use fuchsia_zircon as zx;
use futures::future::{BoxFuture, FutureExt};
use futures::TryStreamExt;
use runner::component::{ChannelEpitaph, Controllable};
use std::sync::Arc;
use tracing::warn;
use zx::{AsHandleRef, Koid};
use {
fidl_fuchsia_examples_colocated as fcolocated, fuchsia_async as fasync, fuchsia_zircon as zx,
};

/// [`ColocatedProgram `] represents an instance of a program run by the
/// colocated runner. Its state is held in this struct and its behavior
Expand Down
3 changes: 2 additions & 1 deletion examples/components/services/rust/src/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
//!
//! This program is written as a test so that it can be easily launched with `fx test`.
use fuchsia_component::client as fclient;
use tracing::*;
use {
fidl_fuchsia_component as fcomponent, fidl_fuchsia_component_decl as fdecl,
fidl_fuchsia_examples_services as fexamples, fidl_fuchsia_io as fio,
fuchsia_component::client as fclient, tracing::*,
};

const COLLECTION_NAME: &'static str = "account_providers";
Expand Down
17 changes: 8 additions & 9 deletions examples/components/services/rust/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//! initialized with a bank account owner's name (first arg in CML) and an initial balance in cents
//! (second arg in CML).
use {
anyhow::{Context, Result},
fidl_fuchsia_examples_services as fexamples,
fuchsia_component::server::ServiceFs,
futures::lock::Mutex,
futures::prelude::*,
std::{env, sync::Arc},
tracing::*,
};
use anyhow::{Context, Result};
use fidl_fuchsia_examples_services as fexamples;
use fuchsia_component::server::ServiceFs;
use futures::lock::Mutex;
use futures::prelude::*;
use std::env;
use std::sync::Arc;
use tracing::*;

struct Account {
/// Account owner's name.
Expand Down
34 changes: 14 additions & 20 deletions examples/components/storage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {
anyhow::{anyhow, Error},
byteorder::{BigEndian, ByteOrder, WriteBytesExt},
fuchsia_component::server::ServiceFs,
fuchsia_inspect::{Inspector, Node},
futures::stream::StreamExt,
lazy_static::lazy_static,
std::{
fs,
io::Read,
path::{Path, PathBuf},
},
tracing::{info, warn},
};
use anyhow::{anyhow, Error};
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use fuchsia_component::server::ServiceFs;
use fuchsia_inspect::{Inspector, Node};
use futures::stream::StreamExt;
use lazy_static::lazy_static;
use std::fs;
use std::io::Read;
use std::path::{Path, PathBuf};
use tracing::{info, warn};

const U64_SIZE: usize = (u64::BITS / 8) as usize;
const DEFAULT_VALUE: u64 = 1;
Expand Down Expand Up @@ -99,12 +95,10 @@ fn write_file(path: &Path, value: u64) -> Result<(), Error> {

#[cfg(test)]
mod tests {
use {
super::*,
diagnostics_assertions::{assert_data_tree, AnyProperty},
tempfile::TempDir,
test_case::test_case,
};
use super::*;
use diagnostics_assertions::{assert_data_tree, AnyProperty};
use tempfile::TempDir;
use test_case::test_case;

fn make_path() -> (TempDir, PathBuf) {
let dir = TempDir::new().expect("error creating tempdir");
Expand Down
9 changes: 4 additions & 5 deletions examples/components/subpackages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {
component_events::{events::*, matcher::*},
fuchsia_component_test::{Capability, ChildOptions, RealmBuilder, Ref, Route},
tracing::*,
};
use component_events::events::*;
use component_events::matcher::*;
use fuchsia_component_test::{Capability, ChildOptions, RealmBuilder, Ref, Route};
use tracing::*;

// This test demonstrates constructing a realm with two child components
// and verifying the `fidl.examples.routing.Echo` protocol.
Expand Down
14 changes: 6 additions & 8 deletions examples/diagnostics/inspect/codelab/rust/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {
anyhow::Error,
fidl_fuchsia_component::BinderMarker,
fidl_fuchsia_examples_inspect::ReverserMarker,
fuchsia_component::client,
fuchsia_zircon::DurationNum,
tracing::{error, info},
};
use anyhow::Error;
use fidl_fuchsia_component::BinderMarker;
use fidl_fuchsia_examples_inspect::ReverserMarker;
use fuchsia_component::client;
use fuchsia_zircon::DurationNum;
use tracing::{error, info};

struct Args {
strings: Vec<String>,
Expand Down
20 changes: 9 additions & 11 deletions examples/diagnostics/inspect/codelab/rust/fizzbuzz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {
anyhow::{Context, Error},
fidl_fuchsia_examples_inspect::{FizzBuzzRequest, FizzBuzzRequestStream},
fuchsia_async as fasync,
fuchsia_component::server::ServiceFs,
fuchsia_inspect::{self as inspect, component, HistogramProperty, NumericProperty},
fuchsia_zircon::{self as zx},
futures::{StreamExt, TryStreamExt},
std::sync::Arc,
tracing::{error, info},
};
use anyhow::{Context, Error};
use fidl_fuchsia_examples_inspect::{FizzBuzzRequest, FizzBuzzRequestStream};
use fuchsia_async as fasync;
use fuchsia_component::server::ServiceFs;
use fuchsia_inspect::{self as inspect, component, HistogramProperty, NumericProperty};
use fuchsia_zircon::{self as zx};
use futures::{StreamExt, TryStreamExt};
use std::sync::Arc;
use tracing::{error, info};

struct FizzBuzzServerMetrics {
incoming_connection_count: inspect::UintProperty,
Expand Down
Loading

0 comments on commit 4fcdaf5

Please sign in to comment.