use core::fmt; use core::panic::{RefUnwindSafe, UnwindSafe};
use objc2::encode::{Encode, Encoding, RefEncode}; use objc2::rc::{Allocated, Retained}; use objc2::runtime::NSObject; use objc2::{extern_methods, msg_send, AnyThread};
usecrate::{util, NSUUID};
impl UnwindSafe for NSUUID {} impl RefUnwindSafe for NSUUID {}
#[repr(transparent)] struct UuidBytes([u8; 16]);
unsafeimpl RefEncode for UuidBytes { // Encoding actually depends on the instance class, `__NSConcreteUUID` has // a different method encoding than `NSUUID`, the former takes a `char*`. // // This may also depend on the Foundation / OS version. const ENCODING_REF: Encoding = Encoding::Array(16, &u8::ENCODING);
}
/// Create a new `NSUUID` from the given bytes. /// /// NOTE: The headers describe `initWithUUIDBytes:` as taking `uuid_t`, /// but their actual implementation may use something else. /// /// Thus, to use this method, you must currently disable encoding /// verification using the `"disable-encoding-assertions"` Cargo feature /// in `objc2`. /// /// /// # Example /// /// Create a new `NSUUID` from the `uuid` crate. /// /// ```ignore /// use uuid::Uuid; /// use objc2_foundation::NSUUID; /// /// let uuid: Uuid; /// # uuid = todo!(); /// let obj = NSUUID::from_bytes(uuid.into_bytes()); /// assert_eq!(obj.as_bytes(), uuid.into_bytes()); /// ``` pubfn from_bytes(bytes: [u8; 16]) -> Retained<Self> { let bytes = UuidBytes(bytes); Self::initWithUUIDBytes(Self::alloc(), &bytes)
}
/// Convert the UUID to an array. /// /// NOTE: The headers describe `getUUIDBytes:` as taking `uuid_t`, but /// their actual implementation may use something else. /// /// Thus, to use this method, you must currently disable encoding /// verification using the `"disable-encoding-assertions"` Cargo feature /// in `objc2`. pubfn as_bytes(&self) -> [u8; 16] { letmut bytes = UuidBytes([0; 16]); self.getUUIDBytes(&mut bytes);
bytes.0
}
}
impl fmt::Debug for NSUUID { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // The `uuid` crate does `Debug` and `Display` equally, and so do we.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.