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() { gbuf[pos]=*chr;

}

for i in 0...len{

let chr= gbuf[i];

let pos=i;

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

}

}

info!("testdumphexptr end!");

0

}

···

···

相关推荐
DjangoJason23 分钟前
计算机网络 : Socket编程
linux·服务器·开发语言·笔记·计算机网络
救救孩子把39 分钟前
Mac 环境下 JDK 版本切换全指南
java·开发语言·macos
路飞雪吖~44 分钟前
【Linux】共享内存
java·linux·服务器
caihuayuan41 小时前
鸿蒙AI开发:10-多模态大模型与原子化服务的集成
java·大数据·sql·spring·课程设计
张哈大1 小时前
【 Redis | 实战篇 秒杀优化 】
java·数据库·redis·笔记·缓存
低维歌者1 小时前
python训练营day27
java·开发语言·python
maomi_95261 小时前
操作系统之EXT文件系统
linux·服务器
大帅不是我2 小时前
Python多进程编程执行任务
java·前端·python
purrrew2 小时前
【Java ee初阶】jvm(3)
java·jvm
Hello World......4 小时前
互联网大厂Java面试:从Spring到微服务的全面探讨
java·spring boot·spring cloud·微服务·面试·技术栈·互联网大厂