Expand description

This crate is a dependency of the following crates:

  1. r3bl_rs_utils_macro (procedural macros)
  2. r3bl_rs_utils

Due to the requirements of proc macros being in a separate crate, this breakdown of one crate into multiple crates is necessary:

  1. Put some code in a separate crate (r3bl_rs_utils_core) that is used by other crates.
  2. Put the proc macros in a separate crate (r3bl_rs_utils_macro). This crate also depends on the r3bl_rs_utils_core crate.
  3. Finally, make the “public” crate (r3bl_rs_utils) depend on the other two.

As a way to hide this kind of layering from the users of the “main” r3bl_rs_utils crate, all the modules tend to be re-exported, making them available from the “main” or top-level crate.

Re-exports

pub use color_text::styles::*;
pub use color_text::*;
pub use common::*;
pub use decl_macros::*;
pub use tui_core::*;

Modules

ANSI colorized text https://github.com/ogham/rust-ansi-term helper methods.

All the modules in the r3bl_rs_utils_core crate are in support of the tui module in the “main” r3bl_rs_utils crate.

Macros

Similar to assert_eq! but automatically prints the left and right hand side variables if the assertion fails. Useful for debugging tests, since the cargo would just print out the left and right values w/out providing information on what variables were being compared.

Syntactic sugar to run a conditional statement. Here’s an example.

Given a mutable Lolcat, colorize the token tree that follows.

Converts a variety of types (i32, usize) to a UnitType.

This is a really simple macro to make it effortless to use the color console logger. It takes a single identifier as an argument, or any number of them. It simply dumps an arrow symbol, followed by the identifier (stringify’d) along with the value that it contains (using the Debug formatter). All of the output is colorized for easy readability. You can use it like this.

Declarative macro to surround the given block with a call to tokio::spawn. This is useful for spawning a task that will run in the background from a function that is NOT async.

Declarative macro to generate the API call functions. This adds the following:

Wrap the given block or stmt so that it returns a Result<()>. It is just syntactic sugar that helps having to write Ok(()) repeatedly.

Wrap the given block or stmt so that it returns a Result<$it>. It is just syntactic sugar that helps having to write Ok($it) repeatedly.

Unwrap the $option, and if None then run the $next closure which must return a value that is set to $option. Basically a way to compute something lazily when it (the Option) is set to None.

Unwrap the $option, and if None then run the $next closure which must return an error. This macro must be called in a block that returns a CommonResult<T>.

Runs the $code block after evaluating the $eval expression and assigning it to $id.

Similar to with! except $id is a mutable reference to the $eval expression.

Similar to with_mut! except that it returns the value of the $code block.