Skip to content

Commit

Permalink
backends: implement as_any() on OpStore and OpHeadsStore too
Browse files Browse the repository at this point in the history
It's useful for custom commands to be able to downcast to custom
backend types.
  • Loading branch information
martinvonz committed Jan 31, 2024
1 parent cfcc7c5 commit 7c87fe2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/op_heads_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![allow(missing_docs)]

use std::any::Any;
use std::collections::HashSet;
use std::fmt::Debug;
use std::sync::Arc;
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions lib/src/op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/simple_op_heads_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![allow(missing_docs)]

use std::any::Any;
use std::fmt::{Debug, Formatter};
use std::fs;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -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()
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/simple_op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -94,6 +95,10 @@ impl SimpleOpStore {
}

impl OpStore for SimpleOpStore {
fn as_any(&self) -> &dyn Any {
self
}

fn name(&self) -> &str {
Self::name()
}
Expand Down

0 comments on commit 7c87fe2

Please sign in to comment.