Skip to content

Commit

Permalink
encode: Add LongDouble, FloatComplex, DoubleComplex + LongDoubleComplex
Browse files Browse the repository at this point in the history
Found while working on objc_sys, there might be others we're missing so I've marked `Encoding` with `#[non_exhaustive]`
  • Loading branch information
madsmtm committed Nov 2, 2021
1 parent da177fc commit 0cfeefc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions objc2-encode/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::parse;
///
/// [ocrtTypeEncodings]: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive] // Maybe we're missing some encodings?
pub enum Encoding<'a> {
/// A C `char`. Corresponds to the `c` code.
Char,
Expand All @@ -39,6 +40,14 @@ pub enum Encoding<'a> {
Float,
/// A C `double`. Corresponds to the `d` code.
Double,
/// A C `long double`. Corresponds to the `D` code.
LongDouble,
/// A C `float _Complex`. Corresponds to the `jf` code.
FloatComplex,
/// A C `_Complex` or `double _Complex`. Corresponds to the `jd` code.
DoubleComplex,
/// A C `long double _Complex`. Corresponds to the `jD` code.
LongDoubleComplex,
/// A C++ `bool` / C99 `_Bool`. Corresponds to the `B` code.
Bool,
/// A C `void`. Corresponds to the `v` code.
Expand Down Expand Up @@ -99,6 +108,10 @@ impl fmt::Display for Encoding<'_> {
ULongLong => "Q",
Float => "f",
Double => "d",
LongDouble => "D",
FloatComplex => "jf",
DoubleComplex => "jd",
LongDoubleComplex => "jD",
Bool => "B",
Void => "v",
String => "*",
Expand Down
4 changes: 4 additions & 0 deletions objc2-encode/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ fn rm_enc_prefix<'a>(s: &'a str, enc: &Encoding<'_>) -> Option<&'a str> {
ULongLong => "Q",
Float => "f",
Double => "d",
LongDouble => "D",
FloatComplex => "jf",
DoubleComplex => "jd",
LongDoubleComplex => "jD",
Bool => "B",
Void => "v",
String => "*",
Expand Down

0 comments on commit 0cfeefc

Please sign in to comment.