]> git.lizzy.rs Git - rust.git/commitdiff
Make printin the backtrace more convenient
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 14 Jan 2021 11:55:13 +0000 (14:55 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 14 Jan 2021 11:55:13 +0000 (14:55 +0300)
Cargo.lock
crates/profile/Cargo.toml
crates/profile/src/lib.rs
crates/stdx/Cargo.toml
crates/stdx/src/lib.rs

index 7b175ec677e3aee9ba500f87368838262905ba9d..ae99b966ea137409de0422f80450efec44731d83 100644 (file)
@@ -1197,7 +1197,6 @@ name = "profile"
 version = "0.0.0"
 dependencies = [
  "arena",
- "backtrace",
  "cfg-if 1.0.0",
  "libc",
  "once_cell",
@@ -1566,6 +1565,9 @@ dependencies = [
 [[package]]
 name = "stdx"
 version = "0.0.0"
+dependencies = [
+ "backtrace",
+]
 
 [[package]]
 name = "syn"
index c5dfdff32ebf66ddd5298650f5c37da7fb28c76b..4951f1835cf4b00404991afa8a82e1a83dd698ce 100644 (file)
@@ -13,7 +13,6 @@ doctest = false
 once_cell = "1.3.1"
 cfg-if = "1"
 libc = "0.2.73"
-backtrace = { version = "0.3.44", optional = true }
 
 arena = { path = "../arena", version = "0.0.0" }
 
@@ -24,5 +23,4 @@ perf-event = "0.4"
 cpu_profiler = []
 
 # Uncomment to enable for the whole crate graph
-# default = [ "backtrace" ]
 # default = [ "cpu_profiler" ]
index ab19271c70cf6aaaa09e62a350c1f4c392c68336..aa6ccc36c3f3a31305f3710c2c5be11ddd45ff62 100644 (file)
     stop_watch::{StopWatch, StopWatchSpan},
 };
 
-/// Prints backtrace to stderr, useful for debugging.
-#[cfg(feature = "backtrace")]
-pub fn print_backtrace() {
-    let bt = backtrace::Backtrace::new();
-    eprintln!("{:?}", bt);
-}
-#[cfg(not(feature = "backtrace"))]
-pub fn print_backtrace() {
-    eprintln!(
-        r#"enable the backtrace feature:
-    profile = {{ path = "../profile", features = [ "backtrace"] }}
-"#
-    );
-}
-
 thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false));
 
 /// Allows to check if the current code is withing some dynamic scope, can be
index 8d7a51156261be9a42f5c53d3bf79dfe24d971d5..c47e8d0a86bd9061c1a050ab907b470a9e1fc174 100644 (file)
@@ -10,4 +10,9 @@ edition = "2018"
 doctest = false
 
 [dependencies]
+backtrace = { version = "0.3.44", optional = true }
 # Think twice before adding anything here
+
+[features]
+# Uncomment to enable for the whole crate graph
+# default = [ "backtrace" ]
index 13aab1451ec0b22d332e12082c7b69ef2bf4acbb..d9a62e943b68ae392d4767b85455efb7cb26cd9e 100644 (file)
@@ -25,6 +25,27 @@ fn drop(&mut self) {
     Guard { label, start: Instant::now() }
 }
 
+/// Prints backtrace to stderr, useful for debugging.
+#[cfg(feature = "backtrace")]
+pub fn print_backtrace() {
+    let bt = backtrace::Backtrace::new();
+    eprintln!("{:?}", bt);
+}
+#[cfg(not(feature = "backtrace"))]
+pub fn print_backtrace() {
+    eprintln!(
+        r#"Enable the backtrace feature.
+Uncomment `default = [ "backtrace" ]` in `crates/stdx/Cargo.toml`.
+"#
+    );
+}
+
+pub fn to_lower_snake_case(s: &str) -> String {
+    to_snake_case(s, char::to_ascii_lowercase)
+}
+pub fn to_upper_snake_case(s: &str) -> String {
+    to_snake_case(s, char::to_ascii_uppercase)
+}
 fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String {
     let mut buf = String::with_capacity(s.len());
     let mut prev = false;
@@ -43,14 +64,6 @@ fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String {
     buf
 }
 
-pub fn to_lower_snake_case(s: &str) -> String {
-    to_snake_case(s, char::to_ascii_lowercase)
-}
-
-pub fn to_upper_snake_case(s: &str) -> String {
-    to_snake_case(s, char::to_ascii_uppercase)
-}
-
 pub fn replace(buf: &mut String, from: char, to: &str) {
     if !buf.contains(from) {
         return;