Golang 中只有一个 string类型,对应字符串。
string是所有8位字节的字符串的集合,通常但不一定代表UTF-8编码的文本。一个字符串可以是空的,但不能是零。字符串类型的值是不可改变的。
Rust 中有三个类型 str ,&str ,String 来对应处理字符串。
str类型,也被称为 “字符串切片”,是最原始的字符串类型。它通常以其借用的形式出现,即&str。它也是字符串字面的类型,&’static str。字符串切片总是有效的UTF-8。
&str类型是两个主要的字符串类型之一,另一个是String。与其对应的String不同,它的内容是借用的。
String类型是一个UTF-8编码的、可增长的字符串。
String类型是最常见的字符串类型,它对字符串的内容有所有权。它与它的借来的对应物,即原始的str,有着密切的关系。
Golang中字符串只用stirng处理,实际存储的是byte数组。type byte = uint8,也就是uint8数组不可变。要对字符串做遍历直接就可以用索引。如果要变更长度,需要使用strings包的Split,Join等函数修改并返回一个新的字符串。
Rust中字符串是str,实际存储的是u8数组不可变,以&str获取u8数组的切片来访问,遍历。要对字符串做增长修改操作,需要转换成String处理。
Golang中对字符串的拆分,组合字符串,通过包strings处理。Rust中通过把字符串转成String实际是pub struct String { vec: Vec
,}结构,是一个处理字符串的对象,它附带了很多处理字符串的方法函数。但是它不是字符串。Rust的String对象等价于Go中的包strings。
(作为一个Golang开发者学习Rust,非常容易把Rust的String 等价于 Golang中的string 这是个错误。)
Rust中对String的说明太让人难以理解了:
原文:
A UTF-8–encoded, growable string.
The String type is the most common string type that has ownership over the contents of the string. It has a close relationship with its borrowed counterpart, the primitive str.
建议应该改成
An object that performs growth processing on UTF-8 encoded strings.
The String object is the most common set of string growth processing methods, and it has ownership over the content of the string. It has a close relationship with its borrowed counterpart, the original str. It can do splitting, combining, and growing of strings to return a new string.
通过代码比较更容易理解Golang和Rust对字符串处理的差异。代码如下:
package main |
output:
Hello, 世界 |
fn main() { |
output:
Hello, 世界 |
I learned that languages is more than syllables and rhymes.
我得知,语言不仅仅是音节和韵律。
It is a tool for communication.
它是一种沟通的工具。
It connects people,bridges different cultures and brings heart and minds closer.
它将人们联系在一起,为不同的文化架起桥梁,拉近了心灵和思想的距离。
As Chinese, we speak English to make our voice heard, loud and clear,
作为中国人,我们说英语是为了让人们听到我们的声音,响亮而清晰,
to make our narratives more compelling, more convincing, and more appling.
使我们的叙述更引人注目,更有说服力,更有吸引力。
词汇 | 中文 | 读音 |
---|---|---|
language | 语言 | [ˈlæŋɡwɪdʒ] |
syllables | 音节 | [ˈsɪləbəlz] |
rhymes | 韵律 | [raɪmz] |
communication | 沟通 | [kəˌmjuːnɪˈkeɪʃn] |
connects | 联合 | [kəˈnekts] |
narratives | 叙述 | [ˈnærətɪvz] |
compelling | 引人注目的 | [kəmˈpelɪŋ] |
convincing | 有说服力的 | [kənˈvɪnsɪŋ] |
appealing | 有吸引力的 | [əˈpiːlɪŋ] |
And you know, my message has always been to accept youself.
你知道,我一直想表达的就是“接受自己”。
No matter what,to love youself,to embrace your flaws.
无论如何,请深爱自己,接受自己的缺点,拥抱不完美。
I think flaws are the things that make us special.
我认为,正是这些不完美造就了特别的我们,让我们与众不同。
The cracks within us are the beautiful parts that need to have light shed on them.
我们内心的裂缝是美丽的地方,有裂缝,阳光才照得进来,才会光芒四射。
Otherwise,they’re just left.
不然,你就会迷失自己。
词汇 | 中文 | 读音 |
---|---|---|
message | 信息 | [ˈmesɪdʒ] |
accept | 接受 | [əkˈsept] |
no matter what | 无论如何 | |
embrace | 拥抱 | [ɪmˈbreɪs] |
flaws | 缺陷 | [flɔz] |
special | 特别的 | [ˈspeʃl] |
cracks | 裂缝 | [kræks] |
within | 在…之内 | [wɪˈðɪn] |
beautiful parts | 美丽的地方 | |
otherwise | 不然 | [ˈʌðərwaɪz] |
left | 离开 | [left] |
package main |
fn main() { |
package main |
fn main() { |
hexo 主题目录无法加入git跟踪,没法提交到代码仓库中保存怎么处理?
因为主题目录有些是git clone到 hexo的theme目录下的,我下载了
maupassant 主题,目录如下发现,在git 无法跟踪themes/maupassant
tree -L 2 themes/ |
因为主题maupassant下载后,跟整个hexo网站仓库统一管理。
通常主题的文件还需要做一些自定义修改,所以需要删除主题目录下的.git数据。
rm -rf themes/maupassant/.git
在网站仓库把themes/maupassant git缓存强制清除。
git rm -r -f --cached themes/maupassant
经过上面的处理应该就可以跟踪themes/maupassant下的所有文件。
]]>vim 8.0 +python3 +lua
iTerm2 (Support true color)
brew install macvim
vim --version |
Plugin Manager
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ |
git clone https://github.com/wandercn/go-ide-vim.conf.git ./vim_conf && mv ./vim_conf/.vimrc $HOME/.vimrcvim +PlugInstall
A cross platform hot compilation tool
By monitoring the modification of the project directory file, the recompilation and running are automatically triggered. Running directory and monitoring change directory can be different. Monitor the file modification in all recursive subdirectories under the project path.
go get -u github.com/wandercn/hotbuild@latest
wander$ cd $your_project_dir/ |
wander$ cd $your_project_dir/ |
Auto create default configuration file in $your_project_dir/.hotbuild.toml,you can modify the configuration yourself.
wander$ cd $your_project_dir/ |
en | zh-cn | |
---|---|---|
buildcmd | Compile command | 编译命令 |
excludedir | Exclude tracked folders | 排除跟踪的文件夹 |
projectdir | Project directory to track | 需要跟踪的项目目录 |
runcmd | Run command | 运行命令 |
# maxfiles is 256 too small. |