gpt4 book ai didi

rust - 如何启用不稳定的 Rust 功能 str_split_once?

转载 作者:行者123 更新时间:2023-12-03 11:43:53 25 4
gpt4 key购买 nike

我很难弄清楚我需要在哪里写一些东西来启用这个功能。

我尝试将 #![feature(str_split_once)] 添加到我正在使用它的文件中,但没有任何反应。通过谷歌搜索我找到了How do you enable a Rust "crate feature"?但添加后

[features]
default = ["str_split_once"]

Cargo 不是用它构建的

Caused by: feature default includes str_split_once which isneither a dependency nor another feature

最佳答案

I tried adding #![feature(str_split_once)] to the file where I'm using it but nothing happens.

我想这并不是真的“什么都没发生”,但是有一个类似于这个的警告:

warning: crate-level attribute should be in the root module
--> src/lib.rs:2:5
|
2 | #![feature(str_split_once)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Playground

只需在 lib.rs 和/或 main.rs 的开头添加这一行,使用 nightly 构建,它应该可以工作:

#![feature(str_split_once)]

fn main() {
// prints Some(("test1", "test2 test3"))
println!("{:?}", "test1 test2 test3".split_once(" "));
}

Playground

关于rust - 如何启用不稳定的 Rust 功能 str_split_once?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66261355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com