Skip to content

Commit

Permalink
Add as_any methods to Value
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago authored and johnyob committed Oct 20, 2023
1 parent 26c3893 commit 48ab8c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions jstz_core/src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ pub(crate) fn deserialize<T: DeserializeOwned>(bytes: &[u8]) -> T {

/// A key-value 'value' is a value that is can be dynamically
/// coerced (using `Any`) and serialized.
pub trait Value: Any + Debug + erased_serde::Serialize {}
pub trait Value: Any + Debug + erased_serde::Serialize {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}

impl<T> Value for T where T: Any + Debug + erased_serde::Serialize {
fn as_any(&self) -> &dyn Any {
self
}

impl<T> Value for T where T: Any + Debug + erased_serde::Serialize {}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}

// Since trait downcasting isn't permitted, we implement all methods
// from `dyn Any`.
Expand Down

0 comments on commit 48ab8c0

Please sign in to comment.