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() { gbufpos=*chr;

}

for i in 0...len{

let chr= gbufi;

let pos=i;

println!("gbuf idx {},val {:x}!", pos, chr);

}

}

info!("testdumphexptr end!");

0

}

···

···

相关推荐
YatHinLay几秒前
Spring Boot + Calcite 实现跨库查询
java
剑指offer.6 分钟前
ARM裸机开发-点亮LED灯
linux·服务器·嵌入式硬件
酷炫码神23 分钟前
MosMos 创意效果与能力边界展示
java
Wang's Blog29 分钟前
Java 接入Redis: 使用Jedis操作Redis
java·服务器·redis
事圆则缓33 分钟前
Java 8 Lambda、Stream、Optional 与 Android 边界:从回调语法到运行时兼容
android·java
shehuiyuelaiyuehao41 分钟前
算法50,分治归并,数组中的逆序对
java·算法
烽学长43 分钟前
(附源码)基于Springboot+vue的图书阅读分享系统的设计与实现
java·spring boot·后端
Ivanqhz1 小时前
数据搬运是性能关键
java·服务器·网络·人工智能·深度学习
其实防守也摸鱼1 小时前
常见安全架构中 Shiro 的认证确认机制解析
运维·服务器·数据库·windows·github
青山木1 小时前
RocketMQ 入门到原理(三):消息存储原理
java·后端·中间件·架构·rocketmq