首页 > 其他分享 >[Rust] Arrays in Rust

[Rust] Arrays in Rust

时间:2024-02-20 22:46:43浏览次数:22  
标签:Arrays number length let type Rust

In this lesson we take a look at Arrays and the different ways of creating them. Arrays in Rust are collections of values of the same type that cannot change in size. In other words, the number of fields (or elements) has to be known at compile time.

#[allow(warnings)]

fn main() {

  let names = ["Pascal", "Christoph", "Elvira"];

  // type i8, length 4
  let numbers: [i8; 4] = [3, 2, 1, 4];

  // all values are 1, length 10, 
  let tenOnes = [1; 10];

  for number in &numbers {
    println!("{}", number);
  }
}

 

标签:Arrays,number,length,let,type,Rust
From: https://www.cnblogs.com/Answer1215/p/18024201

相关文章

  • [Rust] Vectors in Rust
    Inthislessonyou'lllearnabout Vec<T>,or Vectors.VectorsarelikeArrays,acollectionofvaluesofthesametype,butasopposedtoArrays,Vectorscanchangeinsize.#[allow(warnings)]fnmain(){letmutnumbers=vec![1,4];......
  • rust结构体包含另一个结构体引用时,serde序列化问题
    代码如下useserde::{Deserialize,Serialize};#[derive(Serialize,Deserialize)]structPerson{id:String,name:String,}#[derive(Serialize,Deserialize)]structMsg<'a>{id:String,person:&'aPerson,}fnmain(){......
  • [Rust] Integer Types in Rust
    Thislessontalksabout Integer typesinRustandthatthereare unsigned and signed integers.Italsoexplainshoweverythetypenamesarecomposedof"u"and"i",forunsignedandsignedrespectively,followedbytheir withinbits.......
  • [Rust] parse().unwrap()
    Thislessonexplains TypeInference inRustandhowitallowsthecompilertofigureoutbyitself,whattypevariableshavewhentheygettheirvaluesassigned.Therearecaseswhenthecompilercannotinferavalue'stypethroughstaticanalysis.I......
  • [Rust] Use Impl with Struct
    useanyhow::{Result,anyhow};usestd::str::FromStr;fnget_input()->&'staticstr{return"0,9->5,98,0->0,89,4->3,42,2->2,17,0->7,46,4->2,00,9->2,93,4->1,40,0->8,85,5->8,2&q......
  • 远程控制软件RustDesk自建服务器全平台部署及使用教程
    RustDesk挺出名的一款远程控制,远程协助的开源软件。完美替代TeamViewer,ToDesk,向日葵等平台。关键支持自建服务器,更安全私密远程控制电脑!其中客户端支持安卓,且支持控制安卓手机。官方地址官网:https://rustdesk.com/开源地址:https://github.com/rustdesk/一、准备工作1,有自己......
  • 教你用Rust实现Smpp协议
    本文分享自华为云社区《华为云短信服务教你用Rust实现Smpp协议》,作者:张俭。协议概述SMPP(ShortMessagePeer-to-Peer)协议起源于90年代,最初由Aldiscon公司开发,后来由SMPP开发者论坛维护和推广。SMPP常用于在SMSC(ShortMessageServiceCenter,短信中心)和短信应用之间传输短消息......
  • [Rust] Macros vs. Functions
    InRust,theexclamationmark(!)afteranameindicatesthatitisamacroratherthanafunction.MacrosandfunctionsinRustarecalleddifferentlyandservedifferentpurposes.Macros,likeanyhow!,candothingsthatfunctionscannot,suchasgenera......
  • [Rust] Error handling with Enum
    Wecanuse ReusltenumtodoerrorhandlingtypeResult<V,E>{Err(E),Ok(V)} Example://():empty//uszie:justreturnaintegreaserrorfordemofnerror_me(throw:bool)->Result<(),usize>{ifthrow{returnEr......
  • Rust程序设计 第2版 电子书 pdf
    关注公众号:红宸笑。回复:电子书即可   本书是Rust领域经典参考书,由业内资深系统程序员编写,广受读者好评。书中全面介绍了Rust这种新型系统编程语言——具有无与伦比的安全性,兼具C和C++的高性能,并大大简化了并发程序的编写。第2版对上一版内容进行了重组和完善,新增了对......