#objective-c #macos #ios #encode

no-std objc2-encode

Objective-C type-encoding representation and parsing

11 releases (1 stable)

2.0.0-pre.4 Feb 7, 2023
2.0.0-pre.3 Dec 24, 2022
2.0.0-pre.2 Aug 28, 2022
2.0.0-pre.1 Jul 19, 2022
1.1.0 Nov 19, 2021

#10 in macOS and iOS APIs

Download history 1339/week @ 2022-11-26 1578/week @ 2022-12-03 2301/week @ 2022-12-10 1770/week @ 2022-12-17 1434/week @ 2022-12-24 1888/week @ 2022-12-31 1944/week @ 2023-01-07 1596/week @ 2023-01-14 2390/week @ 2023-01-21 2937/week @ 2023-01-28 6748/week @ 2023-02-04 8124/week @ 2023-02-11 7169/week @ 2023-02-18 7451/week @ 2023-02-25 8237/week @ 2023-03-04 7940/week @ 2023-03-11

32,218 downloads per month

MIT license

72KB
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 just 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);
# Ok::<(), objc2_encode::ParseError>(())

Further resources

No runtime deps

Features

  • alloc
  • std