How do I print a struct when the type doesn’t implement Debug or Display?

⚓ Rust    📅 2025-10-03    👤 surdeus    👁️ 6      

surdeus

Hi, I’m new to Rust. I have a struct that contains a field from another module/crate. For example:

struct Subscription {
    status: SubscriptionInfo, // this type comes from another module
    loading: bool,
}

The problem is that SubscriptionInfo does not implement the Debug or Display traits. Because of that, I can’t use println!("{:?}", ...) or println!("{}", ...) on Subscription even if i add the derive attribute above Subscription.

What’s the recommended way to print if I can’t modify the definition of SubscriptionInfo?

3 posts - 2 participants

Read full topic

🏷️ Rust_feed