use crate::binds::MonoImage;
#[derive(Copy, Clone)]
pub struct Image {
img_ptr: *mut MonoImage,
}
#[allow(unused_imports)]
use crate::binds::MonoAssembly; use crate::metadata::{MetadataTableInfo, MetadataTableKind, MetadataToken};
use std::ffi::CString;
impl Image {
#[must_use]
pub fn get_table_info(&self, kind: MetadataTableKind) -> MetadataTableInfo {
unsafe {
MetadataTableInfo::from_ptr(
crate::binds::mono_image_get_table_info(self.img_ptr, kind as i32),
kind,
)
}
}
#[must_use]
pub fn metadata_string_heap(&self, index: MetadataToken) -> String {
let cstr = unsafe {
CString::from_raw(
crate::binds::mono_metadata_string_heap(self.img_ptr, index) as *mut i8
)
};
let res = cstr.to_str().expect(crate::CSTR2STR_ERR).to_owned();
let _ = cstr.into_raw();
res
}
#[must_use]
pub unsafe fn from_ptr(ptr: *mut crate::binds::MonoImage) -> Self {
Self { img_ptr: ptr }
}
#[must_use]
pub fn get_ptr(&self) -> *mut MonoImage {
self.img_ptr
}
pub fn init(&self) {
unsafe { crate::binds::mono_image_init(self.img_ptr) };
}
#[must_use]
pub fn get_name(&self) -> String {
let ptr = unsafe { crate::binds::mono_image_get_name(self.img_ptr) };
let cstr = unsafe { CString::from_raw(ptr as *mut i8) };
let name = cstr.to_str().expect(crate::STR2CSTR_ERR).to_owned();
let _ = cstr.into_raw();
name
}
pub unsafe fn close(&mut self) {
crate::binds::mono_image_close(self.img_ptr);
let _ = &self;
}
}