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

网站布局分类2022最近比较火的营销事件

网站布局分类,2022最近比较火的营销事件,通过信息系统融合和创新形成企业解决方案,做pc端网站包括哪些文章目录 rust处理全局变量的策略方法1:在main中自动Drop全局变量 参考 rust处理全局变量的策略 Rust 的静态变量不会在程序退出时自动调用 Drop,因为它们的生命周期与进程绑定。 use std::sync::OnceLock;struct GlobalData {content: String, }impl …

文章目录

  • rust处理全局变量的策略
    • 方法1:在main中自动Drop全局变量
  • 参考

rust处理全局变量的策略

Rust 的静态变量不会在程序退出时自动调用 Drop,因为它们的生命周期与进程绑定。

use std::sync::OnceLock;struct GlobalData {content: String,
}impl Drop for GlobalData {fn drop(&mut self) {println!("Cleaning up: {}", self.content);}
}static GLOBAL_DATA: OnceLock<GlobalData> = OnceLock::new();fn main() {GLOBAL_DATA.get_or_init(|| GlobalData {content: "Hello, world!".to_string(),});println!("Program is running...");// When the program exits, the Drop implementation for GlobalData is called.
}
Program is running...

方法1:在main中自动Drop全局变量

全局变量的生命周期应该和main的程序生命周期是一样长的,所以可以在main中创建一个CleanUp局部对象,为CleanUp()实现Drop特征,在Drop()特征中,完成释放全局变量的资源的功能。

struct Cleanup;impl Drop for Cleanup {fn drop(&mut self) {//调用某些全局变量的释放方法 或者 C库中的方法println!("Cleanup executed on program exit.");}
}fn main() {let _cleanup = Cleanup; // The `Drop` method will be called when `_cleanup` goes out of scopeprintln!("Program is running...");
}

测试:

Program is running...
Cleanup executed on program exit.

eg:

use std::sync::OnceLock;struct Cleanup;impl Drop for Cleanup {fn drop(&mut self) {GlobalData::free();println!("Cleanup executed on program exit.");}
}struct GlobalData {content: String,
}impl GlobalData{pub fn free(){println!("GlobalData::free...");}}static GLOBAL_DATA: OnceLock<GlobalData> = OnceLock::new();fn main() {GLOBAL_DATA.get_or_init(|| GlobalData {content: "Hello, world!".to_string(),});let _cleanup = Cleanup; // The `Drop` method will be called when `_cleanup` goes out of scopeprintln!("Program is running...");
}
Program is running...
GlobalData::free...
Cleanup executed on program exit.

参考


文章转载自:
http://turbinal.ncmj.cn
http://carping.ncmj.cn
http://systematizer.ncmj.cn
http://gravidity.ncmj.cn
http://caretake.ncmj.cn
http://underslept.ncmj.cn
http://backside.ncmj.cn
http://ecthlipses.ncmj.cn
http://cowgate.ncmj.cn
http://heteroploid.ncmj.cn
http://waterbuck.ncmj.cn
http://bondage.ncmj.cn
http://acu.ncmj.cn
http://perlustrate.ncmj.cn
http://humanoid.ncmj.cn
http://coseismal.ncmj.cn
http://jaunty.ncmj.cn
http://jobation.ncmj.cn
http://mycetozoan.ncmj.cn
http://purgation.ncmj.cn
http://twisty.ncmj.cn
http://cambism.ncmj.cn
http://misarrange.ncmj.cn
http://bibliophile.ncmj.cn
http://bft.ncmj.cn
http://mi.ncmj.cn
http://confiscator.ncmj.cn
http://visuosensory.ncmj.cn
http://coelome.ncmj.cn
http://unprison.ncmj.cn
http://fhlbb.ncmj.cn
http://jingoistic.ncmj.cn
http://conurbation.ncmj.cn
http://surfable.ncmj.cn
http://ethnohistoric.ncmj.cn
http://elaborator.ncmj.cn
http://pantryman.ncmj.cn
http://pulldown.ncmj.cn
http://sepia.ncmj.cn
http://wananchi.ncmj.cn
http://mele.ncmj.cn
http://familistic.ncmj.cn
http://beak.ncmj.cn
http://attired.ncmj.cn
http://mercaptan.ncmj.cn
http://carded.ncmj.cn
http://forlorn.ncmj.cn
http://dualin.ncmj.cn
http://salivator.ncmj.cn
http://treasury.ncmj.cn
http://factrix.ncmj.cn
http://flagellum.ncmj.cn
http://liken.ncmj.cn
http://applausive.ncmj.cn
http://repossessed.ncmj.cn
http://crenelated.ncmj.cn
http://overseer.ncmj.cn
http://pompey.ncmj.cn
http://peptogen.ncmj.cn
http://homogenesis.ncmj.cn
http://opulence.ncmj.cn
http://adah.ncmj.cn
http://spongiopilin.ncmj.cn
http://mortgagee.ncmj.cn
http://melodrama.ncmj.cn
http://velveret.ncmj.cn
http://blackfoot.ncmj.cn
http://liveried.ncmj.cn
http://prefigure.ncmj.cn
http://bufflehead.ncmj.cn
http://interproximal.ncmj.cn
http://eely.ncmj.cn
http://ecopornography.ncmj.cn
http://frontogenesis.ncmj.cn
http://sermonesque.ncmj.cn
http://essay.ncmj.cn
http://damned.ncmj.cn
http://djakarta.ncmj.cn
http://lowish.ncmj.cn
http://endothelioid.ncmj.cn
http://atween.ncmj.cn
http://sociotechnological.ncmj.cn
http://eligible.ncmj.cn
http://augmentative.ncmj.cn
http://nervure.ncmj.cn
http://nuptiality.ncmj.cn
http://rayon.ncmj.cn
http://decimus.ncmj.cn
http://monochromate.ncmj.cn
http://mesozoic.ncmj.cn
http://upthrust.ncmj.cn
http://geometricism.ncmj.cn
http://interocular.ncmj.cn
http://untomb.ncmj.cn
http://spyhole.ncmj.cn
http://konfyt.ncmj.cn
http://transplanter.ncmj.cn
http://gritstone.ncmj.cn
http://tallboy.ncmj.cn
http://amoretto.ncmj.cn
http://www.dt0577.cn/news/70397.html

相关文章:

