学习Rust的第26天:Rust中的cp

在本文中复刻了 cp 实用程序的功能,我想默认使其递归,因为每次我想复制时都输入 -R 文件夹都会觉得有点重复,本文代码将与前文代码保持相似,我们只会更改程序的核心功能和一些变量名称以匹配用例

Pseudo Code 伪代码

function copy(src,dst)->result{
  create dst directory
  for entry in src{
    get file_type
    if file_type.is_dir(){
      copy(entry.path(), dst.as_ref().join(entry.file_name()))?
    } else {
      fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?
    }
  }
}

args = command_line_arguments
remove the first element of the args vector
if args.length == 0 {
  print error_message
}
else if args.contains("--help") {
  print help_message
} else {
  result = copy(args[0],args[1])
  error handling
}

Looks pretty simple, we’ll create a lib.rs and do the basic setup tasks just like yesterday. We’ll create the following :
看起来很简单,我们将创建一个 lib.rs 并像昨天一样执行基本设置任务。我们将创建以下内容:

  1. config Struct  config 结构体
  2. An implementation block 一个实现块
  3. new method  new 方法
  4. help method  help 方法
  5. not_enough_arguments method  not_enough_arguments 方法
  6. run function  run 函数

and then we’ll write the logic for our copy function
然后我们将为 copy 函数编写逻辑

Creating a new cargo project and setting

  • 20
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

老父亲的能量嘎嘣脆

感谢支持,共同成长

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

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

打赏作者

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

抵扣说明:

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

余额充值