-
Notifications
You must be signed in to change notification settings - Fork 63
Description
icrate (or whatever it'll end up being named) is nearing an initial version, see #264.
After that, we need to figure out how we should handle name translation for enums, method names, and so on. There are a few options:
- Use Objective-C naming scheme:
- Framework:
Foundation - Class:
struct NSObject - Protocol:
struct NSCopying - Category:
trait NSAccessibility; impl NSAccessibility for NSObject;(or perhapsNSObject_NSAccessibility?) - Method:
fn someMethod(arg: i32),fn someMethod_withExtraParam(arg: i32, extra: u32) - Method returning error:
fn aMethod_error(arg: i32) -> Result<(), Id<NSError>> - Method with callback:
async fn aMethodWithCompletionHandler(f: &Block<(), ()>), see alsoasyncsupport #279 - Enum:
struct NSAccessibilityAnnotationPosition(NSInteger) - Enum constant:
const NSAccessibilityAnnotationPositionFullRange: NSAccessibilityAnnotationPosition = ... - Struct:
struct NSDirectionalEdgeInsets { fields* } - Constant:
const NSModalResponseStop: NSModalResponse = 1000 - Typedef:
struct NSBitmapImageRepPropertyKey(NSString) - Static:
extern "C" { static NSImageCurrentFrameDuration: NSBitmapImageRepPropertyKey } - Function:
extern "C" { fn NSBitsPerPixelFromDepth(depth: NSWindowDepth) -> NSInteger }
- Use a scheme similar to Swift's
- Framework:
Foundation - Class: Same, sometimes renamed?
- Protocol: Same
- Category: Same
- Method:
fn some(method: i32),fn some_with(method: i32, extraParam: u32)(name is significantly stripped) - Method returning error:
fn a(arg: i32) -> Result<(), Id<NSError>>(errorpostfix is removed) - Method with callback:
async fn a()(WithCompletionHandlerstripped) - Enum:
struct NSAccessibilityAnnotationPosition(NSInteger), Swift usually creates a nested items likeNSAccessibility::AnnotationPosition, but that is not possible in Rust - Enum constant:
impl NSAccessibilityAnnotationPosition { const fullRange: Self = ... } - Struct:
struct NSDirectionalEdgeInsets { fields* } - Constant:
impl NSModalResponse { const stop: Self = 1000 } - Typedef:
struct NSBitmapImageRepPropertyKey(NSString) - Static:
impl NSBitmapImageRepPropertyKey { fn currentFrameDuration() -> &'static Self }, associated statics are not possible in Rust yet so we must create a new function that can return it (also if we want to make it safe) - Function:
impl NSWindowDepth { fn bitsPerPixel() -> NSInteger }
- Come up with a custom, "Rusty" scheme based on option 2
- Framework:
foundation - Class: Same
- Protocol: Same
- Category: Same
- Method:
fn some_long_method_name(method: i32), method name is made always lowercase (note: difficult now to tell which selector it corresponds to) - Method returning error: Same
- Method with callback: Same
- Enum: Same
- Enum constant:
impl NSAccessibilityAnnotationPosition { const FULL_RANGE: Self = ... }, constant is uppercase - Struct: Same
- Constant:
impl NSModalResponse { const STOP: Self = 1000 }, constant is uppercase - Typedef: Same
- Static:
impl NSBitmapImageRepPropertyKey { fn current_frame_duration() -> &'static Self }, function is made lowercase, in the future if we get associated statics then the name would change to be uppercase - Function:
impl NSWindowDepth { fn bits_per_pixel() -> NSInteger }, function is made lowercase
I like option 1 since it'll mean that things are more "searchable"/"grepable". This point also somewhat goes for option 2, though a bit less so, since Swift is newer. The downside to both of these is of course that the names don't really match Rust's naming conventions.
Implementation wise: Option 1 is already implemented, so that's easy. Option 2 has seen a lot of work already by Apple/Swift developers, and they've even created the .apinotes system to help with edge-cases. Option 3 would be quite easy on top of 2, but would require a bit extra work if we want to tweak names further afterwards.