-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* skeleton of type state pattern in place * Revert "skeleton of type state pattern in place" This reverts commit 7d9c63f. * Changes in place, accidentally set rustfmt too aggressive... * getting there with chasing types through * more chasing * Hopefully done chasing changes through the system * cargo fmt pass * wasm addition * JournalCheckpoint only holds Filesystem clock * remove actor clock from drive initialization
- Loading branch information
1 parent
416dc96
commit 5bcc637
Showing
18 changed files
with
751 additions
and
295 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use super::clock_inner::{ClockInner, ClockInnerSnapshot}; | ||
use crate::codec::{ActorId, ParserResult, Stream}; | ||
|
||
use futures::AsyncWrite; | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub struct Actor { | ||
id: ActorId, | ||
clock: ClockInner, | ||
} | ||
|
||
impl Actor { | ||
fn new(id: ActorId, clock: ClockInner) -> Self { | ||
Self { id, clock } | ||
} | ||
|
||
pub fn initialize(actor_id: ActorId) -> Self { | ||
Self::new(actor_id, ClockInner::initialize()) | ||
} | ||
|
||
pub fn as_snapshot(&self) -> ActorSnapshot { | ||
self.into() | ||
} | ||
|
||
pub async fn encode<W: AsyncWrite + Unpin + Send>( | ||
&self, | ||
writer: &mut W, | ||
) -> std::io::Result<usize> { | ||
ActorSnapshot::from(self).encode(writer).await | ||
} | ||
|
||
pub fn parse(input: Stream) -> ParserResult<Self> { | ||
let (input, snapshot) = ActorSnapshot::parse(input)?; | ||
Ok((input, Self::new(snapshot.id, snapshot.clock.into()))) | ||
} | ||
} | ||
|
||
impl From<ActorSnapshot> for Actor { | ||
fn from(value: ActorSnapshot) -> Self { | ||
Self::new(value.id, value.clock.into()) | ||
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
pub struct ActorSnapshot { | ||
id: ActorId, | ||
clock: ClockInnerSnapshot, | ||
} | ||
|
||
impl ActorSnapshot { | ||
fn new(id: ActorId, clock: ClockInnerSnapshot) -> Self { | ||
Self { id, clock } | ||
} | ||
|
||
pub const fn size() -> usize { | ||
ActorId::size() + ClockInnerSnapshot::size() | ||
} | ||
|
||
pub async fn encode<W: AsyncWrite + Unpin + Send>( | ||
&self, | ||
writer: &mut W, | ||
) -> std::io::Result<usize> { | ||
self.id.encode(writer).await?; | ||
self.clock.encode(writer).await | ||
} | ||
|
||
pub fn parse(input: Stream) -> ParserResult<Self> { | ||
let (input, id) = ActorId::parse(input)?; | ||
let (input, clock) = ClockInnerSnapshot::parse(input)?; | ||
Ok((input, Self::new(id, clock))) | ||
} | ||
} | ||
|
||
impl PartialOrd for ActorSnapshot { | ||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
impl Ord for ActorSnapshot { | ||
fn cmp(&self, other: &Self) -> std::cmp::Ordering { | ||
self.id.cmp(&other.id).then(self.clock.cmp(&other.clock)) | ||
} | ||
} | ||
|
||
impl From<&Actor> for ActorSnapshot { | ||
fn from(value: &Actor) -> Self { | ||
Self { | ||
id: value.id, | ||
clock: (&value.clock).into(), | ||
} | ||
} | ||
} |
Oops, something went wrong.