4、Rust编程基础:字符串、条件语句、循环与自定义类型

Rust编程基础:字符串、条件语句、循环与自定义类型

1. 字符串

在任何编程语言中,字符串都是最常用的数据类型之一。在Rust里,字符串通常有两种形式: &str 类型(发音为 “stir”)和 String 类型。Rust的字符串保证是有效的UTF - 8编码字节序列,它们不像C字符串那样以空字符结尾,并且字符串中间可以包含空字节。

以下是展示这两种类型用法的代码示例:

// strings.rs
fn main() {
    let question = "How are you ?";            // a &str type
    let person: String = "Bob".to_string();
    let namaste = String::from("नमˑे");        // unicodes yay!
    println!("{}! {} {}", namaste, question, person);
}

在上述代码中, person 和 namaste 是 String 类型,而 question 是 &str 类型。创建 String 类型有多种方式。字符串存储在堆上,而 &str 类型通常是指向现有字符串的指针,这个现有

相关推荐

【Rust UDP编程】rust udp编程方法解析与应用实战

Rust标准库通过std::net模块提供了UDP网络编程支持,主要类型包括: UdpSocket:UDP套接字的主要类型 SocketAddr:表示IP地址和端口号的组合

景天科技苑 4万+

5、Rust编程基础:循环、函数、元组与数组

本文介绍了Rust编程的基础知识,包括条件表达式的类型一致性、三种循环(loop、while、for)的使用、函数的定义与调用、注释的使用、元组和数组的基本操作。通过这些内容的学习,读者可以掌握Rust语言的基本特性,并编写安全高效的代码。

a3b4c5的博客 87

4、Rust 编程基础:常见概念与操作

本博客详细介绍了 Rust 编程的基础知识,包括数组索引的安全检查机制、常量与变量的声明和区别、字符串类型的分类及常用操作方法、Rust 中的各类运算符以及决策语句的使用。通过丰富的代码示例,帮助开发者快速掌握 Rust 的基本语法和核心概念,为进一步学习所有权、生命周期等高级特性打下坚实基础。

a3b4c5的博客 66

微信小游戏马甲包过审策略

微信小游戏马甲包是指同一套游戏源码使用不同的名字包装上线微信小游戏平台。微信官方是不允许这样的方式上线小游戏,但是游戏运营方为了买量的需求,往往采用不同包装来,以获取更多流量。另外游戏发行以后,多家联运渠道都需要上线同一款小游戏,也存在马甲包的情况。 如果马甲包游戏源码上传时没有经过特殊处理,就会打回小游戏内容涉嫌代码包内容侵权,同时信用分-5(信用分越低,提审时间越长,一般保持在90分及以上才能保证快速审核)。微信官方回复结果如下: 目前,微信小游戏审核相比苹果商店审核还不算严格,基本上能突破代码

aqi22221的博客 4550

W5500 TCP服务器状态机详解:从SOCK_CLOSED到SOCK_ESTABLISHED的完整流程

本文深入解析W5500芯片作为TCP服务器时的状态机转换流程,从SOCK_CLOSED到SOCK_ESTABLISHED的完整链路实践。通过硬件协议栈架构分析、状态机全流程拆解及异常处理方案,帮助开发者构建高可靠性的嵌入式网络服务端,优化TCP连接性能与稳定性。

Jerry的专栏 1175

手把手教你设计2bit反射型超表面:从单patch扫参到pin管配置全流程

本文提供了一份2bit反射型超表面设计的完整工程实践指南。从单贴片谐振器的参数化扫描与“270度法则”应用,到PIN二极管等效电路模型的获取与集成,再到利用参数化扫描高效仿真四种工作状态,手把手指导读者完成从单元设计到阵列布局、偏置线集成及加工考量的全流程,旨在帮助射频工程师将概念转化为可加工测试的实体模型。

java5的博客 1034

面试复习题--RN面试

考察点:热更新方案的深度理解,选型能力,实战落地经验。答题思路主流热更新方案对比。

hqiangtai的博客 756

论文解读--Phase Noise in FMCW Radar Systems

相位噪声是现代雷达、通信、光谱和计量系统的基本性能参数之一。本文提出了一种适用于FMCW雷达系统的相位噪声理论。导出了一个新的设计方程,用于确定雷达系统中允许的源相位噪声电平的最大界。分析了在传输延迟小于参考振荡器相干时间时,相干混频引起的非线性相位噪声去相关函数;讨论了在传输延迟大于参考振荡器相干时间时,目标响应的频谱展宽。提出了收发链中各子系统的影响,并讨论了一种新的ADC相位噪声模型。介绍了相位噪声建模技术,然后将锁相环频率合成器与低噪声频率合成器进行比较,以演示减少相位噪声边带以改善检测和跟踪性能。

奔袭的算法工程师 3783

Dell T7910工作站LSISAS3008IR RAID配置全流程:从零到实战避坑指南

本文提供了Dell Precision T7910工作站集成LSISAS3008IR RAID控制器的完整配置与避坑指南。详细拆解了从固件版本确认、安全更新到创建RAID 0阵列的全流程,并重点预警了固件与UEFI安全启动冲突等常见陷阱,帮助用户高效、稳定地部署存储系统。

qq_27496129的博客 1096

Python爬虫实战:高效爬取华尔街日报文章的技术与代码详解

在当今信息爆炸的时代,金融数据和分析对于投资者、研究人员和企业决策者来说至关重要。华尔街日报(WSJ)作为全球最具影响力的财经媒体之一,其文章内容具有极高的价值。本文将详细介绍如何使用Python最新技术构建一个高效、稳定的华尔街日报文章爬虫,涵盖从基础到高级的各种技术要点。本文详细介绍了如何使用Python最新技术构建一个高效、稳定的华尔街日报文章爬虫。我们从基础爬虫实现开始,逐步添加了高级功能如分布式处理、反反爬虫策略、数据清洗和存储等。异步处理:使用asyncio和httpx实现高性能网络请求。

2201_76125261的博客 389

CSDN独家首发!万字长文,YOLOv5/v7/v8算法模型yaml文件史上最详细解析与教程!小白也能看懂!掌握了这个就掌握了魔改YOLO的核心!

🍀🍀🍀YOLOv5/v7/v8算法模型yaml文件史上最详细解析与教程,全网最强,学不会算我输!!!

Coding... 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

上一篇: 3、Rust编程入门:安装、基础语法与特性解析
下一篇: 36、物理刺激在中枢神经系统组织工程中的应用
普通网友
博客等级 码龄27年 205粉丝 1502原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址