有没有办法初始化一个空切片?

时间:2017-08-06 15:42:49

标签: arrays rust slice

这样的东西?

Table '_fact'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

[String, 0] 不是一种选择。

1 个答案:

答案 0 :(得分:3)

这会创建一个空数组:

let thing: [String; 0] = [];

您还可以从数组中获取切片:

let thing: &[String] = &[];

您还可以使用as

some_function([] as [String; 0]);
some_function(&[] as &[String]);