Debug for libc structs

Hi there! I have some struct that have Debug formating:

struct ... {
sembuf: libc::sembuf,

But i got an error:

sembuf cannot be formatted using {:?} because it doesn't implement Debug.

If i implement Debug for libc::sembuf i got another error:

impl doesn't use only types from inside the current crate

Simple implematation:

impl fmt::Debug for libc::sembuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, {}", self.sem_num)

Please, help. How can i resolve this problem? Because I need debug information for a number of structures that borrow each other in fields.

It is not possible to implement a 3rd-party trait for a 3rd-party type (because then either one could have a conflicting implementation with yours).

Why don't you implement Debug directly on your own struct? Then you can control how to format each individual field, even when some of them isn't Debug.

I didn't think of it before, thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.