Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions hyperactor/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,43 @@ pub trait Binds<A: Actor>: Referable {
/// is handled by a specific actor type.
pub trait RemoteHandles<M: RemoteMessage>: Referable {}

/// Check if the actor behaves-as the a given behavior (defined by [`behavior!`]).
///
/// ```
/// # use serde::Serialize;
/// # use serde::Deserialize;
/// # use hyperactor::Named;
///
/// // First, define a behavior, based on handling a single message type `()`.
/// hyperactor::behavior!(UnitBehavior, ());
///
/// #[derive(hyperactor::Actor, Debug, Default)]
/// struct MyActor;
///
/// #[async_trait::async_trait]
/// impl hyperactor::Handler<()> for MyActor {
/// async fn handle(
/// &mut self,
/// _cx: &hyperactor::Context<Self>,
/// _message: (),
/// ) -> Result<(), anyhow::Error> {
/// // no-op
/// Ok(())
/// }
/// }
///
/// hyperactor::assert_behaves!(MyActor as UnitBehavior);
/// ```
#[macro_export]
macro_rules! assert_behaves {
($ty:ty as $behavior:ty) => {
const _: fn() = || {
fn check<B: hyperactor::actor::Binds<$ty>>() {}
check::<$behavior>();
};
};
}

#[cfg(test)]
mod tests {
use std::sync::Mutex;
Expand Down
12 changes: 1 addition & 11 deletions hyperactor_mesh/src/resource/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ hyperactor::behavior!(
#[cfg(test)]
mod test {
use hyperactor::Actor;
use hyperactor::ActorRef;
use hyperactor::Context;
use hyperactor::Handler;

Expand Down Expand Up @@ -114,14 +113,5 @@ mod test {
_message: Stop => unimplemented!(),
}

#[test]
fn test_controller_behavior() {
use hyperactor::ActorHandle;

// This is a compile-time check that TestMeshController implements
// the Controller<TestMesh> behavior correctly.
fn _assert_bind(handle: ActorHandle<TestMeshController>) -> ActorRef<Controller<TestMesh>> {
handle.bind()
}
}
hyperactor::assert_behaves!(TestMeshController as Controller<TestMesh>);
}
Loading