Skip to content

Commit

Permalink
Add msgf and valsf flushing versions of the macros
Browse files Browse the repository at this point in the history
  • Loading branch information
nu11ptr committed Jan 28, 2023
1 parent cf0763d commit 814b0d9
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rdbg-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rdbg-client"
version = "0.1.4"
version = "0.1.5"
authors = ["Scott Meeuwsen <smeeuwsen@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "The client library for rdbg"
Expand All @@ -12,4 +12,4 @@ readme = "README.md"
edition = "2021"

[dev-dependencies]
rdbg = { path = "../rdbg", version = "0.2.0" }
rdbg = { path = "../rdbg", version = "0.2.1" }
4 changes: 2 additions & 2 deletions rdbg-view/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rdbg-view"
version = "0.2.2"
version = "0.2.3"
authors = ["Scott Meeuwsen <smeeuwsen@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "A basic command-line viewer for rdbg"
Expand All @@ -12,5 +12,5 @@ readme = "README.md"
edition = "2021"

[dependencies]
rdbg-client = { path = "../rdbg-client", version = "0.1.4" }
rdbg-client = { path = "../rdbg-client", version = "0.1.5" }
clap = { version = "4", features = ["derive"] }
2 changes: 1 addition & 1 deletion rdbg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rdbg"
version = "0.2.0"
version = "0.2.1"
authors = ["Scott Meeuwsen <smeeuwsen@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "Quick and dirty Rust remote debugging"
Expand Down
2 changes: 1 addition & 1 deletion rdbg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ rdbg::flush();

```toml
[dependencies]
rdbg = "0.1"
rdbg = "0.2"
```

## Features
Expand Down
5 changes: 4 additions & 1 deletion rdbg/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ fn main() {
let world = "world";

rdbg::msg!("hello {world}");
rdbg::vals!(world, 1 + 5);
rdbg::flush();
rdbg::vals!(world, 1 + 5);

rdbg::msgf!("hello {world}s");
rdbg::valsf!(world, 2 + 5);
}
78 changes: 72 additions & 6 deletions rdbg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ macro_rules! msg {
};

($($arg:tt)*) => {
$crate::RemoteDebug::default().send_message(file!(), line!(), $crate::MsgPayload::Message(
std::fmt::format(format_args!($($arg)*))
))
$crate::msg!($crate::RemoteDebug::default(), [ $($arg)* ])
};
}

Expand All @@ -58,6 +56,41 @@ macro_rules! msg {
($($arg:tt)*) => {};
}

/// Send a debug message to the remote viewer (with flush)
///
/// ```dontrun
/// // Default port
/// let world = "world!";
/// rdbg::msgf!("Hello {}", world);
/// flush();
///
/// // Custom port
/// let debug = rdbg::port(5000);
/// rdbg::msgf!(&debug, ["Hello {}", world]);
/// debug.flush();
/// ```
#[cfg(feature = "enabled")]
#[macro_export]
macro_rules! msgf {
($port:expr, [ $($arg:tt)* ]) => {{
$port.send_message(file!(), line!(), $crate::MsgPayload::Message(
std::fmt::format(format_args!($($arg)*))
));
$port.flush();
}};

($($arg:tt)*) => {
$crate::msgf!($crate::RemoteDebug::default(), [ $($arg)* ])
};
}

#[cfg(not(feature = "enabled"))]
#[macro_export]
macro_rules! msgf {
($port:expr, [ $($arg:tt)* ]) => {};
($($arg:tt)*) => {};
}

/// Send debug expression name/value pairs to the remote viewer
///
/// ```dontrun
Expand Down Expand Up @@ -85,19 +118,52 @@ macro_rules! vals {
};

($($value:expr),+ $(,)?) => {
$crate::RemoteDebug::default().send_message(file!(), line!(), $crate::MsgPayload::Values(vec![$((
$crate::vals!($crate::RemoteDebug::default(), [ $($value),+ ])
};
}

#[cfg(not(feature = "enabled"))]
#[macro_export]
macro_rules! vals {
($port:expr, [ $($value:expr),+ $(,)? ]) => {};
($($value:expr),+ $(,)?) => {};
}

/// Send debug expression name/value pairs to the remote viewer (with flush)
///
/// ```dontrun
/// // Default port
/// let world = "world!";
/// rdbg::valsf!(world, 1 + 1);
/// flush();
///
/// // Custom port
/// let debug = rdbg::port(5000);
/// rdbg::valsf!(&debug, [world, 1 + 1]);
/// debug.flush();
/// ```
#[cfg(feature = "enabled")]
#[macro_export]
macro_rules! valsf {
($port:expr, [ $($value:expr),+ $(,)? ]) => {{
$port.send_message(file!(), line!(), $crate::MsgPayload::Values(vec![$((
match $value {
val => {
(stringify!($value), format!("{:#?}", &val))
}
}
)),+]))
)),+]));
$port.flush();
}};

($($value:expr),+ $(,)?) => {
$crate::valsf!($crate::RemoteDebug::default(), [ $($value),+ ])
};
}

#[cfg(not(feature = "enabled"))]
#[macro_export]
macro_rules! vals {
macro_rules! valsf {
($port:expr, [ $($value:expr),+ $(,)? ]) => {};
($($value:expr),+ $(,)?) => {};
}
Expand Down

0 comments on commit 814b0d9

Please sign in to comment.