#![allow(dead_code)] use core::{fmt, ptr::NonNull};
use objc2::runtime::__nsstring::nsstring_to_str; use objc2::{
rc::{autoreleasepool_leaking, Retained},
runtime::NSObject,
};
pub(crate) fn retained_ptr_cast<T: ?Sized>(objects: *mut Retained<T>) -> *mut NonNull<T> { // SAFETY: `Retained<T>` has the same memory layout as `NonNull<T>`, and // stronger guarantees.
objects.cast()
}
pub(crate) fn ref_ptr_cast_const<T: ?Sized>(objects: *const &T) -> *mut NonNull<T> { // SAFETY: `&T` has the same memory layout as `NonNull<T>`, and stronger // guarantees.
(objects as *mut &T).cast()
}
/// Display the string. /// /// Put here to allow using it without the `"NSString"` feature being active. /// /// # Safety /// /// The string must be an instance of `NSString`. pub(crate) unsafefn display_string(string: &NSObject, f: &mut fmt::Formatter<'_>) -> fmt::Result { // SAFETY: // - The caller upholds that the object is a `NSString`. // - We control the scope in which the string is alive, so we know // it is not moved outside the current autorelease pool. // // TODO: Use more performant APIs, maybe by copying bytes into a // temporary stack buffer so that we avoid allocating? // // Beware though that the string may be mutable internally, and that // mutation may happen on every call to the formatter `f` (so // `CFStringGetCharactersPtr` is probably out of the question, unless we // somehow check that the string is immutable?).
autoreleasepool_leaking(|pool| fmt::Display::fmt(unsafe { nsstring_to_str(string, pool) }, f))
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.