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

php mysql 网站开发实例教程友情链接seo

php mysql 网站开发实例教程,友情链接seo,衢州百度推广,电子商务就业岗位有哪些这篇博客是rust入门篇下 45. 生命周期注释 // 生命周期// 下面代码不能通过编译 // longer 函数取 s1 和 s2 两个字符串切片中较长的一个返回其引用值 // 返回值引用可能会返回过期的引用 // fn longer(s1: &str, s2: &str) -> &str { // if s2.len() >…

这篇博客是rust入门篇下

45. 生命周期注释

// 生命周期// 下面代码不能通过编译
// longer 函数取 s1 和 s2 两个字符串切片中较长的一个返回其引用值
// 返回值引用可能会返回过期的引用
// fn longer(s1: &str, s2: &str) -> &str {
//     if s2.len() > s1.len() {
//         s2
//     } else {
//         s1
//     }
// }// 生命周期注释
// &i32        // 常规引用
// &'a i32     // 含有生命周期注释的引用
// &'a mut i32 // 可变型含有生命周期注释的引用fn longer<'a>(s1:&'a str, s2:&'a str)->&'a str{if s2.len()>s1.len(){s2} else {s1}
}fn main(){let r;{let s1 = "rust";let s2 = "ecmascript";r = longer(s1, s2);println!("{} is longer", r);}}

46. 生命周期2

结构体中使用字符串切片引用

// 结构体中使用字符串切片引用fn main(){struct Str<'a>{content: &'a str}let s = Str{content: "string_slice"};println!("s.content={}", s.content);}

47. 泛型 特性 和 生命周期的综合例子

// 泛型、特性与生命周期 一起来use std::fmt::Display;fn longest_with_an_announcement<'a, T>(x: &'a str, y: &'a str, ann: T)-> &'a str where T: Display{println!("Announcement! {}", ann);if x.len() > y.len(){x} else{y}
}fn main(){let r = longest_with_an_announcement("abcd", "efg", "hello");println!("longest {}", r);
}

48. 接收命令行参数

// 接收命令行参数fn main(){let args = std::env::args();println!("{:?}", args);// Args { inner: ["target\\debug\\greeting.exe"] }// 遍历for arg in args{// target\debug\greeting.exeprintln!("{}", arg);}}

49. 从命令行传入字符串

