Hi there. Once again I am swearing because of discoverability issues.
I had a pleasant couple of days developing a reader of a non-standard xml file using serde. The compiler succeeded in guiding me toward solutions, though most messages were not, ahem, familiar.
But now I am stuck. I presume this is a very old and familiar problem, discussed many times before. But Google did not help me, so..
I need to make a serializer. Page Implementing a Serializer · Serde gives an example. I pasted this in and compiled, this was the result:
error[E0432]: unresolved import `error::Error`
--> src\lib.rs:8:13
|
8 | use error::{Error, Result};
| ^^^^^ Did you mean `std::error`?
BTW, as I cursor up/dn through the fragment above, I get popups and I can NOT move the cursor until I press Escape. Even when I am selecting. This is a bad idea in code-editors, worse in a forum, where there code has little to no context. This is the second bad idea I encountered, after hijacking Ctrl+F. Seems this forum has quite a mind of its own.
The compiler says "Did you mean std::Error". Well, I don't know what I mean.. I just pasted it in. This is typical with rust examples from The Book also. They fail because of "cargo issues" (I presume).
So I change "use error::{Error, Result};" to "use std::error::{Error, Result};" (thank you std - Rust). Now I have more errors:
error[E0432]: unresolved import `std::error::Result`
--> src\lib.rs:8:25
|
8 | use std::error::{Error, Result};
| ^^^^^^ no `Result` in `error`
Well, now I add "use std::result::{Result};" and get even more errors, almost all like this:
error[E0243]: wrong number of type arguments: expected 2, found 1
--> src\lib.rs:21:35
|
21 | pub fn to_string<T>(value: &T) -> Result<String>
| ^^^^^^^^^^^^^^ expected 2 type arguments
I guess I need an IDE, so I can see where the symbol is defined.
In short the resolution of this error is non-trivial, non-discoverable. And because it is so elementary, it is shocking that a mere Error and Result, so common in The Book need
use std::error::{Error};
use std::result::{Result};
just to get started. And then it still fails. Undoubtedly I am still doing things very wrong, but if so where is the link (to be included with every example in The Book) that explains how to resolve these issues?
This is also legal:
use std::error;
use std::result;
But results in:
error[E0412]: cannot find type `Error` in this scope
--> src\lib.rs:39:18
|
39 | type Error = Error;
| ^^^^^
|
help: possible candidates are found in other modules, you can import them into scope
|
2 | use serde::de::Error;
|
2 | use serde::de::value::Error;
|
2 | use serde::export::fmt::Error;
|
2 | use serde::private::ser::Error;
|
and 3 other candidates
help: try
|
39 | type Error = Self::Error;
| ^^^^^^^^^^^
This makes it clear there are many more Error types, and I have no way of knowing what was intended, how to choose between them?
Anyway, this is not the first time I encounter non-compiling examples or downloads. It is a big drain on novices and resolving this is part of the essentials. Yet I have found nothing to guide me.