Macro axns::def_resource
source · macro_rules! def_resource { ( $( $(#[$attr:meta])* $vis:vis static $name:ident: $ty:ty = $default:expr; )+ ) => { ... }; }
Expand description
Defines a resource that managed by AxNamespace
.
Each resource will be collected into the axns_resource
section. When
accessed, it is either dereferenced from the global namespace or the
thread-local namespace according to the thread-local
feature.
§Example
use axns::AxResource;
axns::def_resource! {
static FOO: u32 = 42;
static BAR: AxResource<String> = AxResource::new();
}
BAR.init_new("hello world".to_string());
assert_eq!(*FOO, 42);
assert_eq!(BAR.as_str(), "hello world");
mod imp {
use axns::{AxNamespace, AxNamespaceIf};
struct AxResourceImpl;
#[crate_interface::impl_interface]
impl AxNamespaceIf for AxResourceImpl {
fn current_namespace_base() -> *mut u8 {
AxNamespace::global().base()
}
}
}