Common interfacing for Valor modules

#51 · open · 0 comments

View on GitHub ↗

pandres95

# Valor: A Multi-Target, Transport-Agnostic Runtime for Modular Code Execution Valor is a Rust runtime designed to run arbitrary code organized in a modular way, independent of the transport layer. It can be compiled for multiple targets, including server-side applications, WebAssembly (WASM/WASI), and embedded systems. ## Design ### Module Registry Valor maintains a static, thread-safe registry of modules. Each module contains a collection of methods, along with arbitrary metadata in the form of extensions. This design allows for organized and manageable execution of code in different environments. ### Attribute Macros Valor provides three attribute macros: `valor::module`, `valor::method`, and `valor::extensions`. These macros are used to define modules and their associated methods and extensions. - `valor::module`: Defines a module. The module contains a collection of methods and metadata. - `valor::method`: Marks functions as methods of the containing module. - `valor::extensions`: Provides arbitrary metadata for methods or modules. ### Module and Method Structures Modules and methods in Valor are represented by the `Module` and `Method` structs, respectively. Both structs contain a name and a set of extensions. The `Method` struct also contains a function that can be called to execute the method. ## Example Usage Here's an example of how to define a module and its methods using Valor: ```rs #[valor::module(a_module)] pub mod a_module { use valor::structures::{Request, Response}; #[valor::method(a_method)] #[valor::extensions(http_verb = "GET", http_path = "/")] pub fn a_method (request: Request) -> Response { // Implement the function } } ``` In this test, we create a Module, add it to the registry, and then verify that it was correctly added. ## Future Work The design of Valor allows for further expansion and adaptation to different use cases. Future plans include additional attribute macros for more granular control over methods, an expanded registry that can manage modules across multiple servers and applications, and potential integrations with different transport layers. Stay tuned for updates!

Comments