-5
 ~/Workspace/microscaler/docker-api-rs on fix/linting-issues cargo clippy --all-targets --all-features -- -D clippy::all -Z macro-backtrace ✔ at 20:14:11 Checking docker-api v0.12.2 (/Users/casibbald/Workspace/microscaler/docker-api-rs) error: this `impl` can be derived --> src/opts/container.rs:50:1 | 50 | / impl Default for Isolation { 51 | | fn default() -> Self { 52 | | Isolation::Default 53 | | } 54 | | } | |_^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls = note: `-D clippy::derivable-impls` implied by `-D clippy::all` = help: remove the manual implementation... help: ...and instead derive it... | 43 | #[derive(Default)] | help: ...and mark the default variant | 45 ~ #[default] 46 ~ Default, | error: could not compile `docker-api` due to previous error warning: build failed, waiting for other jobs to finish... error: could not compile `docker-api` due to previous error 

The following help page is referred to: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls

However, adding #[derive(Default)] does not seem so straightforward when multiple items exist.

Source code here: https://github.com/microscaler/docker-api-rs/blob/d85deec98a10dcc2f6a1ed7c324010e28d437941/src/opts/container.rs#L50

The following does not work:

 Checking docker-api v0.12.2 (/Users/casibbald/Workspace/microscaler/docker-api-rs) error: no default declared --> src/opts/container.rs:41:10 | 41 | #[derive(Default, Clone, Debug, Serialize, Deserialize)] | ^^^^^^^ in this derive macro expansion | ::: /Users/casibbald/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/default.rs:186:1 | 186 | pub macro Default($item:item) { | ----------------- in this expansion of `#[derive(Default)]` | = help: make a unit variant default by placing `#[default]` above it 
3
  • 4
    What do you want? The compiler is telling you what to do. Commented Feb 2, 2023 at 18:38
  • 3
    "Source code here:" - Do not link to external code. A question should contain all of its required resources in itself. Please paste the relevant code in a code block. Commented Feb 2, 2023 at 19:03
  • Voting to close, as the time by now was long enough to provide the source code. Commented Feb 3, 2023 at 10:54

1 Answer 1

1

Read the compiler/linter messages, they tell you exactly what to do:

 = help: remove the manual implementation... help: ...and instead derive it... | 43 | #[derive(Default)] | help: ...and mark the default variant | 45 ~ #[default] 46 ~ Default, | 
 = help: make a unit variant default by placing `#[default]` above it 

Like this:

#[derive(Default, Clone, Debug)] pub enum Isolation { #[default] Default, Process, HyperV, } 
Sign up to request clarification or add additional context in comments.

3 Comments

I followed the messages, and it did not work. cargo clippy --all-targets --all-features -- -D clippy::all -Z macro-backtrace 101 х at 20:29:12 Checking docker-api v0.12.2 (/Users/microscaler/docker-api-rs) error: no default declared --> src/opts/container.rs:41:10 | 41 | #[derive(Default, Clone, Debug)] | ^^^^^^^ in this derive macro expansion | ::: /Users/casibbald/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/default.rs:186:1
Then you did it wrong. I can't help you any more than that with the information you give me.
To prove that my code works: play.rust-lang.org/… Please provide code to back up your claim that it doesn't work. In the form of a minimal reproducible example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.