Closed divs1210 closed 3 years ago
What is a
? I should be a &str
, so anything formatted like "this is a &str"
.
For the rust snipped you posted the problem is that Edn::from_str
returns a type Result<Edn, EdnError>
, so there are two possibilities for this:
use edn_rs::Edn;
use std::str::FromStr;
fn main() {
let edn: Result<Edn, edn_rs::EdnError> = Edn::from_str("[1 2]");
println!("{:?}", edn);
}
or
use edn_rs::Edn;
use std::str::FromStr;
fn main() {
let edn: Edn = Edn::from_str("[1 2]").unwrap();
println!("{:?}", edn);
}
Do you understand Result
and Option
types?
I was following examples from the readme, and there is this code snippet:
let edn_str = "{:a \"2\" :b [true false] :c #{:A {:a :b} nil}}";
// std::str::FromStr
let edn: Edn = Edn::from_str(edn_str);
so I wasn't aware that Edn::from_str
would return an Option
.
Anyhow, adding .unwrap
to my code doesn't seem to have any effect.
The String::from(a)
code is not a part of my codebase, it seems to be a part of this crate which seems to be failing to build.
Basically this is my main.rs
:
use edn_rs::Edn;
use std::str::FromStr;
fn main() {
let edn: Edn = Edn::from_str("[1 2]").unwrap();
println!("{:?}", edn);
}
and this is my Cargo.toml
:
[package]
name = "native"
version = "0.1.0"
edition = "2018"
[dependencies]
edn-rs = "0.16.11"
And this is the error I get:
$ cargo run
Compiling edn-rs v0.16.12
error[E0277]: the trait bound `std::string::String: std::convert::From<char>` is not satisfied
--> /Users/divyansh/.cargo/registry/src/github.com-1ecc6299db9ec823/edn-rs-0.16.12/src/deserialize/parse.rs:119:22
|
119 | let mut symbol = String::from(a);
| ^^^^^^^^^^^^ the trait `std::convert::From<char>` is not implemented for `std::string::String`
|
= help: the following implementations were found:
<std::string::String as std::convert::From<&std::string::String>>
<std::string::String as std::convert::From<&str>>
<std::string::String as std::convert::From<std::borrow::Cow<'a, str>>>
<std::string::String as std::convert::From<std::boxed::Box<str>>>
= note: required by `std::convert::From::from`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `edn-rs`.
To learn more, run the command again with --verbose.
The same exact code for me returns Vector(Vector([UInt(1), UInt(2)]))
.
This snippet:
use edn_rs::Edn;
use std::str::FromStr;
fn main() {
let edn_str = "{:a \"2\" :b [true false] :c #{:A {:a :b} nil}}";
let edn: Edn = Edn::from_str(edn_str).unwrap();
println!("{:?}", edn);
}
returns Map(Map({":a": Str("2"), ":b": Vector(Vector([Bool(true), Bool(false)])), ":c": Set(Set({Map(Map({":a": Key(":b")})), Key(":A"), Nil}))}))
@otaviopace do you have ANY IDEA what may be happening to them?
@divs1210 Edn::from_str
returns a Result<Edn, EdnError>
, but the undated docs is on us, I will take a look at them next week. Rust analyzer can provide you with type hints. Also, the latest version is edn-rs = "0.16.12"
, that is something we need to update in the crates readme. And, the error you are getting is from the edn-rs crate src/deserialize/parse.rs:119:22
, which doesnt fail locally 🤷🏽♀️
@divs1210 What is your rustc version? I think the minimal required, as of now, is 1.46 or higher
Thanks for your help!
I had two different versions of cargo installed via homebrew and rustup.
I uninstalled the homebrew version using $ brew uninstall rust
, and updated the rustup version, and now it works fine!
Hi!
I'm new to rust, so please bear with me if I'm being stupid.
I get the following error when trying to use this crate:
This is my code for reference:
What am I doing wrong?