1
+ # `` objc-encode ``
2
+
3
+ [ ![ Crates.io] ( https://img.shields.io/crates/v/objc-encode.svg )] ( https://crates.io/crates/objc-encode )
4
+ [ ![ Docs.rs] ( https://docs.rs/objc-encode/badge.svg )] ( https://docs.rs/objc-encode/ )
5
+
1
6
Objective-C type encoding creation and parsing in Rust.
2
7
3
8
The Objective-C compiler encodes types as strings for usage in the runtime.
4
9
This crate aims to provide a strongly-typed (rather than stringly-typed) way
5
10
to create and describe these type encodings without memory allocation in Rust.
6
11
7
- # Implementing Encode
12
+
13
+ ## Implementing Encode
8
14
9
15
This crate declares an ` Encode ` trait that can be implemented for types that
10
16
the Objective-C compiler can encode. Implementing this trait looks like:
11
17
12
- ``` rust
18
+ ``` rust
13
19
unsafe impl Encode for CGPoint {
14
20
const ENCODING : Encoding <'static > =
15
21
Encoding :: Struct (" CGPoint" , & [CGFloat :: ENCODING , CGFLOAT :: ENCODING ]);
@@ -19,20 +25,20 @@ unsafe impl Encode for CGPoint {
19
25
For an example of how this works with more complex types, like structs
20
26
containing structs, see the ` core_graphics ` example.
21
27
22
- # Comparing with encoding strings
28
+ ## Comparing with encoding strings
23
29
24
30
An ` Encoding ` can be compared with an encoding string from the Objective-C
25
31
runtime:
26
32
27
- ``` rust
33
+ ``` rust
28
34
assert! (& i32 :: ENCODING == " i" );
29
35
```
30
36
31
- # Generating encoding strings
37
+ ## Generating encoding strings
32
38
33
39
Every ` Encoding ` implements ` Display ` as its string representation.
34
40
This can be generated conveniently through the ` to_string ` method:
35
41
36
- ``` rust
42
+ ``` rust
37
43
assert_eq! (i32 :: ENCODING . to_string (), " i" );
38
44
```
0 commit comments