首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Rust中的过程宏函数声明中打印

无法在Rust中的过程宏函数声明中打印
EN

Stack Overflow用户
提问于 2020-02-20 16:03:17
回答 1查看 580关注 0票数 0

我正在使用一个proc_macro,并希望打印一些详细的调试。println!语句不打印任何内容。

这是宏调用:

代码语言:javascript
复制
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(())
        }
    }
}

它是取自这里的。我增加了以下一行:

代码语言:javascript
复制
println!("send is: {}", sender);

我正在运行块链(Polkadot dApp),在终端(或任何地方)中,我看不到输出消息。注:一切正常,但我无法打印。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-21 08:01:17

此宏调用生成包含打印语句的代码。它不会运行这段代码。在运行代码并调用create_claim之前,您将不会看到打印输出。

如果您想调试宏调用,有几个工具用于宏逐个示例,但我不知道它们是否也适用于过程宏,或者是否存在等效的宏。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60324053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档