Enum objc2::Encoding[][src]

#[non_exhaustive]
pub enum Encoding<'a> {
Show 29 variants Char, Short, Int, Long, LongLong, UChar, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, FloatComplex, DoubleComplex, LongDoubleComplex, Bool, Void, String, Object, Block, Class, Sel, Unknown, BitField(u8), Pointer(&'a Encoding<'a>), Array(usize, &'a Encoding<'a>), Struct(&'a str&'a [Encoding<'a>]), Union(&'a str&'a [Encoding<'a>]),
}
Expand description

An Objective-C type-encoding.

Can be retrieved in Objective-C for a type T using the @encode(T) directive.

NSLog(@"Encoding of NSException: %s", @encode(NSException));

The Display implementation converts the Encoding into its string representation, that the the @encode directive would return. This can be used conveniently through the to_string method:

use objc2_encode::Encoding;
assert_eq!(Encoding::Int.to_string(), "i");

For more information on the string value of an encoding, see Apple’s documentation.

Examples

Comparing an encoding to a string from the Objective-C runtime:

use objc2_encode::Encoding;
assert!(Encoding::Array(10, &Encoding::FloatComplex).equivalent_to_str("[10jf]"));

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.

Char

A C char. Corresponds to the c code.

Short

A C short. Corresponds to the s code.

Int

A C int. Corresponds to the i code.

Long

A C long. Corresponds to the l code.

LongLong

A C long long. Corresponds to the q code.

UChar

A C unsigned char. Corresponds to the C code.

UShort

A C unsigned short. Corresponds to the S code.

UInt

A C unsigned int. Corresponds to the I code.

ULong

A C unsigned long. Corresponds to the L code.

ULongLong

A C unsigned long long. Corresponds to the Q code.

Float

A C float. Corresponds to the f code.

Double

A C double. Corresponds to the d code.

LongDouble

A C long double. Corresponds to the D code.

FloatComplex

A C float _Complex. Corresponds to the jf code.

DoubleComplex

A C _Complex or double _Complex. Corresponds to the jd code.

LongDoubleComplex

A C long double _Complex. Corresponds to the jD code.

Bool

A C++ bool / C99 _Bool. Corresponds to the B code.

Void

A C void. Corresponds to the v code.

String

A C char *. Corresponds to the * code.

Object

An Objective-C object (id). Corresponds to the @ code.

Block

An Objective-C block. Corresponds to the @? code.

Class

An Objective-C class (Class). Corresponds to the # code.

Sel

An Objective-C selector (SEL). Corresponds to the : code.

Unknown

An unknown type. Corresponds to the ? code.

This is usually used to encode functions.

BitField(u8)

Tuple Fields

0: u8

A bitfield with the given number of bits.

Corresponds to the bnum code.

Pointer(&'a Encoding<'a>)

Tuple Fields

0: &'a Encoding<'a>

A pointer to the given type.

Corresponds to the ^type code.

Array(usize, &'a Encoding<'a>)

Tuple Fields

0: usize
1: &'a Encoding<'a>

An array with the given length and type.

Corresponds to the [len type] code.

Struct(&'a str&'a [Encoding<'a>])

Tuple Fields

0: &'a str

A struct with the given name and fields.

The order of the fields must match the order of the order in this.

It is not uncommon for the name to be "?".

Corresponds to the {name=fields...} code.

Union(&'a str&'a [Encoding<'a>])

Tuple Fields

0: &'a str

A union with the given name and fields.

The order of the fields must match the order of the order in this.

Corresponds to the (name=fields...) code.

Implementations

Check if one encoding is equivalent to another.

Check if an encoding is equivalent to the given string representation.

Check if an encoding is equivalent to the start of the given string representation.

If it is equivalent, the remaining part of the string is returned. Otherwise this returns None.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Partial equality between an Encoding and a str.

Using this is heavily discouraged, since it is not transitive; use Encoding::equivalent_to_str instead for more correct semantics.

Using this is discouraged.

Using this is discouraged.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Partial equality between an Encoding and a str.

Using this is heavily discouraged, since it is not transitive; use Encoding::equivalent_to_str instead for more correct semantics.

Using this is discouraged.

Using this is discouraged.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.