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

Format Rust code on main #20034

Merged
merged 3 commits into from
Oct 21, 2023
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: 10 additions & 10 deletions build-support/preambles/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
#![deny(warnings)]
// Enable all clippy lints except for many of the pedantic ones. It's a shame this needs to be copied and pasted across crates, but there doesn't appear to be a way to include inner attributes from a common source.
#![deny(
clippy::all,
clippy::default_trait_access,
clippy::expl_impl_clone_on_copy,
clippy::if_not_else,
clippy::needless_continue,
clippy::unseparated_literal_suffix,
clippy::used_underscore_binding
clippy::all,
clippy::default_trait_access,
clippy::expl_impl_clone_on_copy,
clippy::if_not_else,
clippy::needless_continue,
clippy::unseparated_literal_suffix,
clippy::used_underscore_binding
)]
// It is often more clear to show that nothing is being moved.
#![allow(clippy::match_ref_pats)]
// Subjective style.
#![allow(
clippy::len_without_is_empty,
clippy::redundant_field_names,
clippy::too_many_arguments
clippy::len_without_is_empty,
clippy::redundant_field_names,
clippy::too_many_arguments
)]
// Default isn't as big a deal as people seem to think it is.
#![allow(clippy::new_without_default, clippy::new_ret_no_self)]
Expand Down
38 changes: 19 additions & 19 deletions src/rust/engine/address/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
#![deny(warnings)]
// Enable all clippy lints except for many of the pedantic ones. It's a shame this needs to be copied and pasted across crates, but there doesn't appear to be a way to include inner attributes from a common source.
#![deny(
clippy::all,
clippy::default_trait_access,
clippy::expl_impl_clone_on_copy,
clippy::if_not_else,
clippy::needless_continue,
clippy::unseparated_literal_suffix,
clippy::used_underscore_binding
clippy::all,
clippy::default_trait_access,
clippy::expl_impl_clone_on_copy,
clippy::if_not_else,
clippy::needless_continue,
clippy::unseparated_literal_suffix,
clippy::used_underscore_binding
)]
// It is often more clear to show that nothing is being moved.
#![allow(clippy::match_ref_pats)]
// Subjective style.
#![allow(
clippy::len_without_is_empty,
clippy::redundant_field_names,
clippy::too_many_arguments
clippy::len_without_is_empty,
clippy::redundant_field_names,
clippy::too_many_arguments
)]
// Default isn't as big a deal as people seem to think it is.
#![allow(clippy::new_without_default, clippy::new_ret_no_self)]
// Arc<Mutex> can be more clear than needing to grok Orderings:
#![allow(clippy::mutex_atomic)]

pub struct AddressInput<'a> {
pub path: &'a str,
pub target: Option<&'a str>,
pub generated: Option<&'a str>,
pub parameters: Vec<(&'a str, &'a str)>,
pub path: &'a str,
pub target: Option<&'a str>,
pub generated: Option<&'a str>,
pub parameters: Vec<(&'a str, &'a str)>,
}

pub struct SpecInput<'a> {
/// The address (or literal, if no target/generated/parameters were specified) portion.
pub address: AddressInput<'a>,
/// If a spec wildcard was specified (`:` or `::`), its value.
pub wildcard: Option<&'a str>,
/// The address (or literal, if no target/generated/parameters were specified) portion.
pub address: AddressInput<'a>,
/// If a spec wildcard was specified (`:` or `::`), its value.
pub wildcard: Option<&'a str>,
}

