小编神楽坂*_*坂深海的帖子

为什么PowerShell会自动展平数组?

我写了一些pwsh代码

"a:b;c:d;e:f".Split(";") | ForEach-Object { $_.Split(":") }
# => @(a, b, c, d, e, f)
Run Code Online (Sandbox Code Playgroud)

但是我想要这个

// in javascript
"a:b;c:d;e:f".split(";").map(str => str.split(":"))
[ [ 'a', 'b' ], [ 'c', 'd' ], [ 'e', 'f' ] ]
Run Code Online (Sandbox Code Playgroud)

嵌套数组

@(
    @(a, b),
    @(c, d),
    @(e, f),
)
Run Code Online (Sandbox Code Playgroud)

为什么?那我该怎么办

arrays powershell pipeline jagged-arrays

4
推荐指数
1
解决办法
92
查看次数

Rust 在取消引用时会自动实现克隆吗?

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

impl Copy for Point {}

impl Clone for Point {
    fn clone(&self) -> Point {
        *self
    }
}
Run Code Online (Sandbox Code Playgroud)

当我只实现时Copy,Rust 告诉我需要实现Clone。当我只实现时Clone,Rust 告诉我Point可以移动。

我的问题是,我从来没有实现过任何东西,这段代码有点像循环依赖,但它有效吗?为什么?

rust

4
推荐指数
1
解决办法
2986
查看次数

标签 统计

arrays ×1

jagged-arrays ×1

pipeline ×1

powershell ×1

rust ×1