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

}

···

···

相关推荐
陈文锦丫4 小时前
MQ的学习
java·开发语言
乌暮4 小时前
JavaEE初阶---线程安全问题
java·java-ee
爱笑的眼睛114 小时前
GraphQL:从数据查询到应用架构的范式演进
java·人工智能·python·ai
Seven974 小时前
剑指offer-52、正则表达式匹配
java
代码or搬砖4 小时前
RBAC(权限认证)小例子
java·数据库·spring boot
青蛙大侠公主4 小时前
Thread及其相关类
java·开发语言
Coder_Boy_4 小时前
DDD从0到企业级:迭代式学习 (共17章)之 四
java·人工智能·驱动开发·学习
2301_768350235 小时前
MySQL为什么选择InnoDB作为存储引擎
java·数据库·mysql
派大鑫wink5 小时前
【Java 学习日记】开篇:以日记为舟,渡 Java 进阶之海
java·笔记·程序人生·学习方法
fegggye5 小时前
PyO3 Class 详解 - 在 Python 中使用 Rust 类
pytorch·rust