Expand description
Rust client for the Ray debugging app.
Install (package name is ray-dbg, crate is ray):
[dependencies]
ray = { version = "0.1", package = "ray-dbg" }Fluent chaining is the intended style:
use ray::ray;
ray!("Hello from Rust").green().label("init");Ray app workflow (screens, labels, visuals):
use ray::ray;
use serde::Serialize;
#[derive(Serialize)]
struct User {
id: u64,
name: &'static str,
}
let user = User { id: 1, name: "Ada" };
ray!().new_screen("Checkout flow");
ray!(&user).label("user").green();
ray!().table(&user).label("user table");
ray!().image("https://example.com/avatar.png").label("avatar");
ray!().separator();
ray!().link("https://myray.app").label("Ray docs");
ray!().notify("Checkout complete");Send multiple values in one call:
use ray::ray;
ray!("first", "second", "third");See the caller or full trace:
use ray::ray;
ray!().caller();
ray!().trace();Render custom payloads (JSON, HTML, XML, files, URLs):
use ray::ray;
use serde::Serialize;
#[derive(Serialize)]
struct Event {
name: String,
}
let event = Event { name: "started".into() };
ray!().to_json(&event).label("json");
ray!().html("<strong>bold html</strong>");
ray!().xml("<root />");
ray!().file("Cargo.toml");
ray!().url("https://example.com");ray_dbg! mirrors dbg! by labeling the expression and returning it:
It uses Debug formatting, so any Debug value works.
use ray::ray_dbg;
let value = ray_dbg!(2 + 2);
assert_eq!(value, 4);Send panic details to Ray:
ray::panic_hook();Pause execution (no-op stub):
use ray::ray;
ray!().pause();Halt execution with die or rd!:
use ray::{ray, rd};
ray!("fatal").die();
rd!("fatal");Count executions and read counters:
use ray::ray;
for _ in 0..3 {
ray!().count();
}
for _ in 0..2 {
ray!().count_named("first");
}
if ray!().counter_value("first") == 2 {
ray!("counter value is two!");
}Measure time and memory usage between calls:
use ray::ray;
use std::thread;
use std::time::Duration;
ray!().measure();
thread::sleep(Duration::from_millis(200));
ray!().measure();Display the class name of an object:
use ray::ray;
let value = vec![1, 2, 3];
ray!().class_name(&value);Update a single entry by reusing the same Ray handle:
use ray::ray;
let mut ray = ray!("counting down");
for n in (1..=3).rev() {
ray = ray.send(&n);
}
ray.green().small().label("count");Conditionally show items with when:
use ray::ray;
ray!().when(true, |ray| ray.log(&"will be shown"));
ray!().when(false, |ray| ray.log(&"will be hidden"));Return a value while still sending it to Ray:
use ray::ray;
let value = ray!().pass("return value");
assert_eq!(value, "return value");Show Rust runtime/build info (alias: phpinfo):
use ray::ray;
ray!().rust_info();
ray!().phpinfo_with_env(["RUST_LOG", "PATH"]);Display exceptions and handle fallible callables:
use ray::ray;
let err = std::io::Error::new(std::io::ErrorKind::Other, "boom");
ray!().exception(&err);
ray!().catch(|| -> Result<(), std::io::Error> {
Err(std::io::Error::new(std::io::ErrorKind::Other, "boom"))
});Show raw Debug output:
use ray::ray;
let value = vec![1, 2, 3];
ray!().raw(&value);Remove items and manage screens:
use ray::ray;
let handle = ray!("will be removed");
handle.remove();
ray!().new_screen("Example screen");
ray!().clear_all();Control app visibility and UI helpers:
use ray::ray;
ray!().show_app();
ray!().hide_app();
ray!().notify("Hello from Ray");
ray!().confetti();Additional helpers (limit/once, rate limiting, carbon):
use ray::{ray, ray_once};
use std::time::SystemTime;
ray!().limit(2).text("only twice");
ray!().once().text("only once");
ray!().once_send("only once (send)");
ray_once!("only once (macro)");
ray!().rate_limiter().max(10).per_second(5);
ray!().carbon(SystemTime::now());Batch multiple entries into a single request:
use ray::ray;
ray!()
.batch()
.log(&"first")
.label("batch")
.commit();Async support (feature: transport-reqwest):
ray_async!().label("async").await;Tracing integration (feature: tracing):
ray::tracing::init().unwrap();
tracing::info!("hello from tracing");ray! logs Serialize values as JSON. ray_json! is an explicit alias:
use ray::ray_json;
use serde::Serialize;
#[derive(Serialize)]
struct Event {
name: String,
}
ray_json!(Event {
name: "started".to_string(),
});Modules§
- payload
- Payload content types sent to the Ray server.
Macros§
- ray
- Create a
Rayhandle for fluent chaining or logSerializevalues immediately.ray!()returns a handle, andray!(value, ...)logs and returns the handle so you can keep chaining. Serialization errors are converted to strings. For Debug-only types, useray!().raw(&value). - ray_dbg
- Debug helper that sends a value to Ray and returns it.
Labels the entry with the expression string, similar to
dbg!. - ray_
json - Log values as JSON using
Serialize.ray_json!()returns a handle, andray_json!(value, ...)logs and returns the handle for chaining.ray!(json: value, ...)is an alias if you prefer to stay onray!. - ray_
once - Send values to Ray only once from the callsite.
- ray_
strict - Create a
Rayhandle with strict error handling. - rd
- Send values to Ray and terminate the process (alias of
ray!(...).die()).
Structs§
- Client
- Sends serialized Ray requests over the configured transport.
- Origin
- Callsite metadata attached to each payload.
- Payload
Envelope - Envelope for a single Ray payload.
- Rate
Limiter Handle - RayConfig
- Runtime configuration for the Ray client.
- RayUrl
- Parsed, validated URL for Ray link payloads.
- Request
- A serialized Ray request containing one or more payloads.
Enums§
- Config
Error - Errors returned by
RayConfig::validate. - RayError
- Errors returned by Ray requests.
Traits§
- RayUrl
Input - Accepted URL inputs for Ray link methods.
Functions§
- panic_
hook - Install a panic hook that sends panic details to Ray.
Type Aliases§
- Ray
- Main entry point for sending payloads to Ray.
- RayBatch
- Buffers multiple payloads and sends them in a single request with
commit. Each payload becomes its own Ray entry; use chaining on aRayhandle to update a single entry.commitis best-effort and ignores transport errors; usetry_committo surface errors.