当前位置:网站首页>How to specify const array in the global scope of rust- How to specify const array in global scope in Rust?
How to specify const array in the global scope of rust- How to specify const array in global scope in Rust?
2022-07-03 00:04:00 【Technology feast】
problem :
When I tried to add a const array in the global scope using this code: When I try to add one globally using the following code const Array time :
static NUMBERS: [i32] = [1, 2, 3, 4, 5];I got the following error: I received the following error :
error: mismatched types: expected `[i32]`, found `[i32; 5]`(expected slice, found array of 5 elements) [E0308]static NUMBERS2: [i32] = [1, 2, 3, 4, 5]; ^~~~~~~~~~~~~~~The only way I found to deal with this problem is to specify the length in the type: I found that the only way to deal with this problem is to specify the length in the type :
static NUMBERS: [i32; 5] = [1, 2, 3, 4, 5];Is there a better way? Is there a better way ?It should be possible to create an array without manually counting its elements. It should be possible to create an array without manually calculating its elements .
Solution :
Reference resources : https://stackoom.com/en/question/1bu4m边栏推荐
- Optimization of streaming media technology
- A single element in an ordered array -- Valentine's Day mental problems
- ArrayList分析2 :Itr、ListIterator以及SubList中的坑
- MFC文件操作
- MFC gets the current time
- Container runtime analysis
- MySQL基础
- 67 page overall planning and construction plan for a new smart city (download attached)
- S12. Verify multi host SSH mutual access script based on key
- VIM interval deletion note
猜你喜欢

Practical series - free commercial video material library

How to apply for company email when registering in company email format?

MySQL Foundation

Convolution和Batch normalization的融合

带角度的检测框 | 校准的深度特征用于目标检测(附实现源码)
![[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)](/img/c5/2f65d37682607aab98443d7f1ba775.jpg)
[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)

List of major chip Enterprises

JDBC practice cases
![[shutter] open the third-party shutter project](/img/1a/e35d0180612d7e79b55e7818193740.jpg)
[shutter] open the third-party shutter project

Mapper agent development
随机推荐
Convolution和Batch normalization的融合
Leetcode skimming - game 280
Explain in detail the process of realizing Chinese text classification by CNN
Returns the size of the largest binary search subtree in a binary tree
Use redis to realize self increment serial number
来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
Intranet penetration | teach you how to conduct intranet penetration hand in hand
Judge whether the binary tree is full binary tree
How to apply for company email when registering in company email format?
List of major chip Enterprises
返回二叉树两个节点间的最大距离
67 page overall planning and construction plan for a new smart city (download attached)
[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)
Writing of head and bottom components of non routing components
[ml] Li Hongyi III: gradient descent & Classification (Gaussian distribution)
基于OpenCV实现口罩识别
Linux 下安装 redis
How QT exports data to PDF files (qpdfwriter User Guide)
leetcode 650. 2 Keys Keyboard 只有两个键的键盘(中等)
Matlab 信号处理【问答笔记-1】