学习Rust的第8天:Slicing

Slices in Rust allow us to reference contiguous sequences of elements in collections, offering more granular control over data manipulation. We explored how to create slices using array and string literals, understanding the range syntax and its exclusivity.

Rust中的切片允许我们引用集合中连续的元素序列,从而对数据操作提供更细粒度的控制。我们探讨了如何使用数组和字符串字面量创建切片,了解范围语法及其排他性。

Introduction 介绍

In rust, Slices allow you to refer to a contiguous sequence of elements in a collection of items, rather than the whole collection.
在rust中,Slices允许你引用一个项目集合中的一个连续的元素序列,而不是整个集合。

let numbers = [1, 2, 3, 4, 5];
let slice = &numbers[1..4]; // [2, 3, 4]
  • [1..4] starts at index 1 and ends at 3. 4 is exclusive.
    [1..4] 开始于索引1,结束于索引3。四是排他性。
  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老父亲的能量嘎嘣脆

感谢支持,共同成长

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值