Is there a way to initialize an empty slice?

笑着哭i 提交于 2020-11-28 07:02:07

问题


Something like this?

[String, 0]

Vec::new() is not an option.


回答1:


This creates an empty array:

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

You can also get a slice from the array:

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

You can also use as:

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


来源:https://stackoverflow.com/questions/45533699/is-there-a-way-to-initialize-an-empty-slice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!