Skip to content

Commit 53c6bed

Browse files
authored
Merge pull request #7 from ReagentX/feat/cs/collapse-ifs
Rust 1.89 syntax
2 parents 9c3e3c5 + a6cd487 commit 53c6bed

3 files changed

Lines changed: 33 additions & 35 deletions

File tree

src/deserializer/iter.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,25 @@ impl<'a, 'b: 'a> Iterator for PropertyIterator<'a, 'b> {
142142
class: cls,
143143
data: _,
144144
}) = self.object_table.get(*idx)
145+
&& let Some(Archived::Class(cls)) = self.object_table.get(*cls)
145146
{
146-
if let Some(Archived::Class(cls)) = self.object_table.get(*cls) {
147-
let class_name = self
148-
.type_table
149-
.get(cls.name_index)
150-
.and_then(|types| types.first())
151-
.and_then(|t| match t {
152-
Type::String(name) => Some(*name),
153-
_ => None,
154-
})
155-
.unwrap_or("Unknown Class");
156-
// recurse into that object’s own data
157-
let sub_iter =
158-
PropertyIterator::new(self.object_table, self.type_table, *idx)?;
159-
resolved.push(Property::Object {
160-
class: cls,
161-
name: class_name,
162-
data: sub_iter,
163-
});
164-
}
147+
let class_name = self
148+
.type_table
149+
.get(cls.name_index)
150+
.and_then(|types| types.first())
151+
.and_then(|t| match t {
152+
Type::String(name) => Some(*name),
153+
_ => None,
154+
})
155+
.unwrap_or("Unknown Class");
156+
// recurse into that object’s own data
157+
let sub_iter =
158+
PropertyIterator::new(self.object_table, self.type_table, *idx)?;
159+
resolved.push(Property::Object {
160+
class: cls,
161+
name: class_name,
162+
data: sub_iter,
163+
});
165164
}
166165
}
167166
prim => resolved.push(Property::Primitive(prim)),

src/deserializer/typedstream.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ impl<'a> TypedStreamDeserializer<'a> {
232232

233233
// The class we just appended (*idx*) is the **parent** of the
234234
// class we appended in the previous iteration (*prev_new*)
235-
if let Some(child_idx) = prev_new {
236-
if let Archived::Class(ref mut child_cls) = self.object_table[child_idx] {
237-
child_cls.parent_index = Some(idx);
238-
}
235+
if let Some(child_idx) = prev_new
236+
&& let Archived::Class(ref mut child_cls) = self.object_table[child_idx]
237+
{
238+
child_cls.parent_index = Some(idx);
239239
}
240240

241241
// remember the first class we ever pushed
@@ -264,10 +264,10 @@ impl<'a> TypedStreamDeserializer<'a> {
264264

265265
// Patch the outer-most newly created class so that it points to the
266266
// already-existing parent (or to `None` if EMPTY terminated the list).
267-
if let Some(outer_idx) = prev_new {
268-
if let Archived::Class(ref mut outer_cls) = self.object_table[outer_idx] {
269-
outer_cls.parent_index = final_parent;
270-
}
267+
if let Some(outer_idx) = prev_new
268+
&& let Archived::Class(ref mut outer_cls) = self.object_table[outer_idx]
269+
{
270+
outer_cls.parent_index = final_parent;
271271
}
272272

273273
// Return the index of the bottom-most child we created first.
@@ -294,15 +294,14 @@ impl<'a> TypedStreamDeserializer<'a> {
294294
// Read the next type, which should be an object
295295
if let Some(next_index) = self.read_type(false)? {
296296
// Recursively read the types for this object
297-
if let Some(data) = self.read_types(next_index)? {
298-
if let Some(Archived::Object {
297+
if let Some(data) = self.read_types(next_index)?
298+
&& let Some(Archived::Object {
299299
class: _,
300300
data: data_vec,
301301
}) = self.object_table.get_mut(placeholder_index)
302-
{
303-
// Add the data to the object
304-
data_vec.push(data);
305-
}
302+
{
303+
// Add the data to the object
304+
data_vec.push(data);
306305
}
307306
}
308307
}

src/models/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'a> Type<'a> {
9393
Self::String(str)
9494
}
9595

96-
pub(crate) fn get_array_length(types: &[u8]) -> Option<Vec<Type>> {
96+
pub(crate) fn get_array_length(types: &'_ [u8]) -> Option<Vec<Type<'_>>> {
9797
if types.first() == Some(&0x5b) {
9898
let len =
9999
types[1..]
@@ -109,7 +109,7 @@ impl<'a> Type<'a> {
109109
None
110110
}
111111

112-
pub(crate) fn read_new_type(data: &[u8]) -> Result<Consumed<Vec<Type>>> {
112+
pub(crate) fn read_new_type(data: &'_ [u8]) -> Result<Consumed<Vec<Type<'_>>>> {
113113
// Get the type of the object
114114
let type_length = read_unsigned_int(data)?;
115115

0 commit comments

Comments
 (0)