5 releases
Uses old Rust 2015
0.1.4 | Sep 8, 2017 |
---|---|
0.1.3 | Sep 8, 2017 |
0.1.2 | Sep 8, 2017 |
0.1.1 | Sep 8, 2017 |
0.1.0 | Sep 8, 2017 |
#23 in #listener
Used in rapt_derive
29KB
259 lines
Rapt
Build status (Linux) | |
Project status | Usable, between alpha and beta |
Production-readiness | Depends on your risk tolerance |
Rapt is a runtime application instrumentation toolkit for Rust.
Contributing
This project is in its very early days and we will always be welcoming contributors.
Our goal is to encourage frictionless contributions to the project. In order to achieve that, we use Unprotocols C4 process. Please read it, it will answer a lot of questions. Our goal is to merge pull requests as quickly as possible and make new stable releases regularly.
In a nutshell, this means:
- We merge pull requests rapidly (try!)
- We are open to diverse ideas
- We prefer code now over consensus later
To learn more, read our contribution guidelines
lib.rs
:
Rapt
Runtime application instrumentation toolkit
Rapt provides a standard interface for providing runtime introspection capabilities for Rust-based libraries and applications.
There are a few key components to this library:
Instrument
Instrument
is a thread-safe wrapper for a Serde-serializable value. It is parametrized
over Listener
Instruments are cloneable and the wrapped value can be safely updated using Instrument#update
.
Instrument board
Instrument board is a concept of aggregating a number of instruments into a
single structure and implementing or deriving Instruments
for it. Please note that if
derivation is used (using rapt_derive
crate), the last type parameter must be bound to
Listener
:
extern crate rapt;
extern crate serde;
#[macro_use]
extern crate rapt_derive;
use serde::Serialize;
use rapt::{Listener, Instrument};
#[allow(dead_code)]
#[derive(Instruments)]
struct AppInstruments<T : Serialize, L: Listener> {
value: Instrument<T, L>,
}
pub fn main() {}
In the above example, L
must always remain the last type parameter.
It is parametrized over Listener
.
Listener
Listener
is a trait that allows instruments to notify interested parties about updates
Example
extern crate rapt;
extern crate serde;
#[macro_use]
extern crate rapt_derive;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate assert_matches;
use serde::Serialize;
use rapt::{Listener, Instrument};
#[derive(Debug, Clone, Copy, Serialize)]
enum Status { Stopped, Started }
#[derive(Clone, Serialize)]
struct Service {
status: Status,
}
#[derive(Instruments)]
struct AppInstruments<L: Listener> {
http_server: Instrument<Service, L>,
}
use std::thread;
use std::time::Duration;
fn main() {
let app_instruments = AppInstruments::<()> {
http_server: Instrument::new(Service { status: Status::Stopped }),
};
let http_server_svc = app_instruments.http_server.clone();
let thread_handle = thread::spawn(move || {
thread::sleep(Duration::from_millis(100));
let _ = http_server_svc.update(|v| v.status = Status::Started).unwrap();
});
thread::sleep(Duration::from_millis(200));
assert_matches!(app_instruments.http_server.read().and_then(|v| Ok(v.status)), Ok(Status::Started));
let _ = thread_handle.join().unwrap();
}
Dependencies
~0.1–1MB
~17K SLoC