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

}

···

···

相关推荐
Flash.kkl3 小时前
Linux——进程信号
运维·服务器
码出财富4 小时前
SpringBoot 内置的 20 个高效工具类
java·spring boot·spring cloud·java-ee
苏宸啊4 小时前
Linux权限
linux·运维·服务器
我是小疯子664 小时前
Python变量赋值陷阱:浅拷贝VS深拷贝
java·服务器·数据库
森叶5 小时前
Java 比 Python 高性能的原因:重点在高并发方面
java·开发语言·python
xqhoj5 小时前
Linux——make、makefile
linux·运维·服务器
二哈喇子!5 小时前
Eclipse中导入外部jar包
java·eclipse·jar
微露清风5 小时前
系统性学习C++-第二十二讲-C++11
java·c++·学习
lifejump5 小时前
Pikachu | XXE
服务器·web安全·网络安全·安全性测试
进阶小白猿5 小时前
Java技术八股学习Day20
java·开发语言·学习