Closed Quantumplation closed 3 years ago
Resolves #3
Amazing, I loved the macro docs, merged!
If proc-macros were to be easier to implement, we could use them to generate the doc URL in compile time.
Instead of:
impl BlockFrostApi {
endpoints! {
/// Return the content of a requested block for a specific slot in an epoch.
blocks_by_epoch_and_slot(epoch_number: Integer, slot_number: Integer) -> Block => "/blocks/epoch/{epoch_number}/slot/{slot_number}";
("https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1epoch~1{epoch_number}~1slot~1{slot_number}/get"),
/// Return the list of blocks following a specific block.
blocks_next(hash_or_number: String) -> Vec<Block> "/blocks/{hash_or_number}/next";
("https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1next/get"),
}
}
Use this:
#[endpoints]
impl BlockFrostApi {
/// Return the content of a requested block for a specific slot in an epoch.
blocks_by_epoch_and_slot(epoch_number: Integer, slot_number: Integer) -> Block { "/blocks/epoch/{epoch_number}/slot/{slot_number}" }
/// Return the list of blocks following a specific block.
blocks_next(hash_or_number: String) -> Vec<Block> { "/blocks/{hash_or_number}/next" }
}
It would just need to replace "/"
by "~1"
.
Maybe in the future, who knows.
A macro_rules macro to make defining endpoints easier;
The syntax is:
In theory supports multiple parameters, different types, etc.
Macros can be a bit dense, so I tried to document how it works; If it causes an issue in the future, tag me and I'll be happy to help fix it!