pub fn with_resources_from_set<'lua, R>(
        &mut self,
        lua: &'lua Lua,
        resource_set: &ScriptResourceSet,
        resources: &Resources,
        f: impl FnOnce(LuaTable<'lua>) -> R,
    ) -> Result<R> {
        let env = lua.registry_value(&self.env)?;
        let mut erased_loanables = Vec::with_capacity_in(self.map.len(), &self.bump_arena);
        for ty in resource_set.types.iter() {
            let resource = match self.map.get(ty) {
                Some(resource) => resource,
                None => {
                    // TODO: warn about this case. What we have here is, a resource was in the set
                    // requested to be borrowed, *but*, the `ScriptContext` doesn't need it/doesn't
                    // know where to put it.
                    continue;
                }
            };

            if let Err(error) = (resource.loanable)(
                lua,
                &env,
                resources,
                &self.bump_arena,
                &mut erased_loanables,
            ) {
                tracing::error!(
                    name = %resource.name,
                    ?error,
                    "failed to borrow resource {}: {:?}",
                    resource.name,
                    error,
                );
            }
        }

        let out = self.scope_arena.scope(|guard| {
            for loanable in &mut erased_loanables {
                loanable.erased_loan(guard, &self.map, lua)?;
            }

            Ok(f(env))
        });

        drop(erased_loanables);

        self.bump_arena.reset();
        self.scope_arena.reset();

        out
    }
/// Borrow a set of resources from a [`Resources`] and loan it out to matching resources
/// registered with this context, and then call the given thunk, passing in the environment
/// table of this script context (if it exists.)
///
/// Loans will be valid until the thunk returns.
Borrow a set of resources from a [`Resources`] and loan it out to matching resources
registered with this context, and then call the given thunk, passing in the environment
table of this script context (if it exists.)

Loans will be valid until the thunk returns.
Borrow a set of resources from a [ ` Resources ` ] and loan it out to matching resources registered with this context and then call the given thunk passing in the environment table of this script context ( if it exists . ) Loans will be valid until the thunk returns .
pub fn with_resources_from_set<'lua, R>(
        &mut self,
        lua: &'lua Lua,
        resource_set: &ScriptResourceSet,
        resources: &Resources,
        f: impl FnOnce(LuaTable<'lua>) -> R,
    ) -> Result<R> {
        let env = lua.registry_value(&self.env)?;
        let mut erased_loanables = Vec::with_capacity_in(self.map.len(), &self.bump_arena);
        for ty in resource_set.types.iter() {
            let resource = match self.map.get(ty) {
                Some(resource) => resource,
                None => {
                    // TODO: warn about this case. What we have here is, a resource was in the set
                    // requested to be borrowed, *but*, the `ScriptContext` doesn't need it/doesn't
                    // know where to put it.
                    continue;
                }
            };
            if let Err(error) = (resource.loanable)(
                lua,
                &env,
                resources,
                &self.bump_arena,
                &mut erased_loanables,
            ) {
                tracing::error!(
                    name = %resource.name,
                    ?error,
                    "failed to borrow resource {}: {:?}",
                    resource.name,
                    error,
                );
            }
        }
        let out = self.scope_arena.scope(|guard| {
            for loanable in &mut erased_loanables {
                loanable.erased_loan(guard, &self.map, lua)?;
            }
            Ok(f(env))
        });
        drop(erased_loanables);
        self.bump_arena.reset();
        self.scope_arena.reset();
        out
    }
pub fn with_resources_from_set < ' lua , R > ( & mut self , lua : & ' lua Lua , resource_set : & ScriptResourceSet , resources : & Resources , f : impl FnOnce ( LuaTable < ' lua > ) -> R , ) -> Result < R > { let env = lua . registry_value ( & self . env ) ? ; let mut erased_loanables = Vec :: with_capacity_in ( self . map . len ( ) , & self . bump_arena ) ; for ty in resource_set . types . iter ( ) { let resource = match self . map . get ( ty ) { Some ( resource ) => resource , None => { // TODO: warn about this case. What we have here is, a resource was in the set // requested to be borrowed, *but*, the `ScriptContext` doesn't need it/doesn't // know where to put it. continue ; } } ; if let Err ( error ) = ( resource . loanable ) ( lua , & env , resources , & self . bump_arena , & mut erased_loanables , ) { tracing :: error ! ( name resource name error " " resource name error ) ; } } let out = self . scope_arena . scope ( | guard | { for loanable in & mut erased_loanables { loanable . erased_loan ( guard , & self . map , lua ) ? ; } Ok ( f ( env ) ) } ) ; drop ( erased_loanables ) ; self . bump_arena . reset ( ) ; self . scope_arena . reset ( ) ; out }
Borrow a set of resources from a [`Resources`] and loan it out to matching resources
registered with this context, and then call the given thunk, passing in the environment
table of this script context (if it exists.)
Borrow a set of resources from a [ ` Resources ` ] and loan it out to matching resources registered with this context and then call the given thunk passing in the environment table of this script context ( if it exists . )
&mut self
lua
&'lua Lua
resource_set
&ScriptResourceSet
resources
&Resources
f
impl FnOnce(LuaTable<'lua>) -> R
&mut self
lua
&'lua Lua
resource_set
&ScriptResourceSet
resources
&Resources
f
impl FnOnce(LuaTable<'lua>) -> R