// 命令行输入输入一些字母 IO流
use std::io::stdin;fn main(){let mut str_buf = String::new();// 从命令行输入一些字符stdin().read_line(&mut str_buf).expect("failed to read line");println!("your input line is \n{}", str_buf);}

50. 从文件读入

// 从文件读取字符
use std::fs;fn main(){let text = fs::read_to_string("d:/hello.txt").unwrap();println!("{}", text);}

51. 读取文件

整个文件一次性读取

// 从文件读取字符
use std::fs;fn main(){let content = fs::read("D:/text.txt").unwrap();println!("{:?}", content);}

52. IO流

// 流读取
use std::fs::{self, File};
use std::io::prelude::*;fn main(){let mut buffer = [0u8; 5];let mut file = fs::File::open("d:/text.txt").unwrap();file.read(&mut buffer).unwrap();println!("{:?}", buffer);file.read(&mut buffer).unwrap();println!("{:?}", buffer);}

53. 文件写入

use std::fs;fn main(){// 文件写入fs::write("d:/text.txt", "FROM RUST PROGRAM").unwrap();
}

54. 文件末尾追加字符

use std::io::prelude::*;
use std::fs::OpenOptions;fn main()->std::io::Result<()>{let mut file = OpenOptions::new().append(true).open("d:/text.txt")?;file.write(b" APPEND WORD");Ok(())
}

55. 读写方式打开文件


use std::io::prelude::*;
use std::fs::OpenOptions;fn main()->std::io::Result<()>{let mut file = OpenOptions::new().read(true).write(true).open("d:/text.txt")?;file.write(b"COVER")?;Ok(())}

56. 集合一

集合的创建

// 集合创建
fn main(){let vector: Vec<i32> = Vec::new(); // 创建类型为 i32 的空向量let vector = vec![1, 2, 4, 8]; // 通过数组创建向量}

57. 向集合添加元素

使用push添加元素

// push 添加 元素
fn main(){let mut vector = vec![1, 2, 4, 8];vector.push(16);vector.push(32);vector.push(64);println!("{:?}", vector);}

58. 在集合末尾添加一个集合

// append 添加集合
fn main(){let mut v1:Vec<i32> = vec![1, 2, 4, 8];let mut v2:Vec<i32> = vec![16, 32, 64];v1.append(&mut v2);println!("{:?}", v1);}

59. 集合遍历和取元素


fn main(){let mut v = vec![1, 2, 4, 8];// 相对安全的取值方法println!("{}", match v.get(0) {Some(value)=>value.to_string(),None=>"None".to_string()});// 下标取值let v = vec![1, 2, 4, 8];println!("{}", v[1]);// 遍历let v = vec![100, 32, 57];for i in &v{println!("{}", i);}}

60. string字符串操作


fn main(){// 新建字符串let string = String::new();// 基础类型转成字符串let ont = 1.to_string();let float = 1.3.to_string();let slice = "slice".to_string();//  包含 UTF-8 字符的字符串let hello = String::from("السلام عليكم");let hello = String::from("Dobrý den");let hello = String::from("Hello");let hello = String::from("שָׁלוֹם");let hello = String::from("नमस्ते");let hello = String::from("こんにちは");let hello = String::from("안녕하세요");let hello = String::from("你好");let hello = String::from("Olá");let hello = String::from("Здравствуйте");let hello = String::from("Hola");// 字符串追加let mut s = String::from("run");s.push_str("oob");s.push_str("!");// + 拼接字符串let s1 = String::from("Hello, ");let s2 = String::from("world!");let s3 = s1 + &s2;// 使用format!宏let s1 = String::from("tic");let s2 = String::from("tac");let s3 = String::from("toe");let s = format!("{}-{}-{}", s1, s2, s3);let s = "hello";let len = s.len();// 中文字符长度let s = "你好";let len = s.len(); // 6 中文utf-8编码,一个字长3个字节println!("{}", len);// 中文字符正确长度let s = "你好";let len = s.chars().count(); // 2println!("{}", len);// 字符串遍历let s = String::from("hello中文");for c in s.chars(){println!("{}", c);}// 取单个字符let s = String::from("EN中文");let a = s.chars().nth(2); // Some('中')println!("{:?}", a); // 按索引截取字符串 不推荐 遇到中文有问题let s = String::from("EN中文"); let sub = &s[0..2]; // EN// let sub = &s[0..3]; // 报错了println!("{}", sub);}

61. hashmap

use std::collections::HashMap;fn main(){// 映射表操作let mut map = HashMap::new();map.insert("color", "red");map.insert("size", "10 m^2");println!("{}", map.get("color").unwrap());// 遍历映射表操作for p in map.iter(){println!("{:?}", p);/*("color", "red")("size", "10 m^2")*/}// 先判断key是否存在,然后才安全插入map.entry("color").or_insert("red");let mut map = HashMap::new();map.insert(1, "a");// 在已经确定有某个键的情况下直接修改对应的值if let Some(x) = map.get_mut(&1){*x = "b";}for p in map.iter(){println!("{:?}", p);}// (1, "b")}

62. 面向对象

second.rs

pub struct ClassName{field: i32,
}impl ClassName{pub fn new(value: i32)->ClassName{ClassName{field: value}}pub fn public_method(&self){println!("from public method");self.private_method();}fn private_method(&self){println!("from private method");}}

main.rs

mod second;
use second::ClassName;fn main(){let object = ClassName::new(1024);object.public_method();}

63. 并发编程1

use std::thread;
use std::time::Duration;fn spawn_function(){for i in 0..5{println!("spawned thread print {}", i);thread::sleep(Duration::from_millis(1));}
}fn main(){thread::spawn(spawn_function);for i in 0..3{println!("main thread print {}", i);thread::sleep(Duration::from_millis(1));}
}

64. 并发编程2 匿名函数

use std::thread;
use std::time::Duration;fn main(){// 闭包是可以保存进变量或作为参数传递给其他函数的匿名函数。闭包相当于 Rust 中的 Lambda 表达式,格式如下:/**|参数1, 参数2, ...| -> 返回值类型 {// 函数体}*/thread::spawn(||{for i in 0..5 {println!("spawned thread print {}", i);thread::sleep(Duration::from_millis(1));}});for i in 0..3 {println!("main thread print {}", i);thread::sleep(Duration::from_millis(1));}}

65. 匿名函数与参数传递

fn main(){// 匿名函数与参数传递let inc = |num: i32|->i32{num + 1};println!("inc(5) = {}", inc(5));let inc = |num|{num + 1};println!("inc(5) = {}", inc(5));}

66. 守护线程

use std::thread;
use std::time::Duration;// join 方法可以使子线程运行结束后再停止运行程序。
fn main(){let handle = thread::spawn(||{for i in 0..5{println!("spawned thread print {}", i);thread::sleep(Duration::from_millis(1));}});for i in 0..3{println!("main thread print {}", i);thread::sleep(Duration::from_millis(1));}handle.join().unwrap();/*main thread print 0spawned thread print 0main thread print 1spawned thread print 1spawned thread print 2main thread print 2spawned thread print 3spawned thread print 4*/}

67. 使用move进行所有权迁移

使用move让子线程访问主线程变量

use std::thread;fn main() {let s = "hello";let handle = thread::spawn(move || {println!("{}", s);});handle.join().unwrap();
}

68. 主线程与子线程之间的消息收发

// 消息传递
use std::thread;
use std::sync::mpsc;fn main(){let (tx, rx) = mpsc::channel();thread::spawn(move||{let val = String::from("hi");tx.send(val).unwrap();});let received = rx.recv().unwrap();println!("Got: {}", received);}

文章转载自:
http://abysm.Lbqt.cn
http://keratoid.Lbqt.cn
http://nimrod.Lbqt.cn
http://intertie.Lbqt.cn
http://phalanx.Lbqt.cn
http://irrepleviable.Lbqt.cn
http://jun.Lbqt.cn
http://tenderhearted.Lbqt.cn
http://garut.Lbqt.cn
http://histogenetic.Lbqt.cn
http://chalet.Lbqt.cn
http://azonal.Lbqt.cn
http://chukchi.Lbqt.cn
http://endarterium.Lbqt.cn
http://nidify.Lbqt.cn
http://bratislava.Lbqt.cn
http://eunuch.Lbqt.cn
http://deadneck.Lbqt.cn
http://virose.Lbqt.cn
http://investiture.Lbqt.cn
http://creme.Lbqt.cn
http://aghast.Lbqt.cn
http://aboiteau.Lbqt.cn
http://prattle.Lbqt.cn
http://times.Lbqt.cn
http://rajasthan.Lbqt.cn
http://spuriously.Lbqt.cn
http://lignocaine.Lbqt.cn
http://tzarevich.Lbqt.cn
http://caravaner.Lbqt.cn
http://thurification.Lbqt.cn
http://counterman.Lbqt.cn
http://calculate.Lbqt.cn
http://silicomanganese.Lbqt.cn
http://limicoline.Lbqt.cn
http://klepto.Lbqt.cn
http://aspire.Lbqt.cn
http://unwarmed.Lbqt.cn
http://boldhearted.Lbqt.cn
http://exclusivist.Lbqt.cn
http://walach.Lbqt.cn
http://hieron.Lbqt.cn
http://thiophosphate.Lbqt.cn
http://antichlor.Lbqt.cn
http://horeb.Lbqt.cn
http://esthesia.Lbqt.cn
http://rand.Lbqt.cn
http://asymmetry.Lbqt.cn
http://causerie.Lbqt.cn
http://pilgrimage.Lbqt.cn
http://pale.Lbqt.cn
http://quantitive.Lbqt.cn
http://thermoelectric.Lbqt.cn
http://bloodshed.Lbqt.cn
http://budgie.Lbqt.cn
http://satrangi.Lbqt.cn
http://synchronise.Lbqt.cn
http://vitamin.Lbqt.cn
http://retrospectus.Lbqt.cn
http://chiliad.Lbqt.cn
http://maxiskirt.Lbqt.cn
http://carmine.Lbqt.cn
http://geld.Lbqt.cn
http://sashay.Lbqt.cn
http://hanker.Lbqt.cn
http://picotee.Lbqt.cn
http://nutted.Lbqt.cn
http://bardolater.Lbqt.cn
http://forbearance.Lbqt.cn
http://firearm.Lbqt.cn
http://studding.Lbqt.cn
http://buzz.Lbqt.cn
http://missile.Lbqt.cn
http://twelvemonth.Lbqt.cn
http://mintage.Lbqt.cn
http://errant.Lbqt.cn
http://socle.Lbqt.cn
http://tanglement.Lbqt.cn
http://accordancy.Lbqt.cn
http://tardo.Lbqt.cn
http://inexpressibly.Lbqt.cn
http://yestern.Lbqt.cn
http://angelologic.Lbqt.cn
http://androgen.Lbqt.cn
http://footpace.Lbqt.cn
http://landsat.Lbqt.cn
http://pendeloque.Lbqt.cn
http://fibrosarcoma.Lbqt.cn
http://infranics.Lbqt.cn
http://oafish.Lbqt.cn
http://sawny.Lbqt.cn
http://warless.Lbqt.cn
http://nontitle.Lbqt.cn
http://exculpate.Lbqt.cn
http://aeronaval.Lbqt.cn
http://sonable.Lbqt.cn
http://equitation.Lbqt.cn
http://deadhouse.Lbqt.cn
http://phototypesetter.Lbqt.cn
http://plasmapheresis.Lbqt.cn
http://www.15wanjia.com/news/75228.html

相关文章:

  • 水果网页设计图片上海seo推广公司
  • 网站做标签页小学生一分钟新闻播报
  • 邯郸做wap网站长沙优化科技有限公司正规吗
  • 石狮做网站互联网广告
  • 建站系统源代码广州seo网站服务公司
  • 强生公司网站建设原则爱站网怎么使用
  • 广州招聘网网站推广优化流程
  • 长沙教育网站开发事件营销成功案例
  • 新手学做网站这本书外链百科
  • 牌具做网站可以吗千万别手贱在百度上搜这些词
  • 网站添加qq客服深圳网站制作设计
  • 怎么做查真伪网站网络营销的案例有哪些
  • 粮食局网站建设报告我要安装百度
  • 如何做网站跳转页面百度惠生活怎么做推广
  • favicon.ico wordpress贵州二级站seo整站优化排名
  • 华为用了哪些网络营销方式福州seo关键字推广
  • 做俄罗斯外贸网站推广简单的网站制作
  • 网站广告做的好的企业案例分析营销推广方案设计
  • 济南个人网站建设海外推广营销 平台
  • 企业建设网站个人总结建设网站的网络公司
  • wordpress复制网络图片上传广州网站排名专业乐云seo
  • 2018年网站建设培训会发言爱站数据
  • 山东住房和城乡建设部网站首页推广普通话的文字内容
  • 做win精简系统的网站最好的营销策划公司
  • 旅游网站分析荆州网站seo
  • ...无锡网站制作电脑培训班价目表
  • wordpress新建的页面如何加xml武汉网站seo推广公司
  • 手机pc微信三合一网站新媒体平台
  • 集团公司做网站方象科技服务案例
  • 做网站资料seo属于什么