1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! # Objective-C type-encoding
//!
//! The Objective-C directive `@encode` encodes types as strings, and this is
//! used in various places in the runtime.
//!
//! This crate provides the [`Encoding`] type to describe and compare these
//! type-encodings, and the [`EncodingBox`] type which does the same, except
//! it can be parsed from an encoding at runtime.
//!
//! The types from this crate is exported under the [`objc2`] crate as
//! `objc2::encode`, so usually you would use it from there.
//!
//! [`objc2`]: https://crates.io/crates/objc2
//!
//!
//! ## Example
//!
//! Parse an encoding from a string and compare it to a known encoding.
//!
//! ```rust
//! use objc2_encode::{Encoding, EncodingBox};
//! let s = "{s=i}";
//! let enc = Encoding::Struct("s", &[Encoding::Int]);
//! let parsed: EncodingBox = s.parse()?;
//! assert!(enc.equivalent_to_box(&parsed));
//! assert_eq!(enc.to_string(), s);
//! # Ok::<(), objc2_encode::ParseError>(())
//! ```
//!
//!
//! ## Further resources
//!
//! - [Objective-C, Encoding and You](https://dmaclach.medium.com/objective-c-encoding-and-you-866624cc02de).
//! - [Apple's documentation on Type Encodings](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html).
//! - [How are the digits in ObjC method type encoding calculated?](https://stackoverflow.com/a/11527925)
//! - [`clang`'s source code for generating `@encode`](https://github.com/llvm/llvm-project/blob/fae0dfa6421ea6c02f86ba7292fa782e1e2b69d1/clang/lib/AST/ASTContext.cpp#L7500-L7850).
// Update in Cargo.toml as well.
compile_error!;
extern crate std;
extern crate alloc;
// Will be used at some point when generic constants are available
pub use Encoding;
pub use EncodingBox;
pub use ParseError;