Creating an AsciiString

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 - 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`
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`
2 | use std::ascii::AsciiString;
  |     ^^^^^^^^^^^^^^^^^^^^^^^ no `AsciiString` in `ascii`

error: aborting due to previous error

What am I missing here?

Did you add ascii as a dependency in your Cargo.toml?

1 Like

No, but isn't it in the std library? Shouldn't it come with Rust?

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.


The documentation that you linked to yourself points to the 3rd-party ascii crate. hosts documentation of 3rd-party crates.

If you want to look at std's docs, then use std - Rust or


Does everything on come from crates? I thought it contains both crates and standard library.

Well, there is a working link std - Rust (and similarly for core and alloc), which redirects to std - Rust.

1 Like

But you explicitly linked to the ascii crate. Not to std or core.

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?

Correct. The standard library is what's in the std::* path.

1 Like


The standard library has submodules, too. Std is the top-level crate name.

1 Like

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).


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.