-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
2,147 additions
and
898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::{AperSync, TreeMapRef}; | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
pub struct AtomMap<K: Serialize + DeserializeOwned, V: Serialize + DeserializeOwned> { | ||
map: TreeMapRef, | ||
_phantom: std::marker::PhantomData<(K, V)>, | ||
} | ||
|
||
impl<K: Serialize + DeserializeOwned, V: Serialize + DeserializeOwned> AperSync for AtomMap<K, V> { | ||
fn attach(map: TreeMapRef) -> Self { | ||
Self { | ||
map, | ||
_phantom: std::marker::PhantomData, | ||
} | ||
} | ||
|
||
fn listen<F: Fn() -> bool + 'static + Send + Sync>(&self, listener: F) { | ||
self.map.listen(listener) | ||
} | ||
} | ||
|
||
impl<K: Serialize + DeserializeOwned, V: Serialize + DeserializeOwned> AtomMap<K, V> { | ||
pub fn get(&self, key: &K) -> Option<V> { | ||
self.map | ||
.get(&bincode::serialize(key).unwrap()) | ||
.map(|bytes| bincode::deserialize(&bytes).unwrap()) | ||
} | ||
|
||
pub fn set(&mut self, key: &K, value: &V) { | ||
self.map.set( | ||
bincode::serialize(key).unwrap(), | ||
bincode::serialize(value).unwrap(), | ||
); | ||
} | ||
|
||
pub fn delete(&mut self, key: &K) { | ||
self.map.delete(bincode::serialize(key).unwrap()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
pub mod atom; | ||
pub mod atom_map; | ||
pub mod fixed_array; | ||
pub mod map; | ||
|
||
pub use atom::Atom; | ||
pub use atom_map::AtomMap; | ||
pub use fixed_array::FixedArray; | ||
pub use map::Map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
static-client | ||
client-pkg |
Oops, something went wrong.