pub struct Wrapper<T: ?Sized> { /* private fields */ }
Expand description
Create this to register a variable to be debugged
Implementations§
source§impl<T: ?Sized> Wrapper<T>
impl<T: ?Sized> Wrapper<T>
sourcepub fn new(tp: u64, data: &T, name: Arguments<'_>) -> Wrapper<T>
pub fn new(tp: u64, data: &T, name: Arguments<'_>) -> Wrapper<T>
Call new_signal()
with FEBUG_SIGNUM
(SIGUSR2
by default)
Examples found in repository?
examples/string-sorts.rs (line 36)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
fn main() {
febug::start();
if febug::install_handler() {
// Normal registration by TypeId, variables use .wrap(...)
let mut fmt = febug::FORMATTERS.lock().unwrap();
fmt.insert(TypeId::of::<String>().into(), |of, vid| {
let data = unsafe { &*(vid as *const String) };
let _ = of.write_all(data.as_bytes());
let _ = of.write_all(b"\n");
});
// Custom registration with an explicit type number and Wrapper::new()
fmt.insert(0.into(), |of: &mut File, _| {
let _ = write!(of, "{}\n", COMPARISONS.load(Ordering::Relaxed));
});
}
let _comparisons_wrapper = Wrapper::new(0, &COMPARISONS, format_args!("comparisons"));
let threads = (0..10)
.map(|i| {
thread::spawn(move || {
let mut sorteing = "The quick red fox jumps over the lazy brown \
dog... tHE QUICK RED FOX JUMPS OVER THE \
LAZY BROWN DOG!!"
[0..(i + 1) * 10]
.to_string();
let _sorteing_w = sorteing.wrap(format_args!("cool_data_{}", i));
unsafe { sorteing.as_bytes_mut() }.sort_unstable_by(|a, b| {
thread::sleep(Duration::from_millis(250));
COMPARISONS.fetch_add(1, Ordering::Relaxed);
a.cmp(b)
});
thread::sleep(Duration::from_secs(2));
})
})
.collect::<Vec<_>>();
for t in threads {
let _ = t.join();
}
}
Trait Implementations§
Auto Trait Implementations§
impl<T: ?Sized> RefUnwindSafe for Wrapper<T>where T: RefUnwindSafe,
impl<T: ?Sized> Send for Wrapper<T>where T: Send,
impl<T: ?Sized> Sync for Wrapper<T>where T: Sync,
impl<T: ?Sized> Unpin for Wrapper<T>where T: Unpin,
impl<T: ?Sized> UnwindSafe for Wrapper<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more