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

[Rust] Vectors in Rust

时间:2024-02-20 22:46:13浏览次数:17  
标签:Vectors number Vec push Rust numbers

In this lesson you'll learn about Vec<T>, or Vectors. Vectors are like Arrays, a collection of values of the same type, but as opposed to Arrays, Vectors can change in size.

#[allow(warnings)]

fn main() {
    let mut numbers = vec![1, 4];
    numbers.push(3);
    numbers.push(2);
    
    for number in &numbers {
        println!("{}", number)
    }
}

 

Another way to create Vector:

let mut numbers = Vec::new();
numbers.push(1);
numbers.push(2);

 

标签:Vectors,number,Vec,push,Rust,numbers
From: https://www.cnblogs.com/Answer1215/p/18024206

相关文章

  • 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版对上一版内容进行了重组和完善,新增了对......
  • [Rust] Intro Enum
    GoEnumpackagemaintypeGoEnum=intconst(FooGoEnum=iotaBarBaz)funcmain(){} TypescriptEnumenumTsEnum{Foo,Bar,Baz} RustEnumenumRsEnum{Foo,Bar,Baz}Whygooverenums...Theyaresimple......