Struct Wrapper

Source
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>

Source

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)
18fn main() {
19    febug::start();
20    if febug::install_handler() {
21        // Normal registration by TypeId, variables use .wrap(...)
22        let mut fmt = febug::FORMATTERS.lock().unwrap();
23        fmt.insert(TypeId::of::<String>().into(), |of, vid| {
24            let data = unsafe { &*(vid as *const String) };
25
26            let _ = of.write_all(data.as_bytes());
27            let _ = of.write_all(b"\n");
28        });
29
30        // Custom registration with an explicit type number and Wrapper::new()
31        fmt.insert(0.into(), |of: &mut File, _| {
32            let _ = write!(of, "{}\n", COMPARISONS.load(Ordering::Relaxed));
33        });
34    }
35
36    let _comparisons_wrapper = Wrapper::new(0, &COMPARISONS, format_args!("comparisons"));
37
38
39    let threads = (0..10)
40        .map(|i| {
41            thread::spawn(move || {
42                let mut sorteing = "The quick red fox jumps over the lazy brown \
43                                    dog... tHE QUICK RED FOX JUMPS OVER THE \
44                                    LAZY BROWN DOG!!"
45                                       [0..(i + 1) * 10]
46                    .to_string();
47                let _sorteing_w = sorteing.wrap(format_args!("cool_data_{}", i));
48
49                unsafe { sorteing.as_bytes_mut() }.sort_unstable_by(|a, b| {
50                    thread::sleep(Duration::from_millis(250));
51                    COMPARISONS.fetch_add(1, Ordering::Relaxed);
52                    a.cmp(b)
53                });
54
55                thread::sleep(Duration::from_secs(2));
56            })
57        })
58        .collect::<Vec<_>>();
59    for t in threads {
60        let _ = t.join();
61    }
62}
Source

pub fn new_signal( tp: u64, data: &T, signal: u8, name: Arguments<'_>, ) -> Wrapper<T>

Register the specified variable of the specified type with the specified name to be notified (if not SIGKILL) on the specified signal to format it

Trait Implementations§

Source§

impl<T: ?Sized> Drop for Wrapper<T>

Source§

fn drop(&mut self)

Deregister the variable

Auto Trait Implementations§

§

impl<T> Freeze for Wrapper<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for Wrapper<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for Wrapper<T>
where T: Send + ?Sized,

§

impl<T> Sync for Wrapper<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for Wrapper<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for Wrapper<T>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> StaticWrappable for T
where T: 'static + ?Sized,

Source§

fn wrap(&self, name: Arguments<'_>) -> Wrapper<T>

Source§

fn wrap_signal(&self, signal: u8, name: Arguments<'_>) -> Wrapper<T>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Wrappable for T
where T: ?Sized,

Source§

fn wrap_type(&self, tp: u64, name: Arguments<'_>) -> Wrapper<T>

Source§

fn wrap_type_signal( &self, tp: u64, signal: u8, name: Arguments<'_>, ) -> Wrapper<T>