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

}

···

···

相关推荐
SugarPPig9 分钟前
PowerShell 查询及刷新环境变量
服务器
Algorithm157612 分钟前
谈谈接口和抽象类有什么区别?
java·开发语言
YiSLWLL13 分钟前
使用Tauri 2.3.1+Leptos 0.7.8开发桌面小程序汇总
python·rust·sqlite·matplotlib·visual studio code
yu41062114 分钟前
Rust 语言使用场景分析
开发语言·后端·rust
细心的莽夫42 分钟前
SpringCloud 微服务复习笔记
java·spring boot·笔记·后端·spring·spring cloud·微服务
264玫瑰资源库2 小时前
问道数码兽 怀旧剧情回合手游源码搭建教程(反查重优化版)
java·开发语言·前端·游戏
pwzs2 小时前
Java 中 String 转 Integer 的方法与底层原理详解
java·后端·基础
东阳马生架构2 小时前
Nacos简介—2.Nacos的原理简介
java
普if加的帕3 小时前
java Springboot使用扣子Coze实现实时音频对话智能客服
java·开发语言·人工智能·spring boot·实时音视频·智能客服
我的作业错错错3 小时前
搭建私人网站
服务器·阿里云·私人网站