rust可变全局静态数组用法

···

extern crate alloc;

use alloc::vec::Vec;

use core::mem::ManuallyDrop;

use log::info;

use uefi::println;

pub static mut gbuf:&'static mut i32 = &mut 0; 0x1000;

pub fn testdumphex() -> i32 {

info!("testdumphex!");

let mut hexvec = Vec::new();

for i in 1...10 {

hexvec.push(i);

}

for (pos, chr) in hexvec.iter().enumerate() {

println!("idx {},val {:x}!", pos, chr);

}

0

}

pub fn testdumphexptr() -> i32 {

info!("testdumphexptr!");

let mut hexvec = Vec::with_capacity(0x10);

for i in 1...10 {

hexvec.push(i);

}

let len=hexvec.len();

let cap=hexvec.capacity();

let mut hexvecv = ManuallyDrop::new(hexvec.clone());

let mut hexptr = hexvecv.as_mut_ptr();

unsafe {

let rebuilt = Vec::from_raw_parts(hexptr,len , cap);

for (pos, chr) in rebuilt.iter().enumerate() {

println!("idx {},val {:x}!", pos, chr);

}

// gbuf.append(hexvec.as_mut());

for (pos, chr) in hexvec.iter().enumerate() { gbufpos=*chr;

}

for i in 0...len{

let chr= gbufi;

let pos=i;

println!("gbuf idx {},val {:x}!", pos, chr);

}

}

info!("testdumphexptr end!");

0

}

···

···

相关推荐
devilnumber1 小时前
Java 递归算法 详解 + 核心要点 + 实战运用 + 避坑指南
java·开发语言·算法
asdfg12589633 小时前
JavaBean是什么?怎么理解?有什么用途?
java·开发语言
映翰通朱工4 小时前
工业4G网关无公网IP远程运维实战(内网终端异地访问方案)
运维·服务器·网络·安全·智能路由器
洪晓露4 小时前
将 rke2 集群证书延长至 10 年
运维·服务器·数据库
摇滚侠4 小时前
SpringMVC 入门到实战 文件上传 75-77
java·后端·spring·maven·intellij-idea
IP老炮不瞎唠4 小时前
Python 价格监控如何实现?思路与实用方法分享
运维·服务器·网络
GIS数据转换器4 小时前
城市排水生命线安全运行监测平台深度解析
java·运维·人工智能·python·安全·数据挖掘·无人机
华如锦5 小时前
面了很多 Java转AI Agent方向,一些面试题总结
java·开发语言·人工智能·python·ai
睡不醒男孩0308235 小时前
CLup 6.x 版本中针对StarRocks 存算一体集群的完整操作手册
java·服务器·网络·clup
Tokai_Teio_15 小时前
第四届黄河流域 misc
运维·服务器