Skip to content

Commit

Permalink
Convert class_is_a to use the new superclasses_iter signature
Browse files Browse the repository at this point in the history
  • Loading branch information
krakow10 committed Oct 6, 2024
1 parent 4f4b5cd commit e389adf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
10 changes: 3 additions & 7 deletions rbx_reflection/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,9 @@ impl<'a> ReflectionDatabase<'a> {

/// This mimics the behavior of the Roblox Lua Instance:IsA(ClassName) method.
/// Returns whether superclass_descriptor is a superclass of descriptor.
pub fn class_is_a(
&'a self,
descriptor: &'a ClassDescriptor<'a>,
superclass_descriptor: &'a ClassDescriptor<'a>,
) -> bool {
self.superclasses_iter(descriptor)
.any(|class_descriptor| class_descriptor.name == superclass_descriptor.name)
pub fn class_is_a(&'a self, class_name: &'a str, superclass_name: &'a str) -> bool {
self.superclasses_iter(class_name)
.any(|class_descriptor| class_descriptor.name == superclass_name)
}

/// Finds the default value of a property given its name and a class that
Expand Down
12 changes: 2 additions & 10 deletions rbx_reflection_database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@ mod test {
#[test]
fn class_is_a_test() {
let database = get();
let part_class_descriptor = database.classes.get("Part").unwrap();
let instance_class_descriptor = database.classes.get("Instance").unwrap();
assert_eq!(
database.class_is_a(part_class_descriptor, instance_class_descriptor),
true
);
assert_eq!(
database.class_is_a(instance_class_descriptor, part_class_descriptor),
false
);
assert_eq!(database.class_is_a("Part", "Instance"), true);
assert_eq!(database.class_is_a("Instance", "Part"), false);
}
}

0 comments on commit e389adf

Please sign in to comment.