backends: implement as_any() on OpStore and OpHeadsStore too

It's useful for custom commands to be able to downcast to custom
backend types.
This commit is contained in:
Martin von Zweigbergk 2024-01-30 18:28:28 -08:00 committed by Martin von Zweigbergk
parent cfcc7c5e34
commit 7c87fe243c
4 changed files with 16 additions and 0 deletions

View file

@ -14,6 +14,7 @@
#![allow(missing_docs)]
use std::any::Any;
use std::collections::HashSet;
use std::fmt::Debug;
use std::sync::Arc;
@ -35,6 +36,8 @@ pub trait OpHeadsStoreLock {}
/// Manages the set of current heads of the operation log.
pub trait OpHeadsStore: Send + Sync + Debug {
fn as_any(&self) -> &dyn Any;
fn name(&self) -> &str;
/// Remove the old op heads and add the new one.

View file

@ -14,6 +14,7 @@
#![allow(missing_docs)]
use std::any::Any;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::{Debug, Error, Formatter};
use std::iter;
@ -434,6 +435,8 @@ pub enum OpStoreError {
pub type OpStoreResult<T> = Result<T, OpStoreError>;
pub trait OpStore: Send + Sync + Debug {
fn as_any(&self) -> &dyn Any;
fn name(&self) -> &str;
fn root_operation_id(&self) -> &OperationId;

View file

@ -14,6 +14,7 @@
#![allow(missing_docs)]
use std::any::Any;
use std::fmt::{Debug, Formatter};
use std::fs;
use std::path::{Path, PathBuf};
@ -71,6 +72,10 @@ struct SimpleOpHeadsStoreLock {
impl OpHeadsStoreLock for SimpleOpHeadsStoreLock {}
impl OpHeadsStore for SimpleOpHeadsStore {
fn as_any(&self) -> &dyn Any {
self
}
fn name(&self) -> &str {
Self::name()
}

View file

@ -14,6 +14,7 @@
#![allow(missing_docs)]
use std::any::Any;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Debug;
use std::io::{ErrorKind, Write};
@ -94,6 +95,10 @@ impl SimpleOpStore {
}
impl OpStore for SimpleOpStore {
fn as_any(&self) -> &dyn Any {
self
}
fn name(&self) -> &str {
Self::name()
}