-
Notifications
You must be signed in to change notification settings - Fork 1.1k
basic-types/functions #210
-
basic-types/functions
Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 25 -
👎 3 -
😄 2 -
🎉 2 -
❤️ 3 -
🚀 2
Replies: 68 comments 12 replies
-
第4题题解这个unimplemented!()
,太超纲了吧🤣
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 13
-
同感
Beta Was this translation helpful? Give feedback.
All reactions
-
我写的是exit(0)......感觉只要调用一个返回值为!的函数作为返回值就行了
Beta Was this translation helpful? Give feedback.
All reactions
-
std::thread::sleep
可还行。
Beta Was this translation helpful? Give feedback.
All reactions
-
这章虽然内容很少,但是练习题好难🙈😩
Beta Was this translation helpful? Give feedback.
All reactions
-
难在哪? 难在拿完全没讲过的东西来考hehe
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 9
-
有个想法,练习题里涉及到一些知识点,拿到书里面去讲如何?
Beta Was this translation helpful? Give feedback.
All reactions
-
额,正在查漏补缺 ing
Beta Was this translation helpful? Give feedback.
All reactions
-
完成 5/5
Beta Was this translation helpful? Give feedback.
All reactions
-
done ! 第四题的难度就不对劲
Beta Was this translation helpful? Give feedback.
All reactions
-
done!这个练习的solution链接只到repo地址没有到对应的md😂
Beta Was this translation helpful? Give feedback.
All reactions
-
unimplement!():未实现(not implemented)
todo!():尚未被实现(not yet implemented)
两个宏函数都可以导致panic,但是这两个方法的语义不同。
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Done
Beta Was this translation helpful? Give feedback.
All reactions
-
Done
Beta Was this translation helpful? Give feedback.
All reactions
-
第4题跟讲过的东西不能说毫无关系, 只能说毫无联系
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3
-
Done!这节的发散函数并不是很能理解,这样的函数在实际应用中能用来做什么呢?
Beta Was this translation helpful? Give feedback.
All reactions
-
例如一个服务器的守护进程可能是无限循环的,因此是发散函数。
函数里部分代码因为各种原因暂时留空不写时,程序会因为缺少对应类型返回值无法通过编译;如果暂时给返回值类型记作()
,那么到时这些函数需要全部都批量修改函数签名会很麻烦;更不用说如果有已实现分支返回预期的类型,那么未实现的分支就必须捏造一个符合返回类型的值返回,这非常恼人;而todo!()
unimplement!()
这些宏对应的!
类型可以转换成任意类型,也就规避了这个问题。后期实现真正的业务逻辑时也不用修改函数签名,只需要删掉宏并替换为自己的代码。
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 15
-
如果有已实现分支返回预期的类型,那么未实现的分支就必须捏造一个符合返回类型的值返回
此处十分拗口,有所疑问,不知是否理解正确,目前的我的理解中git分支可以有多个,但是统一最终都会独立开发的代码,那么这种情况是否为:仅当未实现分支中引用了实现分支中的代码进行继承才会出现这个情况?
Beta Was this translation helpful? Give feedback.
All reactions
-
这个分支应该是match匹配的分支吧,不是git的分支
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
有些东西教程里完全没涉及到哦, 但是教程为了讲重点不抽丝剥茧也可以理解, 提个小意见, 可以把不是那么重要的东西做一个简述列表之类的放在对应的小节底下供读者自己学习
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
发散函数这里对于刚接触的不是很友好 如果有更多的叙述就更好了
Beta Was this translation helpful? Give feedback.
All reactions
-
Done
Beta Was this translation helpful? Give feedback.
All reactions
-
done but diffiuclt
Beta Was this translation helpful? Give feedback.
All reactions
-
Done!
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
day1 完成了 2.2 所有练习
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
Done!
Beta Was this translation helpful? Give feedback.
All reactions
-
题里有些知识点 没提过啊
Beta Was this translation helpful? Give feedback.
All reactions
-
Done
Beta Was this translation helpful? Give feedback.
All reactions
-
✅
Beta Was this translation helpful? Give feedback.
All reactions
-
看不懂这一章在干啥,虽然程序都能改对
Beta Was this translation helpful? Give feedback.
All reactions
-
发散函数实现方式基本有三种:
1.panic! 触发恐慌;
2.loop{} 无限循环;
3.use std::process;process::exit(0); 程序退出
以上三种方式都可以满足要求,而且简单易懂!
使用场景可以问AI,方便联想记忆.
欢迎补充
Beta Was this translation helpful? Give feedback.
All reactions
-
书里在前面没有提到第四第五题的match 以及第五题的unimplement!()/loop{}和todo!(),可能最好还是要提一下?((
Beta Was this translation helpful? Give feedback.