惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
S
SegmentFault 最新的问题
Engineering at Meta
Engineering at Meta
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News
博客园_首页
云风的 BLOG
云风的 BLOG
月光博客
月光博客
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
D
Docker
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
博客园 - 叶小钗
Martin Fowler
Martin Fowler
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog

KuangjuX(狂且)

提高 Directory Cache 性能 高速缓存技术(Cache) Chisel 学习笔记 随笔(一) 指令级并行技术 TLB MMU 笔记(基于 MIPS) Verilator 学习笔记 MIT-6.S081-mmap MIT-6.S081 Networking MIT-6.S081 Lazy Page Allocation MIT-6.S081 Copy on Write Fork MIT-6.S081 User Level Threads 2021年终总结 xv6-riscv中的KPTI机制 RISC -V N扩展 io_uring 阅读笔记 在Ubuntu中升级Linux内核 飞书Rust实习面试 Rust并发安全总结
Rust String 用法总结
KuangjuX · 2021-10-19 · via KuangjuX(狂且)
  • String + String -> String:
1
2
3
let s1 = "0";
let s2 = "1";
let s = format!("{}{}", s1, s2);
  • String + &str -> String:
1
2
3
let s1: &str;
let s: String;
s.push_str(s1);
  • &str + &str -> String:
1
2
3
4
let s1: &str;
let s2: &str;
let s = String::from_str(s1);
s.push_str(s2);
  • String -> &str:
1
2
3
let s: String;
let s1: &str = s.as_str();
let s2: &mut str = s.as_mut_str();
  • String -> &[u8]:
1
2
let s: String;
let s1: &[u8] = s.as_bytes();
  • String -> &mut Vec< u8 >
1
2
let s: String
let s1: &mut Vec<u8> = s.as_mut_vec();
  • &str -> String:
1
2
let s: &str;
let s1 = String::from_str(s);
  • &[u8] -> String:
1
2
3
let s: &[u8];
let s1 = String::from_utf8_lossy(s);
let s2 = String::from_utf8(s.to_vec()).unwrap();
  • Vec< u8 > -> String:
1
2
let s: Vec<u8>;
let s1 = String::from_utf8(s).unwrap();
  • 通过索引获取 String 中的 字符
1
2
let s: String;
let c = s.chars().nth(index).unwrap();
  • 遍历 String
1
2
3
4
let s: String;
for c in s.chars() {

}

Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.