| Crates.io | ovsdb-derive |
| lib.rs | ovsdb-derive |
| version | 0.0.1 |
| created_at | 2025-03-08 04:54:42.314765+00 |
| updated_at | 2025-03-08 04:54:42.314765+00 |
| description | Derive macro for OVSDB table structs |
| homepage | |
| repository | https://review.vexxhost.dev/plugins/gitiles/ovsdb |
| max_upload_size | |
| id | 1584082 |
| size | 23,741 |
A procedural macro crate for Rust to generate code for OVSDB table structs.
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 controlYou 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.
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
}
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>,
}
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 implementationThis project is licensed under the Apache License, Version 2.0.