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

Code before:
    ReadOnly(AsyncReadOnlyOperation),
    ReadWrite(AsyncReadWriteOperation),
}

impl AsyncOperation {
    pub fn notify_error(&self, error: BackendError) {
        match self {
            Self::ReadOnly(operation) => operation.notify_error(error),
            Self::ReadWrite(operation) => operation.notify_error(error),
        }
    }
}

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum CreateObjectResult {
    Created,
    AlreadyExists,
}

#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
/// Messaging used in the context of connection lifecycle management.
pub enum ConnectionMsg {
    /// Error if a DB is opened for a version lower than the current db version.
    VersionError { name: String, id: Uuid },
    /// Opening a connection was aborted.
    AbortError { name: String, id: Uuid },
    /// A newly created connection with a version,
    /// updgraded or not.
    Connection {
        name: String,
        id: Uuid,
        version: u64,
        upgraded: bool,
    },
    /// An upgrade transaction for a version started.
    Upgrade {
        name: String,
        id: Uuid,
        version: u64,
        old_version: u64,
        transaction: u64,
    },
    /// A `versionchange` event should be fired for a connection.
    VersionChange {
        /// The id of the connection.
        id: Uuid,
        /// The name of the connection.
        name: String,
        version: u64,
        old_version: u64,
    },

Review comment (suggestion):
```suggestion
            Self::ReadOnly(operation) |
            Self::ReadWrite(operation) => operation.notify_error(error),
```

Code after:
}

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),
}

impl AsyncOperation {
    pub fn notify_error(&self, error: BackendError) {
        match self {
            Self::ReadOnly(operation) => operation.notify_error(error),
            Self::ReadWrite(operation) => operation.notify_error(error),
        }
    }
}

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum CreateObjectResult {
    Created,
    AlreadyExists,
}

#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
/// Messaging used in the context of connection lifecycle management.
pub enum ConnectionMsg {
    /// Error if a DB is opened for a version lower than the current db version.
    VersionError { name: String, id: Uuid },
    /// Opening a connection was aborted.
    AbortError { name: String, id: Uuid },
    /// A newly created connection with a version,
    /// updgraded or not.
    Connection {
        name: String,
        id: Uuid,
        version: u64,
        upgraded: bool,
    },
    /// An upgrade transaction for a version started.