我有一个csv格式的文件,第一列数据表示项目代码,可选择以"UNIUNI"这些字符结尾或混合使用,通过条形码阅读器加载.我需要削减最后一个"UNI"s.
在Rust中,我尝试用部分成功编写一个基本上像这样的函数:
fn main() {
// Ok: from "9846UNIUNI" to "9846"
println!("{}", read_csv_rilev("9846UNIUNI".to_string()));
// Wrong: from "9846uniuni" to "9846"
println!("{}", read_csv_rilev("9846uniuni".to_string()));
}
fn read_csv_rilev(code: String) -> String {
code
//.to_uppercase() /*Unstable feature in Rust 1.1*/
.trim_right_matches("UNI")
.to_string()
}
Run Code Online (Sandbox Code Playgroud)
理想的功能签名如下:
fn read_csv_rilev(mut s: &String) {/**/}
Run Code Online (Sandbox Code Playgroud)
但可能对String的就地动作不是一个好主意.实际上,在Rust标准库中没有任何可以做到的事情String::pop().
有没有办法在String上应用修剪而不分配另一个?
我希望与Rust专家验证这个简单的Rust程序(在Linux x86-64系统上每晚生成0.13.0):
/*
the runtime error is:
task '<main>' has overflowed its stack
Illegal instruction (core dumped)
*/
fn main() {
let l = [0u, ..1_000_000u];
}
Run Code Online (Sandbox Code Playgroud)
编译过程完美结束,没有错误,但在运行时程序失败,代码注释中显示错误.
Rust中固定大小数组的维度是否有限制,或者这是编译器中某处的错误?