Skip to content

[feat] Implement Debug for tauri::State #3676

@mihirsamdarshi

Description

@mihirsamdarshi

Describe the problem

I am writing an application, and I would like to add the #[instrument] macro from the tracing crate (as well as Sentry) to some of my tauri::commands.

However in order to do that, for some of my commands which access state, I am receiving the following error, which states that tauri::State does not implement Debug

error[E0277]: `tauri::State<'_, state::InfraState>` doesn't implement `std::fmt::Debug`
   --> src/ssh/port_forward.rs:722:1
    |
722 | #[instrument]
    | ^^^^^^^^^^^^^ `tauri::State<'_, state::InfraState>` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
    |
    = help: the trait `std::fmt::Debug` is not implemented for `tauri::State<'_, state::InfraState>`
    = note: required because of the requirements on the impl of `std::fmt::Debug` for `&tauri::State<'_, state::InfraState>`
note: required by a bound in `tracing::field::debug

Describe the solution you'd like

Implement Debug for tauri::State

Please let me know what method works the best, I was thinking that you could utilize the inner method of State

impl<T: Send + Sync + Debug + 'static> Debug for State<'_, T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!("tauri::State \{ {} \}", self.inner().fmt())
    }
}

Alternatives considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions