From 7c87fe243c3b14f0321c2bd101af3879770cb90f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 30 Jan 2024 18:28:28 -0800 Subject: [PATCH] backends: implement as_any() on OpStore and OpHeadsStore too It's useful for custom commands to be able to downcast to custom backend types. --- lib/src/op_heads_store.rs | 3 +++ lib/src/op_store.rs | 3 +++ lib/src/simple_op_heads_store.rs | 5 +++++ lib/src/simple_op_store.rs | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/lib/src/op_heads_store.rs b/lib/src/op_heads_store.rs index a55f53686..828eafc4c 100644 --- a/lib/src/op_heads_store.rs +++ b/lib/src/op_heads_store.rs @@ -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. diff --git a/lib/src/op_store.rs b/lib/src/op_store.rs index 716c8a71a..49cd27cf0 100644 --- a/lib/src/op_store.rs +++ b/lib/src/op_store.rs @@ -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 = Result; pub trait OpStore: Send + Sync + Debug { + fn as_any(&self) -> &dyn Any; + fn name(&self) -> &str; fn root_operation_id(&self) -> &OperationId; diff --git a/lib/src/simple_op_heads_store.rs b/lib/src/simple_op_heads_store.rs index 21a101580..848539aee 100644 --- a/lib/src/simple_op_heads_store.rs +++ b/lib/src/simple_op_heads_store.rs @@ -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() } diff --git a/lib/src/simple_op_store.rs b/lib/src/simple_op_store.rs index 19433b107..f0dd2fc6f 100644 --- a/lib/src/simple_op_store.rs +++ b/lib/src/simple_op_store.rs @@ -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() }