-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Figure out naming scheme in icrate
#284
Comments
Also discussed previously in the |
I think we should stick with Objective-C naming at the very least until we can autogenerate documentation based on https://developer.apple.com/, since it's just much more discoverable that way - but I can be persuaded otherwise! |
The |
So far going through the Apple's documentation I've only came across one instance of where an instance method and type method has had the same name. The What do you think about having suffixes for methods like |
I'm a bit unsure about your terminology here; do you mean "instance method" and "protocol method"? In general my opinion is that adding prefixes or suffixes is unnecessary - to the user, it doesn't really matter if something is a method or a property, or defined on a class or on a protocol, the way they're used is exactly the same. Take for example Similarly, I don't think we need to differentiate between class and instance methods, since their usage is different enough from Rust that it is already quite clear: Of course, duplicate names do occur in such a way that we must change (e.g. |
I understand where your coming from and you made a good point :) |
Another possibility is to namespace enums, structs and typedefs behind modules (when it makes sense):
I considered namespacing the same was as Swift, e.g. Though perhaps we could then do |
mod ns {
struct Array<T>; // NSArray
struct String; // NSString
struct Number; // NSNumber
}
// Usage
use cidre::ns;
let array: ns::Array<ns::String> = ns::Array::new(); Which works pretty good for Foundation, but I'm not sure how well it extends to e.g. AppKit? |
I've pushed some of the |
I've pondered this for a while now, but at this point I feel like sticking close to Objective-C for method and function names is the correct approach, even though it's less "Rusty". That said, we still need to do some more work on the enum case prefix stripping, eliminating needless words in methods and on category naming. Currently, I think the naming scheme is going to be:
|
Implements the algorithm described in: https://github.com/swiftlang/swift/blob/swift-6.0.3-RELEASE/docs/CToSwiftNameTranslation.md#enum-style-prefix-stripping Examples: `NSWindowSharingType::NSWindowSharingNone -> NSWindowSharingType::None`. `MTLFeatureSet::_iOS_GPUFamily1_v1 -> MTLFeatureSet::iOS_GPUFamily1_v1`. `MTLSparsePageSize::MTLSparsePageSize16 -> MTLSparsePageSize::Size16`. Part of #284.
I've implemented the better enum case prefix stripping in a305d6f. |
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:
Foundation
struct NSObject
struct NSCopying
trait NSAccessibility; impl NSAccessibility for NSObject;
(or perhapsNSObject_NSAccessibility
?)fn someMethod(arg: i32)
,fn someMethod_withExtraParam(arg: i32, extra: u32)
fn aMethod_error(arg: i32) -> Result<(), Id<NSError>>
async fn aMethodWithCompletionHandler(f: &Block<(), ()>)
, see alsoasync
support #279struct NSAccessibilityAnnotationPosition(NSInteger)
const NSAccessibilityAnnotationPositionFullRange: NSAccessibilityAnnotationPosition = ...
struct NSDirectionalEdgeInsets { fields* }
const NSModalResponseStop: NSModalResponse = 1000
struct NSBitmapImageRepPropertyKey(NSString)
extern "C" { static NSImageCurrentFrameDuration: NSBitmapImageRepPropertyKey }
extern "C" { fn NSBitsPerPixelFromDepth(depth: NSWindowDepth) -> NSInteger }
Foundation
fn some(method: i32)
,fn some_with(method: i32, extraParam: u32)
(name is significantly stripped)fn a(arg: i32) -> Result<(), Id<NSError>>
(error
postfix is removed)async fn a()
(WithCompletionHandler
stripped)struct NSAccessibilityAnnotationPosition(NSInteger)
, Swift usually creates a nested items likeNSAccessibility::AnnotationPosition
, but that is not possible in Rustimpl NSAccessibilityAnnotationPosition { const fullRange: Self = ... }
struct NSDirectionalEdgeInsets { fields* }
impl NSModalResponse { const stop: Self = 1000 }
struct NSBitmapImageRepPropertyKey(NSString)
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)impl NSWindowDepth { fn bitsPerPixel() -> NSInteger }
foundation
fn some_long_method_name(method: i32)
, method name is made always lowercase (note: difficult now to tell which selector it corresponds to)impl NSAccessibilityAnnotationPosition { const FULL_RANGE: Self = ... }
, constant is uppercaseimpl NSModalResponse { const STOP: Self = 1000 }
, constant is uppercaseimpl 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 uppercaseimpl NSWindowDepth { fn bits_per_pixel() -> NSInteger }
, function is made lowercaseI 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.The text was updated successfully, but these errors were encountered: