initial commit

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ib131388c1056b6708b730a35011811026a6a6964
This commit is contained in:
raf 2026-02-18 20:13:00 +03:00
commit 033e253259
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
33 changed files with 3126 additions and 0 deletions

14
pscand-macros/Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[package]
name = "pscand-macros"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
[lib]
proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["full"] }

62
pscand-macros/src/lib.rs Normal file
View file

@ -0,0 +1,62 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};
#[proc_macro_attribute]
pub fn scanner(name: TokenStream, input: TokenStream) -> TokenStream {
let name_str = parse_macro_input!(name as syn::LitStr).value();
let input = parse_macro_input!(input as ItemFn);
let _fn_name = input.sig.ident.clone();
let body = &input.block;
let result = quote! {
#[no_mangle]
pub extern "C" fn pscand_scanner() -> Box<dyn pscand_core::Scanner> {
struct ScannerImpl;
impl pscand_core::Scanner for ScannerImpl {
fn name(&self) -> &'static str {
#name_str
}
fn interval(&self) -> std::time::Duration {
std::time::Duration::from_secs(1)
}
fn init(&mut self, _config: &toml::Value) -> pscand_core::Result<()> {
Ok(())
}
fn collect(&self) -> pscand_core::Result<std::collections::HashMap<String, pscand_core::MetricValue>> {
#body
}
fn cleanup(&mut self) -> pscand_core::Result<()> {
Ok(())
}
}
Box::new(ScannerImpl)
}
};
result.into()
}
#[proc_macro]
pub fn register_scanner(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemFn);
let fn_name = input.sig.ident.clone();
let result = quote! {
#input
#[no_mangle]
pub extern "C" fn pscand_scanner() -> Box<dyn pscand_core::Scanner> {
Box::new(#fn_name())
}
};
result.into()
}