objc2 icon indicating copy to clipboard operation
objc2 copied to clipboard

Follow the Rust API Guidelines - Checklist

Open madsmtm opened this issue 2 years ago • 4 comments

Mostly relevant for objc2_foundation/objc2::rc, which are the "real" user-facing APIs.

Rust API Guidelines Checklist

  • Naming (crate aligns with Rust naming conventions)
    • [x] Casing conforms to RFC 430 (C-CASE)
    • [x] Ad-hoc conversions follow as_, to_, into_ conventions (C-CONV)
    • [x] Getter names follow Rust convention (C-GETTER)
    • [x] Methods on collections that produce iterators follow iter, iter_mut, into_iter (C-ITER)
    • [ ] Iterator type names match the methods that produce them (C-ITER-TY)
    • [x] Feature names are free of placeholder words (C-FEATURE)
    • [x] Names use a consistent word order (C-WORD-ORDER)
  • Interoperability (crate interacts nicely with other library functionality)
    • [ ] Types eagerly implement common traits (C-COMMON-TRAITS)
      • Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display, Default
    • [ ] Conversions use the standard traits From, AsRef, AsMut (C-CONV-TRAITS)
    • [ ] Collections implement FromIterator and Extend (C-COLLECT)
    • [ ] Data structures implement Serde's Serialize, Deserialize (C-SERDE)
    • [x] Types are Send and Sync where possible (C-SEND-SYNC)
    • [x] Error types are meaningful and well-behaved (C-GOOD-ERR)
    • [ ] Binary number types provide Hex, Octal, Binary formatting (C-NUM-FMT)
    • [ ] Generic reader/writer functions take R: Read and W: Write by value (C-RW-VALUE)
  • Macros (crate presents well-behaved macros)
    • [x] Input syntax is evocative of the output (C-EVOCATIVE)
    • [x] Macros compose well with attributes (C-MACRO-ATTR)
    • [x] Item macros work anywhere that items are allowed (C-ANYWHERE)
    • [x] Item macros support visibility specifiers (C-MACRO-VIS)
    • [x] Type fragments are flexible (C-MACRO-TY)
  • Documentation (crate is abundantly documented)
    • [ ] Crate level docs are thorough and include examples (C-CRATE-DOC)
    • [ ] All items have a rustdoc example (C-EXAMPLE)
    • [ ] Examples use ?, not try!, not unwrap (C-QUESTION-MARK)
    • [ ] Function docs include error, panic, and safety considerations (C-FAILURE)
    • [x] Prose contains hyperlinks to relevant things (C-LINK)
    • [x] Cargo.toml includes all common metadata (C-METADATA)
      • authors, description, license, homepage, documentation, repository, keywords, categories
    • [x] Release notes document all significant changes (C-RELNOTES)
    • [x] Rustdoc does not show unhelpful implementation details (C-HIDDEN)
  • Predictability (crate enables legible code that acts how it looks)
    • [ ] Smart pointers do not add inherent methods (C-SMART-PTR)
    • [x] Conversions live on the most specific type involved (C-CONV-SPECIFIC)
    • [x] Functions with a clear receiver are methods (C-METHOD)
    • [x] Functions do not take out-parameters (C-NO-OUT)
    • [x] Operator overloads are unsurprising (C-OVERLOAD)
    • [ ] Only smart pointers implement Deref and DerefMut (C-DEREF)
    • [x] Constructors are static, inherent methods (C-CTOR)
  • Flexibility (crate supports diverse real-world use cases)
    • [ ] Functions expose intermediate results to avoid duplicate work (C-INTERMEDIATE)
    • [x] Caller decides where to copy and place data (C-CALLER-CONTROL)
    • [ ] Functions minimize assumptions about parameters by using generics (C-GENERIC)
    • [ ] Traits are object-safe if they may be useful as a trait object (C-OBJECT)
  • Type safety (crate leverages the type system effectively)
    • [x] Newtypes provide static distinctions (C-NEWTYPE)
    • [ ] Arguments convey meaning through types, not bool or Option (C-CUSTOM-TYPE)
    • [ ] Types for a set of flags are bitflags, not enums (C-BITFLAG)
    • [ ] Builders enable construction of complex values (C-BUILDER)
  • Dependability (crate is unlikely to do the wrong thing)
  • Debuggability (crate is conducive to easy debugging)
  • Future proofing (crate is free to improve without breaking users' code)
    • [ ] Sealed traits protect against downstream implementations (C-SEALED)
    • [x] Structs have private fields (C-STRUCT-PRIVATE)
    • [x] Newtypes encapsulate implementation details (C-NEWTYPE-HIDE)
    • [x] Data structures do not duplicate derived trait bounds (C-STRUCT-BOUNDS)
  • Necessities (to whom they matter, they really matter)
    • [x] Public dependencies of a stable crate are stable (C-STABLE)
    • [ ] Crate and its dependencies have a permissive license (C-PERMISSIVE)

madsmtm avatar Sep 05 '21 14:09 madsmtm

Also, investigate using ToOwned.

madsmtm avatar Sep 05 '21 14:09 madsmtm

I think we want to keep breaking C-SMART-PTR for Id::autorelease because that is a method name that only ever makes sense on Id

madsmtm avatar Oct 15 '21 01:10 madsmtm

#![warn(missing_debug_implementations)] can be helpful here

madsmtm avatar Nov 02 '21 14:11 madsmtm

We should also check all traits for whether they provide correct blanket impls (impl<T: Trait> Trait for &T, Box<T>, ...)

madsmtm avatar Apr 01 '22 20:04 madsmtm

I will consider most of this guideline as not really applicable to icrate, since most of the design questions there are handled by Apple, and not us.

Naming decisions in icrate are explicitly moved to https://github.com/madsmtm/objc2/issues/284

madsmtm avatar May 26 '23 09:05 madsmtm

I consider this basically done now, remaining parts are tracked in the linked issues

madsmtm avatar Sep 04 '23 15:09 madsmtm