当前位置:网站首页>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边栏推荐
- [shutter] shutter open source project reference
- JDBC練習案例
- Why can't the start method be called repeatedly? But the run method can?
- Develop knowledge points
- 返回二叉树中最大的二叉搜索子树的大小
- 程序分析与优化 - 9 附录 XLA的缓冲区指派
- 【OJ】两个数组的交集(set、哈希映射 ...)
- leetcode 650. 2 keys keyboard with only two keys (medium)
- Use of cocospods
- Many to one, one to many processing
猜你喜欢

I've been interviewed. The starting salary is 16K

JDBC Exercise case

Convolution和Batch normalization的融合

Open source | Wenxin big model Ernie tiny lightweight technology, which is accurate and fast, and the effect is fully open

程序分析与优化 - 9 附录 XLA的缓冲区指派

35页危化品安全管理平台解决方案2022版
![[Verilog tutorial]](/img/15/d5e188a15e22fa44f1756fc492099d.jpg)
[Verilog tutorial]

Intranet penetration | teach you how to conduct intranet penetration hand in hand
![MATLAB signal processing [Q & a notes-1]](/img/53/ae081820fe81ce28e1f04914678a6f.png)
MATLAB signal processing [Q & a notes-1]

Implementation of VGA protocol based on FPGA
随机推荐
MFC gets the current time
The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
判断二叉树是否为满二叉树
JDBC教程
CADD course learning (4) -- obtaining proteins without crystal structure (Swiss model)
2022 latest and complete interview questions for software testing
Writing of head and bottom components of non routing components
Speech recognition Series 1: speech recognition overview
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
Interface automation coverage statistics - used by Jacobo
Mapper代理开发
Analyze ad654: Marketing Analytics
Highly available cluster (HAC)
leetcode 650. 2 Keys Keyboard 只有两个键的键盘(中等)
[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)
Explain in detail the process of realizing Chinese text classification by CNN
JDBC Exercise case
Data set - fault diagnosis: various data and data description of bearings of Western Reserve University
Returns the root node of the largest binary search subtree in a binary tree
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)