Having trouble using features to import "Serde" from the slog library

I'm having trouble with importing a struct that is behind a feature flag.

I'm trying to use the Serde unit struct in slog in order to log things that are serde serializable. The problem is, I can't seem to import the Serde struct, even with the nested-values feature enabled.

I get the error

error[E0425]: cannot find function, tuple struct or tuple variant `Serde` in crate `slog`
  --> src/main.rs:44:42
   |
44 |     info!(log, "test"; "output" => slog::Serde(output));
   |                                          ^^^^^ not found in `slog`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `slog-serde-example` (bin "slog-serde-example") due to previous error

I've imported slog using

slog = { version = "2.7", features = ["nested-values"] }

which seems sufficient, given the struct is simply defined by

#[cfg(feature = "nested-values")]
#[derive(Clone, serde_derive::Serialize)]
pub struct Serde<T>(pub T)
where
    T: serde::Serialize + Clone + Send + 'static;

You can see an example here GitHub - Paul-E/slog-serde-example

I'm able to import/see the SerdeValue, a trait which is also behind the nested-values flag, so it seems like the feature flag is working. Additionally, the fact that the struct doesn't show up in the generated docs makes me thinks something is going on in the slog crate.

Is anyone able to spot why Serde in slog can't be imported?

Looks like it isn’t part of the version 2.7. You could try 2.8.0-beta.1.

2 Likes

Ah, yep that is it. That is the rather obvious answer.

Thank you!

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.