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

}

···

···

相关推荐
IMPYLH6 小时前
Linux 的 pinky 命令
linux·运维·服务器·bash
dllxhcjla6 小时前
微服务全套
java
亚历克斯神6 小时前
JVM 内存管理 2026:深度解析与调优实战
java·spring·微服务
REDcker6 小时前
Linux iptables 与 Netfilter:原理、路径与运维要点
linux·运维·服务器
逻辑驱动的ken7 小时前
Java高频面试题:03
java·开发语言·面试·求职招聘·春招
广师大-Wzx7 小时前
一篇文章看懂MySQL数据库(下)
java·开发语言·数据结构·数据库·windows·python·mysql
野生技术架构师7 小时前
Java NIO到底是个什么东西?
java·开发语言·nio
likerhood9 小时前
简单工厂设计模式
java·ide·intellij-idea
派大星酷9 小时前
Java 调用 Kimi API 实战:实现与大模型的简单对话
java·开发语言·ai编程
无忧.芙桃10 小时前
进程控制(上)
linux·运维·服务器