use crate::Library;
use crate::img;
use crate::os;
use std::path;
use std::ptr;
#[cfg(unix)]
use os::unix as imp;
#[cfg(windows)]
use os::windows as imp;
#[derive(Debug, Clone)]
pub struct Weak {
pub(crate) base_addr: *const img::Image,
pub(crate) path_name: Option<path::PathBuf>,
}
impl crate::sealed::Sealed for Weak {}
impl Default for Weak {
fn default() -> Self {
Self {
base_addr: ptr::null(),
path_name: None,
}
}
}
impl Weak {
#[inline]
pub const fn new() -> Self {
Self {
base_addr: ptr::null(),
path_name: None,
}
}
pub fn upgrade(&self) -> Option<Library> {
unsafe { imp::InnerLibrary::from_ptr(self.base_addr.cast_mut()) }.map(Library)
}
#[inline]
pub fn to_ptr(&self) -> *const img::Image {
unsafe { imp::base_addr(self.base_addr.cast_mut().cast()) }
}
#[inline]
pub fn path(&self) -> Option<&path::Path> {
self.path_name.as_deref()
}
}