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

}

···

···

相关推荐
C雨后彩虹3 小时前
任务最优调度
java·数据结构·算法·华为·面试
heartbeat..3 小时前
Spring AOP 全面详解(通俗易懂 + 核心知识点 + 完整案例)
java·数据库·spring·aop
Jing_jing_X3 小时前
AI分析不同阶层思维 二:Spring 的事务在什么情况下会失效?
java·spring·架构·提升·薪资
元Y亨H5 小时前
Nacos - 服务发现
java·微服务
微露清风5 小时前
系统性学习C++-第十八讲-封装红黑树实现myset与mymap
java·c++·学习
dasi02275 小时前
Java趣闻
java
苏宸啊6 小时前
Linux指令篇(一)
linux·运维·服务器
阿波罗尼亚6 小时前
Tcp SSE Utils
android·java·tcp/ip
susu10830189116 小时前
springboot3.5.8整合minio8.5.9
java·springboot
不知道累,只知道类6 小时前
深入理解 Java 虚拟线程 (Project Loom)
java·开发语言