我写了一些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)
为什么?那我该怎么办
#[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可以移动。
我的问题是,我从来没有实现过任何东西,这段代码有点像循环依赖,但它有效吗?为什么?