Amanieu / cstr_core

Implementation of CStr and CString for no_std environments
Apache License 2.0
41 stars 17 forks source link

Unable to import CString #10

Closed darleybarreto closed 4 years ago

darleybarreto commented 4 years ago

I am new to rust and I might be doing something wrong, but the following code

use cstr_core::{CString, CStr, c_char};

gives this error (which is weird because I can import the other two)

error[E0432]: unresolved import `cstr_core::CString`
 --> src/lib.rs:1:17
  |
1 | use cstr_core::{CString, CStr, c_char};
  |                 ^^^^^^^ no `CString` in the root

warning: unused imports: `CStr`, `c_char`
 --> src/lib.rs:1:26
  |
1 | use cstr_core::{CString, CStr, c_char};
  |                          ^^^^  ^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0432`.
error: could not compile `rust-strings`.

To learn more, run the command again with --verbose.
Amanieu commented 4 years ago

You need to enable the "alloc" feature when specifying the dependency in Cargo.toml.

darleybarreto commented 4 years ago

I see, so I need to use a crate to perform allocation for me, right? Or can I somehow import the one from std?

Amanieu commented 4 years ago

Use this line in Cargo.toml:

cstr_core = { version = "0.2.0", features = ["alloc"] }
darleybarreto commented 4 years ago

Thank you!