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

一般网站建设流程有哪些步骤建筑方案设计案例

一般网站建设流程有哪些步骤,建筑方案设计案例,长宁区网站建设公,怎么查网站是否备案【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.yayakq.cn/news/807824/

相关文章:

  • 服装设计参考网站免费大数据查询
  • wordpress 停用多站点知乎 闲鱼网站建设和网站运营
  • 深圳做门户网站网络推广的目标
  • 网站类的百度百科怎么做免费crm手机版
  • 辽宁城乡住房建设厅网站首页想开工作室没有项目
  • 制作app网站律师做几个网站
  • 建立网站大约多少钱温州网页设计公司
  • 济南商城网站建设多少钱大连网站
  • 靖安建设局网站免费网站seo诊断
  • 吴江网站建设收费可以做视频推广的网站有哪些内容
  • 沈阳论坛建站模板小程序数据库怎么建立
  • 石家庄工信部网站做第三方库网站
  • 企业手机网站制作做网站推广怎么样
  • 宁波seo网站推广盐城网站建设推广
  • 网站建设营销型网站连云港做网站企业
  • 新手学做网站图纸深圳网络推广平台
  • html5手机网站开发实例全网通官方网站
  • 建设一个网站需要哪些硬件设备天津seo实战培训
  • 莱芜找工作网站长沙中小企业有哪些公司
  • 网站推广具体内容竞彩网站开发
  • 做百度移动端网站优化eclipse做网站代码
  • 怎样做网站上更改文字2023今天的新闻联播
  • 连云港网站优化网站建设资质要求
  • 虚拟商城网站广告营销推广方案
  • 广州定制网站建设域名策划方案
  • 把公司网站 公开下载 做教程 侵权吗深圳手机网站建设价格低
  • 潮州专业网站建设制作美工培训网站
  • 怎样收录网站如何给网站做二维码
  • 网站建设演示ppt模板下载海淘网站
  • 建网站如何备案长春网站公司有哪些内容