Repository: servo/servo
File: components/script/dom/globalscope.rs (Rust)

Code before:
        }
        unreachable!();
    }

    pub(crate) fn append_deferred_fetch(
        &self,
        deferred_fetch: QueuedDeferredFetchRecord,
    ) -> DeferredFetchRecordId {
        let deferred_record_id = DeferredFetchRecordId::default();
        self.fetch_group
            .borrow_mut()
            .deferred_fetch_records
            .insert(deferred_record_id, deferred_fetch);
        deferred_record_id
    }

    pub(crate) fn deferred_fetches(&self) -> Vec<QueuedDeferredFetchRecord> {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .values()
            .cloned()
            .collect()
    }

    pub(crate) fn deferred_fetch_record_for_id(
        &self,
        deferred_fetch_record_id: &DeferredFetchRecordId,
    ) -> QueuedDeferredFetchRecord {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .get(deferred_fetch_record_id)
            .expect("Should always use a generated fetch_record_id instead of passing your own")
            .clone()
    }

    /// <https://fetch.spec.whatwg.org/#process-deferred-fetches>
    pub(crate) fn process_deferred_fetches(&self) {
        // Step 1. For each deferred fetch record deferredRecord of fetchGroup’s
        // deferred fetch records, process a deferred fetch deferredRecord.
        for deferred_fetch in self.deferred_fetches() {
            deferred_fetch.process();
        }
    }

    pub(crate) fn import_map(&self) -> Ref<'_, ImportMap> {
        self.import_map.borrow()
    }

    pub(crate) fn import_map_mut(&self) -> RefMut<'_, ImportMap> {

Review comment (suggestion):
Everywhere this is used, I would look into passing the id to a method of the fetch group and doing whatever processing is necessary there.  Example: `global.abort_deferred_fetch(id)` which itself would call `fetch_group.abort_deferred_fetch(id)`. 

This would remove the need for an Rc around the record. 

Note that the Rc would be fundamentally required only if multiple structs that are part of the same global would own refs to the same record and operate on it independently(for example in `PipeTo`), but from what I can tell all operations go through the global and the associated fetchgroup so there is no fundamental need for an rc.

Code after:
        }
        unreachable!();
    }

    pub(crate) fn append_deferred_fetch(
        &self,
        deferred_fetch: QueuedDeferredFetchRecord,
    ) -> DeferredFetchRecordId {
        let deferred_record_id = DeferredFetchRecordId::default();
        self.fetch_group
            .borrow_mut()
            .deferred_fetch_records
            .insert(deferred_record_id, deferred_fetch);
        deferred_record_id
    }

    pub(crate) fn deferred_fetches(&self) -> Vec<QueuedDeferredFetchRecord> {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .values()
            .cloned()
            .collect()
    }

    pub(crate) fn deferred_fetch_record_for_id(
        &self,
        deferred_fetch_record_id: &DeferredFetchRecordId,
    ) -> QueuedDeferredFetchRecord {
        self.fetch_group
            .borrow()
            .deferred_fetch_records
            .get(deferred_fetch_record_id)
            .expect("Should always use a generated fetch_record_id instead of passing your own")
            .clone()
    }

    /// <https://fetch.spec.whatwg.org/#process-deferred-fetches>
    pub(crate) fn process_deferred_fetches(&self) {
        // Step 1. For each deferred fetch record deferredRecord of fetchGroup’s
        // deferred fetch records, process a deferred fetch deferredRecord.
        for deferred_fetch in self.deferred_fetches() {
            deferred_fetch.process(self);
        }
    }

    pub(crate) fn import_map(&self) -> Ref<'_, ImportMap> {
        self.import_map.borrow()
    }

    pub(crate) fn import_map_mut(&self) -> RefMut<'_, ImportMap> {