A newtype wrapper that causes Debug impls to skip a field.

Overview

debug-ignore

debug-ignore on crates.io Documentation (latest release) Documentation (main) License License

This library contains DebugIgnore, a newtype wrapper that causes a field to be skipped while printing out Debug output.

Examples

use debug_ignore::DebugIgnore;

// Some structs have many fields with large `Debug` implementations.
#[derive(Debug)]
struct InnerStructWithLotsOfDebugInfo {
    field: &'static str,
    // ...
}

#[derive(Debug)]
pub struct PublicStruct {
    inner: DebugIgnore<InnerStructWithLotsOfDebugInfo>,
}

impl PublicStruct {
    pub fn new() -> Self {
        Self {
            inner: DebugIgnore(InnerStructWithLotsOfDebugInfo { field: "field", /* ... */ })
        }
    }
}

let x = PublicStruct::new();
assert_eq!(format!("{:?}", x), "PublicStruct { inner: ... }");

// Fields within inner can still be accessed through the Deref impl.
assert_eq!(x.inner.field, "field");

Why?

Some structs have many fields with large Debug implementations. It can be really annoying to go through a ton of usually irrelevant Debug output.

DebugIgnore is a zero-cost, zero-compile-time way to achieve a Debug impl that skips over a field.

Optional features

serde: serde support with #[serde(transparent)].

Rust version support

The MSRV is Rust 1.34 though this crate likely builds with older versions. This crate is too trivial to require anything more recent.

Optional features may require newer versions of Rust.

Alternatives

  • Implement Debug by hand.
  • derivative has greater control over the behavior of Debug impls, at the cost of a compile-time proc-macro dependency.

Contributing

Pull requests are welcome! Please follow the code of conduct.

License

This project is available under the terms of either the Apache 2.0 license or the MIT license.

You might also like...
🌌⭐cosmo is a wrapper for Git essentially, allowing you to compress multiple commands into one
🌌⭐cosmo is a wrapper for Git essentially, allowing you to compress multiple commands into one

❯ Cosmo Git tooling of the future New feature: Cosmo hooks! Click here for more info! ❯ 👀 Features Config files (with defaults!) Fast Easy to use Fri

Command line wrapper of the DeepL API

deeprs - A command line wrapper of DeepL API About deeprs is a command line wrapper of the DeepL translator API. To use it you need a API key which yo

Wrapper around atspi-code to provide higher-level at-spi Rust bindings

atspi Wrapper around atspi-codegen to provide higher-level at-spi Rust bindings. Contributions Take a look at our atspi-codegen crate, and try inpleme

Shared memory - A Rust wrapper around native shared memory for Linux and Windows

shared_memory A crate that allows you to share memory between processes. This crate provides lightweight wrappers around shared memory APIs in an OS a

Idiomatic inotify wrapper for the Rust programming language

inotify-rs Idiomatic inotify wrapper for the Rust programming language. extern crate inotify; use std::env; use inotify::{ EventMask, Watch

🐎 A fast implementation of the Aho-Corasick algorithm using the compact double-array data structure. (Python wrapper for daachorse)

python-daachorse daachorse is a fast implementation of the Aho-Corasick algorithm using the compact double-array data structure. This is a Python wrap

A wrapper around the code action dump from https://mcdiamondfire.com.

DiamondFire Action Dump for Rust A wrapper around the code action dump from https://mcdiamondfire.com. This currently only provides schema types for u

Rust wrapper for gphoto2 (mirror of https://git.maxicarlos.de/maxicarlos08/gphoto2-rs)

GPhoto2-rs Rust bindings to libgphoto2 What about gphoto-rs? I know about the other crate (gphoto and gphoto2-sys which was created by @dcuddeback, bu

Plain Rust wrapper of Ableton Link's C 11 extension

rusty_link rusty_link is a Rust wrapper of abl_link, which is a C 11 extension for Ableton Link, provided by Ableton. This library attempts to be most

Comments
  • Introduce no_std compatibility

    Introduce no_std compatibility

    This crate is currently incompatibility with microcontrollers, as it isn't no_std.

    It doesn't use a single feature of std though, so this PR introduces no_std compatibility.

    opened by Finomnis 2
  • Add From to easier create the wrapped object

    Add From to easier create the wrapped object

    Currently:

    #[derive(Debug)]
    pub struct PublicStruct {
        inner: DebugIgnore<InnerStructWithLotsOfDebugInfo>,
    }
    
    impl PublicStruct {
        pub fn new() -> Self {
            Self {
                inner: DebugIgnore(InnerStructWithLotsOfDebugInfo { field: "field", /* ... */ })
            }
        }
    }
    

    If From is implemented, it will allow to call .into(), similar to what Option has:

    impl PublicStruct {
        pub fn new() -> Self {
            Self {
    -            inner: DebugIgnore(InnerStructWithLotsOfDebugInfo { field: "field", /* ... */ })
    +            inner: InnerStructWithLotsOfDebugInfo { field: "field", /* ... */ }.into()
            }
        }
    }
    
    
    opened by pravic 1
Releases(1.0.3)
Owner
Rain
they/she
Rain
Easy access of struct fields in strings using different/custom pre/postfix: "Hello, {field}" in rust

Easy access to struct fields in strings ?? add strung to the dependencies in the Cargo.toml: [dependencies] strung = "0.1.3" ?? use/import everything

Dekirisu 2 Sep 19, 2022
Statically verified Rust struct field names as strings.

field Statically verified struct field names as strings. See the documentation for more details. Installation Add the following to your Cargo manifest

Indraneel Mahendrakumar 3 Jul 9, 2023
`nm` and `addr2line` but for DI "debug-info" COFF files

Summary This is a very simple tool that prints out function, global, and source line information from a .dbg "DI" COFF debug file. This can handle bot

null 7 Dec 18, 2022
A TUI front-end for the Debug Adapter Protocol.

Pesticide A TUI front-end for the Debug Adapter Protocol. Motivation I am an avid kakoune user. Kak is a very niche text editor with few users. As suc

raiguard 6 Jun 17, 2022
Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux.

Load Symbols Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux. Requirements Last tested wi

null 4 Jul 20, 2022
Downloads and provides debug symbols and source code for nix derivations to gdb and other debuginfod-capable debuggers as needed.

nixseparatedebuginfod Downloads and provides debug symbols and source code for nix derivations to gdb and other debuginfod-capable debuggers as needed

Guillaume Girol 16 Mar 6, 2023
A low-level ncurses wrapper for Rust

ncurses-rs This is a very thin wrapper around the ncurses TUI lib. NOTE: The ncurses lib is terribly unsafe and ncurses-rs is only the lightest wrappe

Jeaye Wilkerson 628 Jan 7, 2023
ddi is a wrapper for dd. It takes all the same arguments, and all it really does is call dd in the background

ddi A safer dd Introduction If you ever used dd, the GNU coreutil that lets you copy data from one file to another, then you may have encountered a ty

Tomás Ralph 80 Sep 8, 2022
A small CLI wrapper for authenticating with SSH keys from Hashicorp Vault

vaultssh A small CLI wrapper for authenticating with SSH keys from Hashicorp Vault vaultssh is a small CLI wrapper for automatically fetching and usin

Joshua Gilman 50 Dec 10, 2022
argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

argmax argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper w

David Peter 22 Nov 20, 2022