Skip to content

Commit

Permalink
Merge pull request SSheldon#11 from madsmtm/encoding-parameter-size
Browse files Browse the repository at this point in the history
Change Encoding parameter sizes
  • Loading branch information
madsmtm committed Aug 31, 2021
2 parents 1d1ad54 + f13996e commit b697ca5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion objc_encode/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ unsafe impl Encode for *const c_void {
}

unsafe impl<T: Encode, const LENGTH: usize> Encode for [T; LENGTH] {
const ENCODING: Encoding<'static> = Encoding::Array(LENGTH as u32, &<T as Encode>::ENCODING);
const ENCODING: Encoding<'static> = Encoding::Array(LENGTH, &<T as Encode>::ENCODING);
}

// External crates cannot implement Encode for pointers or [`Option`], but
Expand Down
4 changes: 2 additions & 2 deletions objc_encode/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub enum Encoding<'a> {
Class,
Sel,
Unknown,
BitField(u32),
BitField(u8),
Pointer(&'a Encoding<'a>),
Array(u32, &'a Encoding<'a>),
Array(usize, &'a Encoding<'a>),
Struct(&'a str, &'a [Encoding<'a>]),
Union(&'a str, &'a [Encoding<'a>]),
}
Expand Down
6 changes: 3 additions & 3 deletions objc_encode/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn rm_enc_prefix<'a>(s: &'a str, enc: &Encoding<'_>) -> Option<&'a str> {
Unknown => "?",
BitField(b) => {
let s = s.strip_prefix('b')?;
return rm_int_prefix(s, b);
return rm_int_prefix(s, b as usize);
}
Pointer(t) => {
let s = s.strip_prefix('^')?;
Expand Down Expand Up @@ -75,7 +75,7 @@ fn rm_enc_prefix<'a>(s: &'a str, enc: &Encoding<'_>) -> Option<&'a str> {
s.strip_prefix(code)
}

fn chomp_int(s: &str) -> Option<(u32, &str)> {
fn chomp_int(s: &str) -> Option<(usize, &str)> {
// Chomp until we hit a non-digit
let (num, t) = match s.find(|c: char| !c.is_digit(10)) {
Some(i) => s.split_at(i),
Expand All @@ -84,7 +84,7 @@ fn chomp_int(s: &str) -> Option<(u32, &str)> {
num.parse().map(|n| (n, t)).ok()
}

fn rm_int_prefix(s: &str, other: u32) -> Option<&str> {
fn rm_int_prefix(s: &str, other: usize) -> Option<&str> {
chomp_int(s).and_then(|(n, t)| if other == n { Some(t) } else { None })
}

Expand Down

0 comments on commit b697ca5

Please sign in to comment.