Some crate wanted me to pass in an AsciiString so I am trying to figure out how to create one, but so far failed horribly. Based on the commend in the source code at ascii_string.rs - source
I wrote the following:
use ascii::AsciiString;
fn main() {
let mut s = AsciiString::new();
}
rustc gives me the following error:
error[E0432]: unresolved import `ascii`
--> try.rs:1:5
|
1 | use ascii::AsciiString;
| ^^^^^
| |
| unresolved import
| help: a similar path exists: `std::ascii`
error: aborting due to previous error
So I changed the code and tried this as well:
use std::ascii::AsciiString;
fn main() {
let mut s = AsciiString::new();
}
Now I get this error:
error[E0432]: unresolved import `std::ascii::AsciiString`
--> try.rs:2:5
|
2 | use std::ascii::AsciiString;
| ^^^^^^^^^^^^^^^^^^^^^^^ no `AsciiString` in `ascii`
error: aborting due to previous error
No, the standard library has no AsciiString type. Even if it did, nothing prevents a library from creating its own AsciiString, which is what happens in this case.
Hmm, in some other languages the "standard library" contains various libraries in various names spaces.
Do I understand correctly that in Rust "standard library", only refers to things in std::* and only those come with the installation of Rust?
You might also see core and alloc being used instead of std, but they're all part of the standard library. Included with the compiler there are also the APIs for proc macros, though that's quite niche.
OK, so when people say "standard library" in Rust, do they mean only std or anything that comes with the default installation of the compiler? If I am not mistaken std - Rust says that std is the "standard library" and the others have different names. Is there some commonly used name for "all the libraries that come with the compiler" shorter than this quoted text?
I'd say that "standard library" (unless further qualified) means "anything defined in std, or reachable via std (including core and alloc)".
Edit: it's worth pointing out that std re-exports the contents of core and alloc, which is how most people use them. However, they can be used directly in cases where std is not available, or not usable for some reason.
When people are talking specifically about core or alloc, I'd expect them to be named explicitly.
The only other "comes with the compiler" library I can think of that you're supposed to use in stable Rust would be proc_macro, but I wouldn't say that's part of the "standard library". At least, not colloquially.
Std re-exports all of alloc and core, so it's the biggest set you can name and still refer to only the "standard library" (or, equivalently, the smallest set that already contains the entire standard library).