5 releases (2 stable)

1.1.0 Oct 16, 2019
1.0.0 Mar 25, 2019
0.0.3 Apr 30, 2017
0.0.2 Feb 20, 2017
0.0.1 Feb 19, 2017

#198 in macOS and iOS APIs

Download history 255/week @ 2024-07-21 378/week @ 2024-07-28 265/week @ 2024-08-04 372/week @ 2024-08-11 923/week @ 2024-08-18 792/week @ 2024-08-25 607/week @ 2024-09-01 734/week @ 2024-09-08 410/week @ 2024-09-15 450/week @ 2024-09-22 59/week @ 2024-09-29 130/week @ 2024-10-06 381/week @ 2024-10-13 463/week @ 2024-10-20 133/week @ 2024-10-27 27/week @ 2024-11-03

1,011 downloads per month

MIT license

16KB
358 lines

Objective-C type encoding creation and parsing in Rust.

The Objective-C compiler encodes types as strings for usage in the runtime. This crate aims to provide a strongly-typed (rather than stringly-typed) way to create and describe these type encodings without memory allocation in Rust.

Implementing Encode

This crate declares an Encode trait that can be implemented for types that the Objective-C compiler can encode. Implementing this trait looks like:

unsafe impl Encode for CGPoint {
    const ENCODING: Encoding<'static> =
        Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFLOAT::ENCODING]);
}

For an example of how this works with more complex types, like structs containing structs, see the core_graphics example.

Comparing with encoding strings

An Encoding can be compared with an encoding string from the Objective-C runtime:

assert!(&i32::ENCODING == "i");

Generating encoding strings

Every Encoding implements Display as its string representation. This can be generated conveniently through the to_string method:

assert_eq!(i32::ENCODING.to_string(), "i");

No runtime deps