pub fn remove_unused_resources(&mut self) {
        let mut unused_resources    = HashMap::new();
        let mut to_remove           = HashSet::new();

        for (idx, (target_resource, draw)) in self.pending_drawing.iter().enumerate() {
            // Figure out the resources used by this step
            let used_resources = draw.source_resource(target_resource);

            // If no resources are used, then this is declaring a new resource
            if used_resources.len() == 0 {
                // If the target resource is in the unused list, remove any item that refers to it
                if let Some(declaration_indexes) = unused_resources.remove(target_resource) {
                    to_remove.extend(declaration_indexes);
                }

                // This is declaring this resource: add it as 'unused'
                unused_resources.insert(*target_resource, vec![idx]);
            } else {
                // Remove the used resources from the unused list
                for resource in used_resources {
                    // A self-reference doesn't count as a usage of the resource (just another spot where it's unused)
                    if &resource != target_resource {
                        unused_resources.remove(&resource);
                    } else {
                        // A self-reference is added to the indexes that form the declaration of the resource (except for layers and sprites)
                        match resource {
                            DrawResource::Layer(_) | DrawResource::Sprite(_)    => { },
                            _                                                   => { unused_resources.get_mut(&resource).map(|declaration_list| declaration_list.push(idx)); }
                        }
                    }
                }
            }
        }

        // Remove any resources in the to_remove set
        if to_remove.len() > 0 {
            let old_drawing         = mem::take(&mut self.pending_drawing);
            self.pending_drawing    = old_drawing.into_iter()
                .enumerate()
                .filter(|(idx, _item)| !to_remove.contains(idx))
                .map(|(_idx, item)| item)
                .collect();
        }
    }
///
/// Removes any resource in this stream that's declared but not used
///
Removes any resource in this stream that's declared but not used
Removes any resource in this stream that ' s declared but not used
pub fn remove_unused_resources(&mut self) {
        let mut unused_resources    = HashMap::new();
        let mut to_remove           = HashSet::new();
        for (idx, (target_resource, draw)) in self.pending_drawing.iter().enumerate() {
            // Figure out the resources used by this step
            let used_resources = draw.source_resource(target_resource);
            // If no resources are used, then this is declaring a new resource
            if used_resources.len() == 0 {
                // If the target resource is in the unused list, remove any item that refers to it
                if let Some(declaration_indexes) = unused_resources.remove(target_resource) {
                    to_remove.extend(declaration_indexes);
                }
                // This is declaring this resource: add it as 'unused'
                unused_resources.insert(*target_resource, vec![idx]);
            } else {
                // Remove the used resources from the unused list
                for resource in used_resources {
                    // A self-reference doesn't count as a usage of the resource (just another spot where it's unused)
                    if &resource != target_resource {
                        unused_resources.remove(&resource);
                    } else {
                        // A self-reference is added to the indexes that form the declaration of the resource (except for layers and sprites)
                        match resource {
                            DrawResource::Layer(_) | DrawResource::Sprite(_)    => { },
                            _                                                   => { unused_resources.get_mut(&resource).map(|declaration_list| declaration_list.push(idx)); }
                        }
                    }
                }
            }
        }
        // Remove any resources in the to_remove set
        if to_remove.len() > 0 {
            let old_drawing         = mem::take(&mut self.pending_drawing);
            self.pending_drawing    = old_drawing.into_iter()
                .enumerate()
                .filter(|(idx, _item)| !to_remove.contains(idx))
                .map(|(_idx, item)| item)
                .collect();
        }
    }
pub fn remove_unused_resources ( & mut self ) { let mut unused_resources = HashMap :: new ( ) ; let mut to_remove = HashSet :: new ( ) ; for ( idx , ( target_resource , draw ) ) in self . pending_drawing . iter ( ) . enumerate ( ) { // Figure out the resources used by this step let used_resources = draw . source_resource ( target_resource ) ; // If no resources are used, then this is declaring a new resource if used_resources . len ( ) == 0 { // If the target resource is in the unused list, remove any item that refers to it if let Some ( declaration_indexes ) = unused_resources . remove ( target_resource ) { to_remove . extend ( declaration_indexes ) ; } // This is declaring this resource: add it as 'unused' unused_resources . insert ( * target_resource , vec ! [ idx ] ) ; } else { // Remove the used resources from the unused list for resource in used_resources { // A self-reference doesn't count as a usage of the resource (just another spot where it's unused) if & resource != target_resource { unused_resources . remove ( & resource ) ; } else { // A self-reference is added to the indexes that form the declaration of the resource (except for layers and sprites) match resource { DrawResource :: Layer ( _ ) | DrawResource :: Sprite ( _ ) => { } , _ => { unused_resources . get_mut ( & resource ) . map ( | declaration_list | declaration_list . push ( idx ) ) ; } } } } } } // Remove any resources in the to_remove set if to_remove . len ( ) > 0 { let old_drawing = mem :: take ( & mut self . pending_drawing ) ; self . pending_drawing = old_drawing . into_iter ( ) . enumerate ( ) . filter ( | ( idx , _item ) | ! to_remove . contains ( idx ) ) . map ( | ( _idx , item ) | item ) . collect ( ) ; } }
Removes any resource in this stream that's declared but not used
Removes any resource in this stream that ' s declared but not used
&mut self