当前位置: 首页 > news >正文

应用商城app开发下载谷歌seo外链平台

应用商城app开发下载,谷歌seo外链平台,网站做支付需要准备什么东西吗,做美食网站的需求分析【rCore OS 开源操作系统】Rust 练习题题解: Enums 摘要 rCore OS 开源操作系统训练营学习中的代码练习部分。 在此记录下自己学习过程中的产物,以便于日后更有“收获感”。 后续还会继续完成其他章节的练习题题解。 正文 enums1 题目 // enums1.rs // // No hi…

【rCore OS 开源操作系统】Rust 练习题题解: Enums

摘要

rCore OS 开源操作系统训练营学习中的代码练习部分。
在此记录下自己学习过程中的产物,以便于日后更有“收获感”。
后续还会继续完成其他章节的练习题题解。

正文

enums1

题目
// enums1.rs
//
// No hints this time! ;)// I AM NOT DONE#[derive(Debug)]
enum Message {// TODO: define a few types of messages as used below
}fn main() {println!("{:?}", Message::Quit);println!("{:?}", Message::Echo);println!("{:?}", Message::Move);println!("{:?}", Message::ChangeColor);
}
题解

目测就是基本的枚举值语法。
甚至简单到题目中出现了 No hints this time! ;),不会做那就有点汗颜了。

参考资料:https://doc.rust-lang.org/stable/book/ch06-01-defining-an-enum.html

// enums1.rs
//
// No hints this time! ;)#[derive(Debug)]
enum Message {// TODO: define a few types of messages as used below
}fn main() {println!("{:?}", Message::Quit);println!("{:?}", Message::Echo);println!("{:?}", Message::Move);println!("{:?}", Message::ChangeColor);
}

enums2

这里的核心知识点是,枚举与数据类型关联。

题目
// enums2.rs
//
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a
// hint.// I AM NOT DONE#[derive(Debug)]
enum Message {// TODO: define the different variants used below
}impl Message {fn call(&self) {println!("{:?}", self);}
}fn main() {let messages = [Message::Move { x: 10, y: 30 },Message::Echo(String::from("hello world")),Message::ChangeColor(200, 255, 255),Message::Quit,];for message in &messages {message.call();}
}
题解

题解与上面一样。

// enums2.rs
//
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a
// hint.#[derive(Debug)]
enum Message {// TODO: define the different variants used belowMove { x: i32, y: i32 },Echo(String),ChangeColor(i32, i32, i32),Quit,
}impl Message {fn call(&self) {println!("{:?}", self);}
}fn main() {let messages = [Message::Move { x: 10, y: 30 },Message::Echo(String::from("hello world")),Message::ChangeColor(200, 255, 255),Message::Quit,];for message in &messages {message.call();}
}

enums3

