I am trying to upgrade rust code from clap v3.22.2 to v4.0.8 and faced the problem how to change Arg::multiple. This is piece of code:
Arg::new("relfs")
required(true)
multiple(true)
So I get an error
error[E0599]: no method named `multiple` found for struct `Arg` in the current scope
--> src/bin/reo.rs:178:26
|
178 | .multiple(true)
| ^^^^^^^^ method not found in `Arg`
I already tried to Arg::action as written in https://github.com/clap-rs/clap/issues/3772 but couldn't.
How can replace deprecated multiple?
Eventually changelog helped me. There is the information what has been changed and how to update.
In my case it was deprecated multiple.
Related
I have a module csv and am trying to use the external csv library (use csv::ReaderBuilder;). I am getting a conflict.
Minimal code that exhibits the error
mod csv {
use ::csv::ReaderBuilder;
}
Error message
--> src/csv.rs:4:5
|
4 | use csv::ReaderBuilder;
| ^^^ help: a similar path exists: `crate::csv`
|
= note: `use` statements changed in Rust 2018; read more at <https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html>
My question is how do I avoid such conflicts?
When creating a module, knowing the name of all modules that I may use via use seems un-reasonable. What am I doing wrong? I could name all my modules starting with my_, but this is ugly, and almost not the best solution.
Sorry if some of my terminology is wrong, I am new to rust.
You can disambiguate these where you use them. A leading crate path element indicates that the module belongs to the current crate. A leading empty path element indicates that the module belongs to the namespace root, much like a leading / character makes a filesystem path absolute.
use ::csv::Foo; // Uses Foo from the external csv crate
use crate::csv::Foo; // Uses Foo from the csv module of the current crate
It seems that I did not add the dependency to the Cargo.toml file.
On farther inspection, I see that the error message explains. However, I was confused by the help. It assumes that there is a syntax error in the use command.
In future I need to realise that the help part is a suggestion, not a description of the problem.
Can somebody tell me what is happening with the types in tonic and prost? Only a month or two ago, my team had a working build that used a protobuf definition that contained a timestamp. We're compiling them with tonic_build using well known types. Something changed with the types moving from prost 0.7 to 0.10 and now I get this error.
timestamp: Some(timestamp.into()),
^^^^ the trait `From<SystemTime>` is not implemented for `protobuf::Timestamp`
So I used a few lines to convert the type to what I thought was the correct type from the protobuf crate and then got this.
timestamp: Some(timestamp.into()),
^^^^ the trait `From<protobuf::well_known_types::Timestamp>` is not implemented for `protobuf::Timestamp`
I tried importing Timestamp from the protobuf crate, but that type doesn't exist in the root and it is apparently different from protobuf::well_known_types::Timestamp and I can't find what crate or version this type is coming from.
And then finally, if I allow tonic_build to use prost_types, I get this error instead.
timestamp: Some(timestamp.into()),
^^^^ the trait `From<protobuf::well_known_types::Timestamp>` is not implemented for `prost_types::Timestamp`
I am able to import that type, but the documentation on it is confusing, so I haven't figured out how to convert the original SystemTime into the prost_type::Timestamp.
In short, I keep looking but I can't find the correct Timestamp type. I read somewhere that having the correct versions of these crates so they line up correctly is important. Can someone help me figure out how to find the correct type and crate versions?
Thank you so much.
The conversion functionality has moved into prost-types crate.
For reference, see https://docs.rs/prost-types/0.10.1/prost_types/struct.Timestamp.html#impl-From%3CSystemTime%3E and https://github.com/tokio-rs/prost/tree/master/prost-types
timestamp: Some(prost_types::Timestamp::from(timestamp))
Recently, I've been playing with Rust and gRPC using the Tonic libraries. I started looking at how to create a custom Codec and I'm scratching my head over this...
Starting with this chunk of code, I copied the MockEncoder & MockDecoder and added all the same imports used here in the test module:
https://github.com/hyperium/tonic/blob/master/tonic/src/codec/prost.rs#L133-L158
Then I got stuck on this error:
no method named `bytes` found for mutable reference `&mut tonic::codec::DecodeBuf<'_>` in the current scope
method not found in `&mut tonic::codec::DecodeBuf<'_>`rustc(E0599)
codec.rs(55, 37): method not found in `&mut tonic::codec::DecodeBuf<'_>`
The error is complaining about let out = Vec::from(buf.bytes()); because DecodeBuf doesn't implement a bytes method.
Now, for some reason, if I wrap this code I copied in a module with #[cfg(tests)] (similar to how this originally appeared in Tonic) this error goes away. I can compile and run tests without any errors.
Curious, what is #[cfg(tests)] doing that makes buf.bytes() compile and is there something I can import in order to move MockDecoder outside of this test config?
The option is #[cfg(test)] (singular), not #[cfg(tests)] (plural). This is probably not failing because it's not being compiled or run at all, since the option is never set.
I am writing a crate that I plan to publish. When publishing, one of the most important thing (in my opinion) is to ensure the crate is well documented. Therefore my question : is there a warning to be turned on which warms undocumented sections of the code ?
E.g.: I typically think of something like #[warn(undocumented)].
Yes, such a lint exists. The rustc compiler provides the missing_docs lint, which warns about missing documentation on public items when enabled. The clippy linter provides the missing_docs_in_private_items lint, which additionally warns… well, you guessed it. Note that missing_docs_in_private_items warns for all items, so you don't need missing_docs if you enable it.
You can enable the lints using
#![warn(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]
for warnings or
#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
for errors.
You are looking for the missing-docs lint in the Rust compiler.
Example:
#![warn(missing_docs)]
fn foo(bar: i32) {}
The output from the compiler:
warning: missing documentation for crate
--> src/lib.rs:1:1
|
1 | / #![warn(missing_docs)]
2 | |
3 | | fn foo(bar: i32) {}
| |___________________^
|
You may also find more lints in the rustc book.
This question already has an answer here:
How do you enable a Rust "crate feature"?
(1 answer)
Closed 3 years ago.
Managed to build and run some of the examples in https://github.com/rustwasm/wasm-bindgen/tree/master/examples
Then started with little prototype program for Dom manipulation, things works, until stuck on this.
Use
https://docs.rs/web-sys/0.3.35/web_sys/struct.HtmlButtonElement.html
lists pub struct HtmlButtonElement, similar to
https://docs.rs/web-sys/0.3.35/web_sys/struct.Element.html and
https://docs.rs/web-sys/0.3.35/web_sys/struct.HtmlElement.html
Having:
use web_sys::Element;
use web_sys::HtmlElement;
use web_sys::HtmlButtonElement;
Gives compile error:
error[E0432]: unresolved import `web_sys::HtmlButtonElement`
--> src/lib.rs:8:5
|
8 | use web_sys::HtmlButtonElement;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `HtmlButtonElement` in the root
While Element and HtmlElement are found in web_sys
What is the difference/missing for HtmlButtonElement? Does the no HtmlButtonElement in the root message give a clue?
Following the comment by #chpio. When adding HtmlButtonElement to features in Cargo.toml HtmlButtonElement is found when building.