raw ptr for map observer

This commit is contained in:
Dominik Maier 2020-10-29 11:35:34 +01:00
parent ac4e71390a
commit a42b787eb5

View File

@ -1,5 +1,5 @@
use crate::AflError; use crate::AflError;
use std::cell::RefCell; use std::slice::from_raw_parts;
pub trait Observer { pub trait Observer {
fn flush(&mut self) -> Result<(), AflError> { fn flush(&mut self) -> Result<(), AflError> {
@ -16,14 +16,14 @@ pub trait Observer {
pub trait MapObserver<MapT>: Observer { pub trait MapObserver<MapT>: Observer {
// TODO: Rust // TODO: Rust
fn get_map(&self) -> &RefCell<Vec<MapT>>; fn get_map(&self) -> &[MapT];
//fn get_map_mut(&mut self) -> &mut Vec<MapT>; //fn get_map_mut(&mut self) -> &mut Vec<MapT>;
} }
pub struct U8MapObserver { pub struct U8MapObserver {
map: RefCell<Vec<u8>>, map: &'static [u8],
} }
@ -38,15 +38,18 @@ impl Observer for U8MapObserver {
impl MapObserver<u8> for U8MapObserver { impl MapObserver<u8> for U8MapObserver {
fn get_map(&self) -> &RefCell<Vec<u8>> { // TODO: Rust
// TODO: Rust this better fn get_map(&self) -> &[u8] {
return &self.map; return self.map;
} }
//fn get_map_mut(&mut self) -> &mut Vec<MapT>;
} }
impl U8MapObserver { impl U8MapObserver {
pub fn new(map: RefCell<Vec<u8>>) -> Self { pub fn new(map_ptr: *const u8, len: usize) -> Self {
U8MapObserver{map: map} unsafe {
U8MapObserver{map: from_raw_parts(map_ptr, len)}
}
} }
} }