objc_encode/lib.rs
1/*!
2Objective-C type encoding creation and parsing in Rust.
3
4The Objective-C compiler encodes types as strings for usage in the runtime.
5This crate aims to provide a strongly-typed (rather than stringly-typed) way
6to create and describe these type encodings without memory allocation in Rust.
7
8# Implementing Encode
9
10This crate declares an `Encode` trait that can be implemented for types that
11the Objective-C compiler can encode. Implementing this trait looks like:
12
13``` ignore
14unsafe impl Encode for CGPoint {
15 const ENCODING: Encoding<'static> =
16 Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFLOAT::ENCODING]);
17}
18```
19
20For an example of how this works with more complex types, like structs
21containing structs, see the `core_graphics` example.
22
23# Comparing with encoding strings
24
25An `Encoding` can be compared with an encoding string from the Objective-C
26runtime:
27
28```
29# use objc_encode::Encode;
30assert!(&i32::ENCODING == "i");
31```
32
33# Generating encoding strings
34
35Every `Encoding` implements `Display` as its string representation.
36This can be generated conveniently through the `to_string` method:
37
38```
39# use objc_encode::Encode;
40assert_eq!(i32::ENCODING.to_string(), "i");
41```
42*/
43
44#![no_std]
45
46#[cfg(test)]
47extern crate std;
48
49mod encoding;
50mod encode;
51mod parse;
52
53pub use crate::encoding::Encoding;
54pub use crate::encode::Encode;