Struct febug::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)
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();
    }
}
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: ?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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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