validator: move function call so get_model_info is infallible

This commit is contained in:
Quaternions 2025-04-11 21:46:44 -07:00
parent 57db5f738e
commit 668c5fef51
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131

@ -127,10 +127,7 @@ pub struct ModelInfo<'a>{
counts:Counts,
}
pub fn get_model_info(dom:&rbx_dom_weak::WeakDom)->Result<ModelInfo,GetRootInstanceError>{
// extract the root instance, otherwise immediately return
let model_instance=get_root_instance(&dom)?;
pub fn get_model_info<'a>(dom:&'a rbx_dom_weak::WeakDom,model_instance:&'a rbx_dom_weak::Instance)->ModelInfo<'a>{
// extract model info
let map_info=get_mapinfo(&dom,model_instance);
@ -161,12 +158,12 @@ pub fn get_model_info(dom:&rbx_dom_weak::WeakDom)->Result<ModelInfo,GetRootInsta
}
}
Ok(ModelInfo{
ModelInfo{
model_class:model_instance.class.as_str(),
model_name:model_instance.name.as_str(),
map_info,
counts,
})
}
}
// check if an observed string matches an expected string
@ -515,8 +512,11 @@ impl crate::message_handler::MessageHandler{
// decode dom (slow!)
let dom=maybe_gzip.read_with(read_dom,read_dom).map_err(Error::ModelFileDecode)?;
// extract the root instance
let model_instance=get_root_instance(&dom).map_err(Error::GetRootInstance)?;
// extract information from the model
let model_info=get_model_info(&dom).map_err(Error::GetRootInstance)?;
let model_info=get_model_info(&dom,model_instance);
// convert the model information into a structured report
let map_check=model_info.check();