use core::fmt;
use core::panic::{RefUnwindSafe, UnwindSafe};
use crate::ffi;
#[cfg(feature = "gnustep-1-7")]
use crate::Encode;
use crate::{Encoding, RefEncode};
pub struct NSZone {
_inner: ffi::objc_object,
}
impl fmt::Debug for NSZone {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<NSZone {:p}>", self)
}
}
impl UnwindSafe for NSZone {}
impl RefUnwindSafe for NSZone {}
unsafe impl RefEncode for NSZone {
#[cfg(feature = "apple")]
const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("_NSZone", &[]));
#[cfg(feature = "gnustep-1-7")]
const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct(
"_NSZone",
&[
Encoding::Pointer(&Encoding::Unknown),
Encoding::Pointer(&Encoding::Unknown),
Encoding::Pointer(&Encoding::Unknown),
Encoding::Pointer(&Encoding::Unknown),
Encoding::Pointer(&Encoding::Unknown),
Encoding::Pointer(&Encoding::Unknown),
Encoding::Pointer(&Encoding::Unknown),
usize::ENCODING,
Encoding::Object,
Encoding::Pointer(&Encoding::Struct("_NSZone", &[])),
],
));
}
#[cfg(test)]
mod tests {
use alloc::string::ToString;
use core::ptr;
use super::*;
use crate::foundation::NSObject;
use crate::msg_send_id;
use crate::rc::{Allocated, Id, Owned};
use crate::ClassType;
#[test]
fn alloc_with_zone() {
let zone: *const NSZone = ptr::null();
let _obj: Id<Allocated<NSObject>, Owned> =
unsafe { msg_send_id![NSObject::class(), allocWithZone: zone] };
}
#[test]
fn verify_encoding() {
let expected = if cfg!(all(feature = "gnustep-1-7", target_pointer_width = "64")) {
"^{_NSZone=^?^?^?^?^?^?^?Q@^{_NSZone}}"
} else if cfg!(all(
feature = "gnustep-1-7",
not(target_pointer_width = "64")
)) {
"^{_NSZone=^?^?^?^?^?^?^?I@^{_NSZone}}"
} else {
"^{_NSZone=}"
};
assert_eq!(NSZone::ENCODING_REF.to_string(), expected);
}
}