From b6cf9b0eeb64f890d16b9b1636e5a95a3f9feb09 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 13 Jul 2024 09:59:59 +0000 Subject: [PATCH] Format Rust code using rustfmt --- core/src/core/engine.rs | 5 ++--- core/src/field.rs | 26 +++++++++++++++--------- core/src/lib.rs | 6 +++--- core/src/logger.rs | 15 ++++++-------- core/src/profiler/interface.rs | 2 +- core/src/profiler/mod.rs | 2 +- core/src/profiler/section.rs | 33 ++++++++++++++++-------------- core/src/trace/interface.rs | 2 +- core/src/trace/span.rs | 37 +++++++++++++++++++++------------- core/src/util.rs | 4 +++- 10 files changed, 75 insertions(+), 57 deletions(-) diff --git a/core/src/core/engine.rs b/core/src/core/engine.rs index 2d0dc08..020f7bf 100644 --- a/core/src/core/engine.rs +++ b/core/src/core/engine.rs @@ -26,14 +26,13 @@ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::fmt::Arguments; -use std::num::NonZeroU32; use crate::field::FieldSet; use crate::trace::span::Callsite; +use std::fmt::Arguments; +use std::num::NonZeroU32; pub enum Engine { None, - } impl crate::profiler::Profiler for Engine { diff --git a/core/src/field.rs b/core/src/field.rs index 58cf638..885c315 100644 --- a/core/src/field.rs +++ b/core/src/field.rs @@ -34,26 +34,26 @@ pub enum FieldValue<'a> { Float(f32), Double(f64), String(&'a str), - Debug(&'a dyn Debug) + Debug(&'a dyn Debug), } pub struct Field<'a> { name: &'a str, - value: FieldValue<'a> + value: FieldValue<'a>, } impl<'a> Field<'a> { pub fn new(name: &'a str, value: impl Into>) -> Self { Self { name, - value: value.into() + value: value.into(), } } pub fn new_debug(name: &'a str, value: &'a dyn Debug) -> Self { Self { name, - value: FieldValue::Debug(value) + value: FieldValue::Debug(value), } } @@ -105,17 +105,25 @@ impl<'a> FieldSet<'a> { Self(fields) } - pub fn iter(&self) -> impl Iterator> { + pub fn iter(&self) -> impl Iterator> { self.0.iter() } } #[macro_export] macro_rules! field { - ($name: ident) => {$crate::field::Field::new(stringify!($name), $name)}; - (?$name: ident) => {$crate::field::Field::new_debug(stringify!($name), &$name)}; - ($name: ident = $value: expr) => {$crate::field::Field::new(stringify!($name), $value)}; - ($name: ident = ?$value: expr) => {$crate::field::Field::new_debug(stringify!($name), &$value)}; + ($name: ident) => { + $crate::field::Field::new(stringify!($name), $name) + }; + (?$name: ident) => { + $crate::field::Field::new_debug(stringify!($name), &$name) + }; + ($name: ident = $value: expr) => { + $crate::field::Field::new(stringify!($name), $value) + }; + ($name: ident = ?$value: expr) => { + $crate::field::Field::new_debug(stringify!($name), &$value) + }; } #[macro_export] diff --git a/core/src/lib.rs b/core/src/lib.rs index 23c860b..4670e2d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -27,9 +27,9 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. mod core; -pub mod profiler; pub mod field; -mod util; pub mod logger; -pub mod trace; mod macros; +pub mod profiler; +pub mod trace; +mod util; diff --git a/core/src/logger.rs b/core/src/logger.rs index 4b9f1cd..b1e8e99 100644 --- a/core/src/logger.rs +++ b/core/src/logger.rs @@ -26,21 +26,18 @@ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::fmt::Arguments; -use bp3d_logger::{Level, Location}; use crate::field::FieldSet; +use bp3d_logger::{Level, Location}; +use std::fmt::Arguments; pub struct Callsite { location: Location, - level: Level + level: Level, } impl Callsite { pub const fn new(location: Location, level: Level) -> Self { - Self { - location, - level - } + Self { location, level } } } @@ -54,13 +51,13 @@ extern "Rust" { #[cfg(test)] mod tests { - use bp3d_logger::Level; use crate::log; + use bp3d_logger::Level; #[test] fn api_test() { let i = 42; - log!(Level::Info, {i}, "test: {i}: {}", i); + log!(Level::Info, { i }, "test: {i}: {}", i); log!(Level::Error, "test: {}", i); } } diff --git a/core/src/profiler/interface.rs b/core/src/profiler/interface.rs index d0027e4..f59af26 100644 --- a/core/src/profiler/interface.rs +++ b/core/src/profiler/interface.rs @@ -26,9 +26,9 @@ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::num::NonZeroU32; use crate::field::FieldSet; use crate::profiler::section::Section; +use std::num::NonZeroU32; pub trait Profiler { fn section_register(&self, section: &'static Section) -> NonZeroU32; diff --git a/core/src/profiler/mod.rs b/core/src/profiler/mod.rs index 0e077ec..915834a 100644 --- a/core/src/profiler/mod.rs +++ b/core/src/profiler/mod.rs @@ -26,7 +26,7 @@ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -pub mod section; mod interface; +pub mod section; pub use interface::*; diff --git a/core/src/profiler/section.rs b/core/src/profiler/section.rs index e7f9864..708ae8b 100644 --- a/core/src/profiler/section.rs +++ b/core/src/profiler/section.rs @@ -26,12 +26,12 @@ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::num::NonZeroU32; -use std::sync::{OnceLock}; -use std::time::Instant; -use bp3d_logger::Location; use crate::field::FieldSet; use crate::profiler::Profiler; +use bp3d_logger::Location; +use std::num::NonZeroU32; +use std::sync::OnceLock; +use std::time::Instant; #[repr(u8)] #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -43,7 +43,7 @@ pub enum Level { Periodic = 1, // An event based section. - Event = 2 + Event = 2, } thread_local! { @@ -53,7 +53,7 @@ thread_local! { pub struct Entered<'a> { id: NonZeroU32, start: u64, - fields: FieldSet<'a> + fields: FieldSet<'a>, } impl<'a> Drop for Entered<'a> { @@ -69,7 +69,7 @@ pub struct Section { location: Location, level: Level, parent: Option<&'static Section>, - id: OnceLock> + id: OnceLock>, } impl Section { @@ -79,7 +79,7 @@ impl Section { location, level, parent: None, - id: OnceLock::new() + id: OnceLock::new(), } } @@ -105,7 +105,8 @@ impl Section { } pub fn get_id(&'static self) -> &Option { - self.id.get_or_init(|| crate::core::ENGINE.get().map(|v| v.section_register(self))) + self.id + .get_or_init(|| crate::core::ENGINE.get().map(|v| v.section_register(self))) } pub fn enter<'a>(&'static self, fields: FieldSet<'a>) -> Option> { @@ -113,20 +114,20 @@ impl Section { id.map(|id| Entered { id, start: CUR_TIME.with(|v| v.elapsed().as_nanos() as _), - fields + fields, }) } } #[cfg(test)] mod tests { - use crate::{field, fields, location}; use crate::profiler::profiler_section_register; use crate::profiler::section::{Level, Section}; + use crate::{field, fields, location}; mod whatever { - use std::num::NonZeroU32; use crate::profiler::section::Section; + use std::num::NonZeroU32; /*#[no_mangle] pub extern "Rust" fn profiler_section_register(section: &'static Section) -> NonZeroU32 { @@ -143,8 +144,8 @@ mod tests { #[test] fn api_test() { static SECTION: Section = Section::new("api_test", location!(), Level::Event); - static SECTION2: Section = Section::new("api_test2", location!(), Level::Event) - .set_parent(&SECTION); + static SECTION2: Section = + Section::new("api_test2", location!(), Level::Event).set_parent(&SECTION); /*assert!(SECTION.enter([]).is_none()); assert!(SECTION.enter(("test", 42)).is_none()); assert!(SECTION.enter(("test", "test 123")).is_none()); @@ -154,6 +155,8 @@ mod tests { let value = 32; let str = "this is a test"; let lvl = Level::Event; - assert!(SECTION.enter(fields!({value} {str} {?lvl} {test = value})).is_none()); + assert!(SECTION + .enter(fields!({value} {str} {?lvl} {test = value})) + .is_none()); } } diff --git a/core/src/trace/interface.rs b/core/src/trace/interface.rs index 67d7df2..c079425 100644 --- a/core/src/trace/interface.rs +++ b/core/src/trace/interface.rs @@ -26,9 +26,9 @@ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::num::NonZeroU32; use crate::field::FieldSet; use crate::trace::span::Callsite; +use std::num::NonZeroU32; pub trait Tracer { fn register_callsite(&self, callsite: &'static Callsite) -> NonZeroU32; diff --git a/core/src/trace/span.rs b/core/src/trace/span.rs index d9e4076..561d7df 100644 --- a/core/src/trace/span.rs +++ b/core/src/trace/span.rs @@ -26,16 +26,16 @@ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::num::NonZeroU32; -use std::sync::OnceLock; -use bp3d_logger::Location; use crate::field::FieldSet; use crate::trace::Tracer; +use bp3d_logger::Location; +use std::num::NonZeroU32; +use std::sync::OnceLock; pub struct Callsite { name: &'static str, location: Location, - id: OnceLock> + id: OnceLock>, } impl Callsite { @@ -43,32 +43,41 @@ impl Callsite { Self { name, location, - id: OnceLock::new() + id: OnceLock::new(), } } pub fn get_id(&'static self) -> &Option { - self.id.get_or_init(|| crate::core::ENGINE.get().map(|v| v.register_callsite(self))) + self.id + .get_or_init(|| crate::core::ENGINE.get().map(|v| v.register_callsite(self))) } } pub struct Span { - id: Option + id: Option, } impl Span { pub fn new(callsite: &'static Callsite, fields: &FieldSet) -> Self { - let id = callsite.get_id() - .map(|cid| crate::core::ENGINE.get().map(|v| v.span_create(cid, fields))) + let id = callsite + .get_id() + .map(|cid| { + crate::core::ENGINE + .get() + .map(|v| v.span_create(cid, fields)) + }) .flatten(); - Self { - id - } + Self { id } } pub fn record(&self, fields: &FieldSet) { if let Some(id) = self.id { - unsafe { crate::core::ENGINE.get().unwrap_unchecked().span_record(id, fields) }; + unsafe { + crate::core::ENGINE + .get() + .unwrap_unchecked() + .span_record(id, fields) + }; } } @@ -79,7 +88,7 @@ impl Span { } } -impl Drop for Span { +impl Drop for Span { fn drop(&mut self) { if let Some(id) = self.id { unsafe { crate::core::ENGINE.get().unwrap_unchecked().span_exit(id) }; diff --git a/core/src/util.rs b/core/src/util.rs index 02cd9ef..04a0991 100644 --- a/core/src/util.rs +++ b/core/src/util.rs @@ -28,5 +28,7 @@ #[macro_export] macro_rules! location { - () => {bp3d_logger::Location::new(module_path!(), file!(), line!())}; + () => { + bp3d_logger::Location::new(module_path!(), file!(), line!()) + }; }