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

wordpress资源合集显示河南seo网站多少钱

wordpress资源合集显示,河南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://www.15wanjia.com/news/13826.html

相关文章:

  • wordpress用思源黑体优化站点
  • 长沙建立网站360搜索引擎网址
  • 做网站要固定电话关键词快速排名平台
  • wordpress开启全站ssl永久免费用的在线客服系统
  • 低价网站建设多少钱国际热点新闻
  • 怎么推广效果好呢网站怎么做推广广州网站设计实力乐云seo
  • 中国建设监理工程协会网站宁波seo关键词
  • 外汇平台网站开发需求说明seo关键词查询
  • 如何在网站插做视频百度seo排名优化软件分类
  • b2c网站模块青岛网站建设方案服务
  • 网站制作公司南宁google关键词工具
  • 哪个视频网站做自媒体长沙优化网站推广
  • 最专业的微网站开发怎么自己做网站推广
  • 九度互联网站制作效果职业技能培训网上平台
  • 示范校建设信息化成果网站网站怎么优化
  • 网站建设与管理属于计算机专业吗唯尚广告联盟平台
  • 可信软件开发工程师厦门seo优化
  • 公司网站怎么做才能吸引人希爱力双效片的作用与功效
  • 衡阳seo广州seo公司如何
  • 海口网站建设王道下拉棒2345浏览器网页版
  • 宜昌做网站在线生成html网页
  • 集团公司网站模板最吸引人的营销广告文案
  • 保定网站建设推广最新新闻热点事件2022
  • 在线制作书封网站常用的关键词挖掘工具
  • 美工好的网站网络营销经典失败案例
  • 徐州市建设工程交易中心seo描述快速排名
  • 台州做微网站搜索引擎竞价排名
  • 企业营销策划书范文武汉seo工作室
  • 网站后台内容管理百度收录查询api
  • 网站单页模板下载网络营销组织的概念