1 unstable release
new 0.0.1 | Mar 8, 2025 |
---|
#871 in #macro-derive
90 downloads per month
32KB
508 lines
OVSDB Derive
A procedural macro crate for Rust to generate code for OVSDB table structs.
Overview
This crate provides two approaches for working with OVSDB tables:
#[ovsdb_object]
attribute macro: Automatically adds_uuid
and_version
fields to your struct#[derive(OVSDB)]
derive macro: requires manual fields but offers more control
Usage
You can either use the attribute macro or the derive macro to generate code for your OVSDB table structs. For more details
on how to use the library, check out the examples in the examples
directory.
Attribute Macro (Recommended)
use ovsdb_derive::ovsdb_object;
use std::collections::HashMap;
#[ovsdb_object]
pub struct NbGlobal {
pub name: Option<String>,
pub nb_cfg: Option<i64>,
pub external_ids: Option<HashMap<String, String>>,
// No need to add _uuid and _version fields
}
Derive Macro (Alternative)
use ovsdb_derive::OVSDB;
use std::collections::HashMap;
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, OVSDB)]
pub struct NbGlobal {
pub name: Option<String>,
pub nb_cfg: Option<i64>,
pub external_ids: Option<HashMap<String, String>>,
// Required fields with the derive approach
pub _uuid: Option<Uuid>,
pub _version: Option<Uuid>,
}
Generated Code
Both macros generate the following implementations:
new()
method that creates a new instance with default valuesto_map()
method that converts the struct to a HashMap for OVSDB serializationfrom_map()
method that creates a struct from a HashMap received from OVSDBDefault
trait implementationserde::Serialize
trait implementationserde::Deserialize
trait implementation
License
This project is licensed under the Apache License, Version 2.0.
Dependencies
~0.9–1.8MB
~37K SLoC