Source code

Revision control

Copy as Markdown

Other Tools

//! # 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.
//!
//! ```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
//!
//! - [How are the digits in ObjC method type encoding calculated?](https://stackoverflow.com/a/11527925)
#![no_std]
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
#![warn(clippy::missing_errors_doc)]
#![warn(clippy::missing_panics_doc)]
// Update in Cargo.toml as well.
#![doc(html_root_url = "https://docs.rs/objc2-encode/4.1.0")]
#[cfg(not(feature = "alloc"))]
compile_error!("the `alloc` feature currently must be enabled");
extern crate alloc;
#[cfg(any(feature = "std", doc))]
extern crate std;
mod encoding;
mod encoding_box;
mod helper;
mod parse;
// Will be used at some point when generic constants are available
#[allow(dead_code)]
mod static_str;
pub use self::encoding::Encoding;
pub use self::encoding_box::EncodingBox;
pub use self::parse::ParseError;