【问题标题】:Scrypto Importing Structs from other folderScrypto 从其他文件夹导入结构
【发布时间】:2022-07-16 22:41:02
【问题描述】:

在 Scrypto 中,我的文件夹结构如下:

src/
├── lib.rs
├── script.rs
├── custom_types
│   └── type.rs

type.rs 中,我定义了以下内容:


use sbor::*;

#[derive(TypeId, Encode, Decode, Describe)]
pub struct Date {
    year: u8,
    day: u8,
    month: u8,
}

我希望能够在script.rs 中使用Date 结构,我该怎么做?

【问题讨论】:

    标签: rust scrypto


    【解决方案1】:

    组织文件,如:

    src/
    ├── lib.rs
    ├── script.rs
    ├── custom_types
    │   └── type.rs
    │   └── mod.rs
    

    mod.rs:

    pub mod type;
    

    将以下内容添加到script.rs

    use super::custom_types::type::Date;
    
    ...
    

    最后,将以下内容添加到lib.rs

    mod datatypes;
    

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-16
      相关资源
      最近更新 更多