diff --git a/hyperactor_mesh/src/resource.rs b/hyperactor_mesh/src/resource.rs index 234db4a5f..5d9144c1e 100644 --- a/hyperactor_mesh/src/resource.rs +++ b/hyperactor_mesh/src/resource.rs @@ -359,6 +359,23 @@ where } } +/// A trait that bundles a set of types that together define a resource. +pub trait Resource { + /// The spec specification for this resource. + type Spec: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug; + + /// The state for this resource. + type State: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug; +} + +// A behavior defining the interface for a mesh controller. +hyperactor::behavior!( + Controller, + CreateOrUpdate, + GetState, + Stop, +); + /// RankedValues compactly represents rank-indexed values of type T. /// It stores contiguous values in a set of intervals; thus it is /// efficient and compact when the cardinality of T-typed values is diff --git a/hyperactor_mesh/src/resource/mesh.rs b/hyperactor_mesh/src/resource/mesh.rs index 736ddc9a3..3f463ce54 100644 --- a/hyperactor_mesh/src/resource/mesh.rs +++ b/hyperactor_mesh/src/resource/mesh.rs @@ -19,10 +19,8 @@ use ndslice::Extent; use serde::Deserialize; use serde::Serialize; -use crate::resource::CreateOrUpdate; -use crate::resource::GetState; +use crate::resource::Resource; use crate::resource::Status; -use crate::resource::Stop; use crate::v1::ValueMesh; /// Mesh specs @@ -49,17 +47,14 @@ pub trait Mesh { /// The mesh-specific specification for this resource. type Spec: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug; - /// The mesh-specific state for thsi resource. + /// The mesh-specific state for this resource. type State: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug; } -// A behavior defining the interface for a mesh controller. -hyperactor::behavior!( - Controller, - CreateOrUpdate>, - GetState>, - Stop, -); +impl Resource for M { + type Spec = Spec; + type State = State; +} #[cfg(test)] mod test { @@ -68,6 +63,10 @@ mod test { use hyperactor::Handler; use super::*; + use crate::resource::Controller; + use crate::resource::CreateOrUpdate; + use crate::resource::GetState; + use crate::resource::Stop; // Consider upstreaming this into `hyperactor` -- lightweight handler definitions // can be quite useful.