/// The boxed version of [`Encoding`]. /// /// This has exactly the same items as `Encoding`, the only difference is in /// where the contents of the more complex encodings like [`Struct`] are /// stored. /// /// In `Encoding`, the data is stored in static memory, while in `EncodingBox` /// it is stored on the heap. The former allows storing in constants (which is /// required by the `objc2::encode::Encode` and `objc2::encode::RefEncode` /// traits), while the latter allows dynamic creation, such as in the case of /// parsing encodings. /// /// **This should be considered a _temporary_ restriction**. `Encoding` and /// `EncodingBox` will become equivalent once heap allocation in constants /// is possible. /// /// [`Struct`]: Self::Struct #[derive(Clone, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] // Maybe we're missing some encodings? pubenum EncodingBox { /// Same as [`Encoding::Char`].
Char, /// Same as [`Encoding::Short`].
Short, /// Same as [`Encoding::Int`].
Int, /// Same as [`Encoding::Long`].
Long, /// Same as [`Encoding::LongLong`].
LongLong, /// Same as [`Encoding::UChar`].
UChar, /// Same as [`Encoding::UShort`].
UShort, /// Same as [`Encoding::UInt`].
UInt, /// Same as [`Encoding::ULong`].
ULong, /// Same as [`Encoding::ULongLong`].
ULongLong, /// Same as [`Encoding::Float`].
Float, /// Same as [`Encoding::Double`].
Double, /// Same as [`Encoding::LongDouble`].
LongDouble, /// Same as [`Encoding::FloatComplex`].
FloatComplex, /// Same as [`Encoding::DoubleComplex`].
DoubleComplex, /// Same as [`Encoding::LongDoubleComplex`].
LongDoubleComplex, /// Same as [`Encoding::Bool`].
Bool, /// Same as [`Encoding::Void`].
Void, /// Same as [`Encoding::String`].
String, /// Same as [`Encoding::Object`].
Object, /// Same as [`Encoding::Block`].
Block, /// Same as [`Encoding::Class`].
Class, /// Same as [`Encoding::Sel`].
Sel, /// Same as [`Encoding::Unknown`].
Unknown, /// Same as [`Encoding::BitField`].
BitField(u8, Option<Box<(u64, Self)>>), /// Same as [`Encoding::Pointer`].
Pointer(Box<Self>), /// Same as [`Encoding::Atomic`].
Atomic(Box<Self>), /// Same as [`Encoding::Array`].
Array(u64, Box<Self>), /// Same as [`Encoding::Struct`]. Struct(String, Vec<Self>), /// Same as [`Encoding::Union`].
Union(String, Vec<Self>), /// Same as [`Encoding::None`].
None,
}
impl EncodingBox { /// Same as [`Encoding::C_LONG`]. pubconst C_LONG: Self = match Encoding::C_LONG {
Encoding::Long => Self::Long,
Encoding::LongLong => Self::LongLong,
_ => unreachable!(),
};
/// Same as [`Encoding::C_ULONG`]. pubconst C_ULONG: Self = match Encoding::C_ULONG {
Encoding::ULong => Self::ULong,
Encoding::ULongLong => Self::ULongLong,
_ => unreachable!(),
};
/// Parse and consume an encoding from the start of a string. /// /// This is can be used to parse concatenated encodings, such as those /// returned by `method_getTypeEncoding`. /// /// [`from_str`][Self::from_str] is simpler, use that instead if you can. /// /// /// # Errors /// /// Returns an error if the string was an ill-formatted encoding string. pubfn from_start_of_str(s: &mut &str) -> Result<Self, ParseError> { letmut parser = Parser::new(s);
parser.strip_leading_qualifiers();
match parser.parse_encoding_or_none() {
Err(ErrorKind::Unknown(b'0'..=b'9')) => { let remaining = parser.remaining();
*s = remaining;
#[test] fn parse_atomic_struct() { let expected = EncodingBox::Atomic(Box::new(EncodingBox::Atomic(Box::new(
EncodingBox::Struct("a".into(), vec![]),
)))); let actual = EncodingBox::from_str("AA{a=}").unwrap();
assert_eq!(expected, actual);
assert_eq!(expected.to_string(), "AA{a}");
let actual = EncodingBox::from_str("AA{a}").unwrap();
assert_eq!(expected, actual);
assert_eq!(expected.to_string(), "AA{a}");
}
#[test] fn parse_part_of_string() { letmut s = "{a}cb0i16";
let expected = EncodingBox::Struct("a".into(), vec![]); let actual = EncodingBox::from_start_of_str(&mut s).unwrap();
assert_eq!(expected, actual);
let expected = EncodingBox::Char; let actual = EncodingBox::from_start_of_str(&mut s).unwrap();
assert_eq!(expected, actual);
let expected = EncodingBox::BitField(16, Some(Box::new((0, EncodingBox::Int)))); let actual = EncodingBox::from_start_of_str(&mut s).unwrap();
assert_eq!(expected, actual);
assert_eq!(s, "");
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.