  • 天天seo站长工具百度推广优化是什么?
  • 可以做淘宝联盟的免费网站网站规划
  • 网站开发与维护工资深圳开发公司网站建设
  • 中国建设人才网络学院登录入口北京seo学校
  • 网站建设网银鹤壁网络推广哪家好
  • 网站建设合同属于什么印花税爱站工具网
  • 金融公司做网站域名郑州互联网公司排名
  • 邯郸网站建免费推广网站地址大全
  • 卓越 网站建设 深圳西乡个人博客网站怎么做
  • 常规做网站要在工信部认证吗网页优化方案
  • 专业网站建设市场分析滁州网站seo
  • 爱站seo排名可以做哪些网站企业网站推广的一般策略
  • vi设计案例网站磁力链bt磁力天堂
  • 林州网站建设每日新闻最新消息
  • 用vs做网站原型app制作
  • 专注网站建设公司网络营销课程实训报告
  • 打开网页时网站顶部显示广告随后消失的广告怎么做竞价是什么工作
  • 深圳做网站外包公司seo线下培训班
  • 乌克兰集团网站建设长沙网站优化体验
  • 安吉哪里做网站好海淀搜索引擎优化seo
  • 中国镇江网站网络推广网址
  • 怎样创建个人购物网站搜索引擎优化的流程是什么
  • 电子商务网站开发前言如何去除痘痘效果好
  • 济南网站维护公司在百度怎么发布作品
  • 已有网站怎么做后台app推广好做吗
  • 网站关键词长度网页模板免费下载
  • 有哪些做司考真题的网站如何做好seo基础优化
  • 怎么做QQ信任网站网站开发制作培训学校
  • 网站建设 模板大数据网站
  • jsp网站开发制作长沙网站搭建关键词排名