fix macro generation, doc test

This commit is contained in:
hinto.janai 2024-06-03 16:32:26 -04:00
parent 9fa5d24e3a
commit b41b7dd557
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
4 changed files with 82 additions and 14 deletions

View file

@ -9,7 +9,7 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/rpc/monero-rpc-types
keywords = ["monero", "rpc", "types"]
[features]
default = ["dep:serde"]
default = ["serde"]
[dependencies]
monero-serai = { workspace = true }

View file

@ -1,8 +1,20 @@
//! TODO
//!
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
//---------------------------------------------------------------------------------------------------- Import
use crate::macros::define_monero_rpc_type_struct;
//---------------------------------------------------------------------------------------------------- TODO
define_monero_rpc_type_struct! {
get_height,
daemon_messages.h => 81..=87,
GetHeight { height: 123 } => r#"{"height":123}"#,
GetHeight {
/// A block height.
height: u64,
}
}
//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]

View file

@ -76,6 +76,9 @@
// FIXME: good lint but is less clear in most cases.
clippy::items_after_statements,
// TODO
rustdoc::bare_urls,
clippy::module_name_repetitions,
clippy::module_inception,
clippy::redundant_pub_crate,

View file

@ -2,22 +2,75 @@
//!
//! These generate repetitive documentation, tests, etc.
//---------------------------------------------------------------------------------------------------- Documentation macros
//---------------------------------------------------------------------------------------------------- Struct definition
/// TODO
macro_rules! serde_doc_test {
macro_rules! define_monero_rpc_type_struct {
(
$type:ty, // TODO
$monero_daemon_rpc_doc_link:ident, // TODO
$monero_code_filename:ident.$monero_code_filename_extension:ident => // TODO
$monero_code_line_start:literal..= // TODO
$monero_code_line_end:literal, // TODO
$type_literal:expr => // TODO
$type_as_json:literal, // TODO
$type_name:ident { // TODO
$(
$( #[$field_attr:meta] )* // TODO
$field:ident: $type:ty, // TODO
)*
}
) => {
#[doc = "TODO"]
///
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
///
// Documents the original Monero type and where it is located in `monero-project/monero`.
#[doc = concat!(
"",
"Definition: [`",
stringify!($monero_code_filename),
".",
stringify!($monero_code_filename_extension),
" @ ",
stringify!($monero_code_line_start),
"..=",
stringify!($monero_code_line_end),
"`](",
"https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/",
stringify!($monero_code_filename),
".",
stringify!($monero_code_filename_extension),
"#L",
stringify!($monero_code_line_start),
"-L",
stringify!($monero_code_line_end),
"), documentation: [`",
stringify!($monero_daemon_rpc_doc_link),
"`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html",
"#",
stringify!($monero_daemon_rpc_doc_link),
").",
)]
///
// Doc-test that tests (de)serialization.
/// # `serde` example
/// ```rust
#[doc = "# use monero_rpc_types::{json::*, binary::*, data::*, mix::*};"]
#[doc = concat!("let t = ", stringify!($type_literal), ";")]
#[doc = "let string = serde_json::to_string(&t).unwrap();"]
#[doc = concat!("assert_eq!(string, ", stringify!($type_as_json), ");")]
#[doc = ""]
#[doc = "let t2 = serde_json::from_str(&string).unwrap();"]
#[doc = "assert_eq!(t, t2);"]
/// ```
// The type.
pub struct $type_name {
$(
$( #[$field_attr] )*
pub $field: $type,
)*
}
};
}
pub(crate) use define_monero_rpc_type_struct;
/// TODO
macro_rules! monero_ref {
(
$monero_code_link:literal, // TODO
$monero_rpc_doc_link:literal, // TODO
) => {
#[doc = "TODO"]
};
}
//---------------------------------------------------------------------------------------------------- Documentation macros