小编Dav*_*wie的帖子

“功能性” Rust对性能有何影响?

我遵循Exercism.io上的Rust轨道。我有大量的C / C ++经验。我喜欢Rust的“功能性”元素,但我担心相对性能。

我解决了“游程编码”问题

pub fn encode(source: &str) -> String {
    let mut retval = String::new();
    let firstchar = source.chars().next();
    let mut currentchar = match firstchar {
        Some(x) => x,
        None => return retval,
    };
    let mut currentcharcount: u32 = 0;
    for c in source.chars() {
        if c == currentchar {
            currentcharcount += 1;
        } else {
            if currentcharcount > 1 {
                retval.push_str(&currentcharcount.to_string());
            }
            retval.push(currentchar);
            currentchar = c;
            currentcharcount = 1;
        }
    }
    if currentcharcount …
Run Code Online (Sandbox Code Playgroud)

functional-programming imperative-programming rust

41
推荐指数
2
解决办法
1668
查看次数