objc-encode

Crates.ioobjc-encode
lib.rsobjc-encode
version1.1.0
sourcesrc
created_at2017-02-19 08:51:20.100203
updated_at2019-10-16 05:06:48.800272
descriptionObjective-C type encoding creation and parsing in Rust.
homepage
repositoryhttp://github.com/SSheldon/rust-objc-encode
max_upload_size
id8579
size15,911
Steven Sheldon (SSheldon)

documentation

http://ssheldon.github.io/rust-objc/objc_encode/

README

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");
Commit count: 0

cargo fmt