Repository: servo/servo
File: components/shared/storage/indexeddb.rs (Rust)

Code before:

impl AsyncReadOnlyOperation {
    fn notify_error(&self, error: BackendError) {
        let _ = match self {
            Self::GetKey { callback, .. } => callback.send(Err(error)),
            Self::GetItem { callback, .. } => callback.send(Err(error)),
            Self::GetAllKeys { callback, .. } => callback.send(Err(error)),
            Self::GetAllItems { callback, .. } => callback.send(Err(error)),
            Self::Count { callback, .. } => callback.send(Err(error)),
            Self::Iterate { callback, .. } => callback.send(Err(error)),
        };
    }
}

#[derive(Debug, Deserialize, Serialize)]
pub enum AsyncReadWriteOperation {
    /// Sets the value of the given key in the associated idb data
    PutItem {
        callback: GenericCallback<BackendResult<PutItemResult>>,
        key: Option<IndexedDBKeyType>,
        value: Vec<u8>,
        should_overwrite: bool,
    },

    /// Removes the key/value pair for the given key in the associated idb data
    RemoveItem {
        callback: GenericCallback<BackendResult<()>>,
        key_range: IndexedDBKeyRange,
    },
    /// Clears all key/value pairs in the associated idb data
    Clear(GenericCallback<BackendResult<()>>),
}

impl AsyncReadWriteOperation {
    fn notify_error(&self, error: BackendError) {
        let _ = match self {
            Self::PutItem { callback, .. } => callback.send(Err(error)),
            Self::RemoveItem { callback, .. } => callback.send(Err(error)),
            Self::Clear(callback) => callback.send(Err(error)),
        };
    }
}

/// Operations that are not executed instantly, but rather added to a
/// queue that is eventually run.
#[derive(Debug, Deserialize, Serialize)]
pub enum AsyncOperation {
    ReadOnly(AsyncReadOnlyOperation),
    ReadWrite(AsyncReadWriteOperation),
}


Review comment (suggestion):
You might be able to combine this into one or'd match to avoid repeating `callback.send(...)`.


```suggestion
            Self::GetKey { callback, .. } |
            Self::GetItem { callback, .. } |
            Self::GetAllKeys { callback, .. } |
            Self::GetAllItems { callback, .. } |
            Self::Count { callback, .. } |
            Self::Iterate { callback, .. } => callback.send(Err(error)),
```

Code after:
    },
    GetAllItems {
        callback: GenericCallback<BackendResult<Vec<Vec<u8>>>>,
        key_range: IndexedDBKeyRange,
        count: Option<u32>,
    },

    Count {
        callback: GenericCallback<BackendResult<u64>>,
        key_range: IndexedDBKeyRange,
    },
    Iterate {
        callback: GenericCallback<BackendResult<Vec<IndexedDBRecord>>>,
        key_range: IndexedDBKeyRange,
    },
}

impl AsyncReadOnlyOperation {
    fn notify_error(&self, error: BackendError) {
        let _ = match self {
            Self::GetKey { callback, .. } => callback.send(Err(error)),
            Self::GetItem { callback, .. } => callback.send(Err(error)),
            Self::GetAllKeys { callback, .. } => callback.send(Err(error)),
            Self::GetAllItems { callback, .. } => callback.send(Err(error)),
            Self::Count { callback, .. } => callback.send(Err(error)),
            Self::Iterate { callback, .. } => callback.send(Err(error)),
        };
    }
}

#[derive(Debug, Deserialize, Serialize)]
pub enum AsyncReadWriteOperation {
    /// Sets the value of the given key in the associated idb data
    PutItem {
        callback: GenericCallback<BackendResult<PutItemResult>>,
        key: Option<IndexedDBKeyType>,
        value: Vec<u8>,
        should_overwrite: bool,
    },

    /// Removes the key/value pair for the given key in the associated idb data
    RemoveItem {
        callback: GenericCallback<BackendResult<()>>,
        key_range: IndexedDBKeyRange,
    },
    /// Clears all key/value pairs in the associated idb data
    Clear(GenericCallback<BackendResult<()>>),
}

impl AsyncReadWriteOperation {
    fn notify_error(&self, error: BackendError) {