#objective-c #macos-ios #macos #ios #encode

no-std objc2-encode

Objective-C type-encoding representation and parsing

15 releases (5 stable)

4.0.1 Apr 17, 2024
4.0.0 Dec 3, 2023
3.0.0 Jul 31, 2023
2.0.0 Jun 20, 2023
1.1.0 Nov 19, 2021

#172 in macOS and iOS APIs

Download history 39410/week @ 2024-01-09 41224/week @ 2024-01-16 42714/week @ 2024-01-23 39546/week @ 2024-01-30 46962/week @ 2024-02-06 45281/week @ 2024-02-13 40648/week @ 2024-02-20 48755/week @ 2024-02-27 48931/week @ 2024-03-05 49372/week @ 2024-03-12 51926/week @ 2024-03-19 56803/week @ 2024-03-26 44872/week @ 2024-04-02 50493/week @ 2024-04-09 54003/week @ 2024-04-16 50998/week @ 2024-04-23

208,400 downloads per month
Used in 1,447 crates (via objc2)

MIT license

75KB
1.5K SLoC

objc2-encode

Latest version License Documentation CI

Objective-C type-encoding in Rust.

This crates provides types to parse and compare Objective-C type-encodings created with the @encode directive.

See the docs for a more thorough overview.

This crate is part of the objc2 project, see that for related crates.


lib.rs:

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.

Example

Parse an encoding from a string and compare it to a known encoding.

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);

Further resources

No runtime deps

Features