Reputation: 4872
I'm having a hard time figuring out where do I need to write something to enable this feature.
I tried adding #![feature(str_split_once)]
to the file where I'm using it but nothing happens. By Googling I found How do you enable a Rust "crate feature"? but after adding
[features]
default = ["str_split_once"]
to Cargo it doesn't build with
Caused by: feature
default
includesstr_split_once
which is neither a dependency nor another feature
Upvotes: 3
Views: 5003
Reputation: 10247
I tried adding #![feature(str_split_once)] to the file where I'm using it but nothing happens.
I guess there's not really "nothing happens", but there was a warning similar to this one:
warning: crate-level attribute should be in the root module
--> src/lib.rs:2:5
|
2 | #![feature(str_split_once)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Just add this line at the beginning of lib.rs
and/or main.rs
, build with nightly, and it should work:
#![feature(str_split_once)]
fn main() {
// prints Some(("test1", "test2 test3"))
println!("{:?}", "test1 test2 test3".split_once(" "));
}
Upvotes: 3