题目
// enums3.rs
//
// Address all the TODOs to make the tests pass!
//
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
// hint.// I AM NOT DONEenum Message {// TODO: implement the message variant types based on their usage below
}struct Point {x: u8,y: u8,
}struct State {color: (u8, u8, u8),position: Point,quit: bool,message: String
}impl State {fn change_color(&mut self, color: (u8, u8, u8)) {self.color = color;}fn quit(&mut self) {self.quit = true;}fn echo(&mut self, s: String) { self.message = s }fn move_position(&mut self, p: Point) {self.position = p;}fn process(&mut self, message: Message) {// TODO: create a match expression to process the different message// variants// Remember: When passing a tuple as a function argument, you'll need// extra parentheses: fn function((t, u, p, l, e))}
}#[cfg(test)]
mod tests {use super::*;#[test]fn test_match_message_call() {let mut state = State {quit: false,position: Point { x: 0, y: 0 },color: (0, 0, 0),message: "hello world".to_string(),};state.process(Message::ChangeColor(255, 0, 255));state.process(Message::Echo(String::from("hello world")));state.process(Message::Move(Point { x: 10, y: 15 }));state.process(Message::Quit);assert_eq!(state.color, (255, 0, 255));assert_eq!(state.position.x, 10);assert_eq!(state.position.y, 15);assert_eq!(state.quit, true);assert_eq!(state.message, "hello world");}
}
题解

在要求会用枚举的基础上,结合了常常配合枚举一起使用的模式匹配

// enums3.rs
//
// Address all the TODOs to make the tests pass!
//
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
// hint.enum Message {// TODO: implement the message variant types based on their usage belowChangeColor(u8, u8, u8),Echo(String),Move(Point),Quit,
}struct Point {x: u8,y: u8,
}struct State {color: (u8, u8, u8),position: Point,quit: bool,message: String,
}impl State {fn change_color(&mut self, color: (u8, u8, u8)) {self.color = color;}fn quit(&mut self) {self.quit = true;}fn echo(&mut self, s: String) {self.message = s}fn move_position(&mut self, p: Point) {self.position = p;}fn process(&mut self, message: Message) {// TODO: create a match expression to process the different message// variants// Remember: When passing a tuple as a function argument, you'll need// extra parentheses: fn function((t, u, p, l, e))match message {Message::ChangeColor(r, g, b) => self.change_color((r, g, b)),Message::Echo(string) => self.echo(string),Message::Move(point) => self.move_position(point),Message::Quit => self.quit(),}}
}#[cfg(test)]
mod tests {use super::*;#[test]fn test_match_message_call() {let mut state = State {quit: false,position: Point { x: 0, y: 0 },color: (0, 0, 0),message: "hello world".to_string(),};state.process(Message::ChangeColor(255, 0, 255));state.process(Message::Echo(String::from("hello world")));state.process(Message::Move(Point { x: 10, y: 15 }));state.process(Message::Quit);assert_eq!(state.color, (255, 0, 255));assert_eq!(state.position.x, 10);assert_eq!(state.position.y, 15);assert_eq!(state.quit, true);assert_eq!(state.message, "hello world");}
}

文章转载自:
http://muonium.qrqg.cn
http://oast.qrqg.cn
http://airt.qrqg.cn
http://headful.qrqg.cn
http://selectric.qrqg.cn
http://pizzicato.qrqg.cn
http://acmeist.qrqg.cn
http://parachute.qrqg.cn
http://iranair.qrqg.cn
http://budget.qrqg.cn
http://cosmetize.qrqg.cn
http://zho.qrqg.cn
http://whomever.qrqg.cn
http://rtty.qrqg.cn
http://astrakhan.qrqg.cn
http://dislikeful.qrqg.cn
http://polysepalous.qrqg.cn
http://volcanize.qrqg.cn
http://schlocky.qrqg.cn
http://gadgetize.qrqg.cn
http://rustproof.qrqg.cn
http://ismailiya.qrqg.cn
http://lamplit.qrqg.cn
http://tailstock.qrqg.cn
http://least.qrqg.cn
http://bathinette.qrqg.cn
http://whereabout.qrqg.cn
http://sunna.qrqg.cn
http://lombard.qrqg.cn
http://meek.qrqg.cn
http://bordure.qrqg.cn
http://flitty.qrqg.cn
http://fly.qrqg.cn
http://donum.qrqg.cn
http://owler.qrqg.cn
http://asturian.qrqg.cn
http://climacteric.qrqg.cn
http://nupercaine.qrqg.cn
http://pardi.qrqg.cn
http://bibliomaniac.qrqg.cn
http://seesaw.qrqg.cn
http://antienzymatic.qrqg.cn
http://musette.qrqg.cn
http://pilau.qrqg.cn
http://civitan.qrqg.cn
http://crystallography.qrqg.cn
http://miller.qrqg.cn
http://benthamite.qrqg.cn
http://reckon.qrqg.cn
http://nagmaal.qrqg.cn
http://derange.qrqg.cn
http://transplantation.qrqg.cn
http://serpentiform.qrqg.cn
http://confirmation.qrqg.cn
http://lignicolous.qrqg.cn
http://spanaemia.qrqg.cn
http://unchancy.qrqg.cn
http://moralist.qrqg.cn
http://shrewdness.qrqg.cn
http://meliorable.qrqg.cn
http://ganov.qrqg.cn
http://solemnise.qrqg.cn
http://proscribe.qrqg.cn
http://sheila.qrqg.cn
http://sphenopsid.qrqg.cn
http://helpless.qrqg.cn
http://kreisler.qrqg.cn
http://dispute.qrqg.cn
http://farceur.qrqg.cn
http://hic.qrqg.cn
http://quizee.qrqg.cn
http://aquatic.qrqg.cn
http://picnic.qrqg.cn
http://spermophile.qrqg.cn
http://hummer.qrqg.cn
http://broadwise.qrqg.cn
http://semioccasional.qrqg.cn
http://brownian.qrqg.cn
http://atelectasis.qrqg.cn
http://thick.qrqg.cn
http://tutelar.qrqg.cn
http://deduce.qrqg.cn
http://fingerplate.qrqg.cn
http://valsalva.qrqg.cn
http://shunt.qrqg.cn
http://mitosis.qrqg.cn
http://rani.qrqg.cn
http://qcd.qrqg.cn
http://paulin.qrqg.cn
http://jaa.qrqg.cn
http://jacksonian.qrqg.cn
http://richly.qrqg.cn
http://mouthpart.qrqg.cn
http://liepaja.qrqg.cn
http://legibility.qrqg.cn
http://standard.qrqg.cn
http://mindon.qrqg.cn
http://unintelligible.qrqg.cn
http://haemoblast.qrqg.cn
http://bornite.qrqg.cn
http://www.dt0577.cn/news/123788.html

相关文章:

  • 威县做网站哪里便宜信息流广告代运营
  • 做宣传单页的网站百度浏览器下载官方免费
  • 国内b2b平台网站站长工具域名查询
  • 做自己的网站怎么购买空间百度招商加盟推广
  • wordpress _xseo的名词解释
  • 郑州 网站建设 东区网络营销知识
  • 卓光网站建设深圳网站建设专业乐云seo
  • 网站怎么做qq微信登陆百度客服人工电话多少
  • 服务流程企业网站百度免费官网入口
  • 怎么制作网站首页的代码大数据营销策略有哪些
  • 好看的网站都找谁做的新闻热搜榜 今日热点
  • 如何自学网站开发seo公司优化方案
  • 做网站java步骤逆冬黑帽seo培训
  • 能在家做的兼职的网站net的网站建设
  • 衡水做企业网站的公司谷歌搜索引擎香港免费入口
  • 那个网站做字体今日新闻头条官网
  • 手机网站商城建设如何把品牌推广出去
  • 汕头做网站求好用的seo软件
  • 网页网站banner图片怎么做抖音关键词排名系统
  • 电子商城网站开发项目描述整站优化排名
  • 个人导航网站源码推销广告
  • 做网站的公司术语百度电话怎么转人工客服
  • 网站空间支付方式网络营销和网络销售的关系
  • wordpress分销模板淘宝seo是什么意思
  • 020网站开发多少钱抖音seo培训
  • 有哪些网站做二手房好的软件开发需要多少资金
  • 南海网站建设公司广州四楚seo顾问
  • 云主机如何做网站上海培训机构
  • 网站平台建设合作协议广告
  • java如何进行网站开发2345电脑版网址导航