peg::parser! {
Expand Down Expand Up @@ -90,5 +90,5 @@ peg::parser! {
}

pub fn parse_address_spec(value: &str) -> Result<SpecInput, String> {
parsers::spec(value).map_err(|e| format!("Failed to parse address spec `{value}`: {e}"))
parsers::spec(value).map_err(|e| format!("Failed to parse address spec `{value}`: {e}"))
}
84 changes: 42 additions & 42 deletions src/rust/engine/async_latch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
#![deny(warnings)]
// Enable all clippy lints except for many of the pedantic ones. It's a shame this needs to be copied and pasted across crates, but there doesn't appear to be a way to include inner attributes from a common source.
#![deny(
clippy::all,
clippy::default_trait_access,
clippy::expl_impl_clone_on_copy,
clippy::if_not_else,
clippy::needless_continue,
clippy::unseparated_literal_suffix,
clippy::used_underscore_binding
clippy::all,
clippy::default_trait_access,
clippy::expl_impl_clone_on_copy,
clippy::if_not_else,
clippy::needless_continue,
clippy::unseparated_literal_suffix,
clippy::used_underscore_binding
)]
// It is often more clear to show that nothing is being moved.
#![allow(clippy::match_ref_pats)]
// Subjective style.
#![allow(
clippy::len_without_is_empty,
clippy::redundant_field_names,
clippy::too_many_arguments
clippy::len_without_is_empty,
clippy::redundant_field_names,
clippy::too_many_arguments
)]
// Default isn't as big a deal as people seem to think it is.
#![allow(clippy::new_without_default, clippy::new_ret_no_self)]
Expand All @@ -40,45 +40,45 @@ use tokio::sync::watch;
///
#[derive(Clone)]
pub struct AsyncLatch {
sender: Arc<Mutex<Option<watch::Sender<()>>>>,
receiver: watch::Receiver<()>,
sender: Arc<Mutex<Option<watch::Sender<()>>>>,
receiver: watch::Receiver<()>,
}

impl AsyncLatch {
pub fn new() -> AsyncLatch {
let (sender, receiver) = watch::channel(());
AsyncLatch {
sender: Arc::new(Mutex::new(Some(sender))),
receiver,
pub fn new() -> AsyncLatch {
let (sender, receiver) = watch::channel(());
AsyncLatch {
sender: Arc::new(Mutex::new(Some(sender))),
receiver,
}
}
}

///
/// Mark this latch triggered, releasing all threads that are waiting for it to trigger.
///
/// All calls to trigger after the first one are noops.
///
pub fn trigger(&self) {
// To trigger the latch, we drop the Sender.
self.sender.lock().take();
}
///
/// Mark this latch triggered, releasing all threads that are waiting for it to trigger.
///
/// All calls to trigger after the first one are noops.
///
pub fn trigger(&self) {
// To trigger the latch, we drop the Sender.
self.sender.lock().take();
}

///
/// Wait for another thread to trigger this latch.
///
pub async fn triggered(&self) {
// To see whether the latch is triggered, we clone the receiver, and then wait for our clone to
// return an Err, indicating that the Sender has been dropped.
let mut receiver = self.receiver.clone();
while receiver.changed().await.is_ok() {}
}
///
/// Wait for another thread to trigger this latch.
///
pub async fn triggered(&self) {
// To see whether the latch is triggered, we clone the receiver, and then wait for our clone to
// return an Err, indicating that the Sender has been dropped.
let mut receiver = self.receiver.clone();
while receiver.changed().await.is_ok() {}
}

///
/// Return true if the latch has been triggered.
///
pub fn poll_triggered(&self) -> bool {
self.sender.lock().is_none()
}
///
/// Return true if the latch has been triggered.
///
pub fn poll_triggered(&self) -> bool {
self.sender.lock().is_none()
}
}

#[cfg(test)]
Expand Down
28 changes: 14 additions & 14 deletions src/rust/engine/async_latch/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ use crate::AsyncLatch;

#[tokio::test]
async fn basic() {
let latch = AsyncLatch::new();
let latch = AsyncLatch::new();

let mut join = tokio::spawn({
let latch = latch.clone();
async move { latch.triggered().await }
});
let mut join = tokio::spawn({
let latch = latch.clone();
async move { latch.triggered().await }
});

// Ensure that `triggered` doesn't return until `trigger` has been called.
tokio::select! {
_ = sleep(Duration::from_secs(1)) => {},
_ = &mut join => { panic!("Background task should have continued to wait.") }
}
latch.trigger();
join.await.unwrap();
// Ensure that `triggered` doesn't return until `trigger` has been called.
tokio::select! {
_ = sleep(Duration::from_secs(1)) => {},
_ = &mut join => { panic!("Background task should have continued to wait.") }
}
latch.trigger();
join.await.unwrap();

// And that calling `trigger` again is harmless.
latch.trigger();
// And that calling `trigger` again is harmless.
latch.trigger();
}
Loading