如何在不需要包装器类型的情况下反序列化 JSON 数组?

How do I deserialize a JSON array without needing a wrapper type?

我想反序列化以下 JSON:

[
  {
    "name": "one",
    "path": "/path/to/one"
  },
  {
    "name": "two",
    "path": "/path/to/two"
  },
  {
    "name": "three",
    "path": "/path/to/three"
  }
]

变成了Vec<Worskpace>Workspace定义如下:

#[derive(Serialize, Deserialize)]
struct Workspace {
    name: String,
    path: String,
}

有没有办法做到这一点而不必做类似的事情:

#[derive(Serialize, Deserialize)]
struct Workspacesss {
    values: Vec<Workspace>,
}

直接反序列化向量即可:

let workspaces = serde_json::from_str::<Vec<Workspace>>(input);