aboutsummaryrefslogtreecommitdiff
path: root/samples/rust/rust_print.rs
diff options
context:
space:
mode:
authorGary Guo <[email protected]>2022-11-10 17:41:18 +0100
committerMiguel Ojeda <[email protected]>2022-12-04 01:59:15 +0100
commitb44becc5ee808e02bbda0f90ee0584f206693a33 (patch)
tree88c3ec578019f9a208d9a6251066d136eae97fe6 /samples/rust/rust_print.rs
parent60f18c225f5f6939e348c4b067711d10afd33151 (diff)
rust: macros: add `#[vtable]` proc macro
This procedural macro attribute provides a simple way to declare a trait with a set of operations that later users can partially implement, providing compile-time `HAS_*` boolean associated constants that indicate whether a particular operation was overridden. This is useful as the Rust counterpart to structs like `file_operations` where some pointers may be `NULL`, indicating an operation is not provided. For instance: #[vtable] trait Operations { fn read(...) -> Result<usize> { Err(EINVAL) } fn write(...) -> Result<usize> { Err(EINVAL) } } #[vtable] impl Operations for S { fn read(...) -> Result<usize> { ... } } assert_eq!(<S as Operations>::HAS_READ, true); assert_eq!(<S as Operations>::HAS_WRITE, false); Signed-off-by: Gary Guo <[email protected]> Reviewed-by: Sergio González Collado <[email protected]> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'samples/rust/rust_print.rs')
0 files changed, 0 insertions, 0 deletions