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

}

···

···

相关推荐
coding随想18 分钟前
Java中间件简介:构建现代软件的“隐形桥梁”
java·中间件
superkcl20224 小时前
【JAVA】【Stream流】
java·windows·python
mldong4 小时前
mldong 快速开发框架登录模块设计与实现
java·后端·架构
Web极客码4 小时前
Proxmox VE与VMWare ESXi:选择适合您的虚拟化平台
服务器·虚拟化·vmware esxi·proxmox ve
bulucc5 小时前
Maven 或 Gradle 下载和添加 jar 文件的步骤
java·maven·jar
墨雪遗痕5 小时前
中文Windows系统下程序输出重定向乱码问题解决方案
rust·编码·powershell
我爱Jack5 小时前
@annotation:Spring AOP 的“精准定位器“
java·后端·spring
云资源服务商5 小时前
探索阿里云网络与CDN产品:解锁高效网络体验
服务器·网络·阿里云·云计算
一ge科研小菜鸡5 小时前
编程语言的演化与选择:技术浪潮中的理性决策
java·c语言·python
我崽不熬夜5 小时前
为什么你该立即学习 Java 的 Lambda 表达式?
java·后端·java ee