[英]Unable to print in a procedural macro function declaration in Rust
我正在使用proc_macro
並想打印一些詳細信息以進行調試。 println!
語句不打印任何內容。
這是宏調用:
decl_module! {
/// The module declaration.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
// A default function for depositing events
fn deposit_event() = default;
/// Allow a user to claim ownership of an unclaimed proof
fn create_claim(origin, proof: Vec<u8>) -> DispatchResult {
// Verify that the incoming transaction is signed and store who the
// caller of this function is.
let sender = ensure_signed(origin)?;
println!("send is: {}", sender);
// Verify that the specified proof has not been claimed yet or error with the message
ensure!(!Proofs::<T>::exists(&proof), "This proof has already been claimed.");
// Call the `system` pallet to get the current block number
let current_block = <system::Module<T>>::block_number();
// Store the proof with the sender and the current block number
Proofs::<T>::insert(&proof, (sender.clone(), current_block));
// Emit an event that the claim was created
Self::deposit_event(RawEvent::ClaimCreated(sender, proof));
Ok(())
}
/// Allow the owner to revoke their claim
fn revoke_claim(origin, proof: Vec<u8>) -> DispatchResult {
// Determine who is calling the function
let sender = ensure_signed(origin)?;
// Verify that the specified proof has been claimed
ensure!(Proofs::<T>::exists(&proof), "This proof has not been stored yet.");
// Get owner of the claim
let (owner, _) = Proofs::<T>::get(&proof);
// Verify that sender of the current call is the claim owner
ensure!(sender == owner, "You must own this claim to revoke it.");
// Remove claim from storage
Proofs::<T>::remove(&proof);
// Emit an event that the claim was erased
Self::deposit_event(RawEvent::ClaimRevoked(sender, proof));
Ok(())
}
}
}
它是從這里拍攝的。 我添加了以下行:
println!("send is: {}", sender);
我正在運行一個區塊鏈(Polkadot dApp),在終端(或任何地方),我看不到輸出消息。 注意:一切正常,但我無法打印。
此宏調用生成包含打印語句的代碼。 它不運行該代碼。 在運行代碼並調用create_claim
之前,您不會看到打印輸出。
如果你想調試你的宏調用,有幾個宏示例的工具,但我不知道它們是否也適用於程序宏,或者是否有等價物。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.