【问题标题】:error[E0412]: cannot find type `String` in this scope错误[E0412]:在此范围内找不到类型“字符串”
【发布时间】:2021-10-06 14:50:14
【问题描述】:
#![cfg_attr(not(feature = "std"), no_std)]

use ink_lang as ink;

#[ink::contract]

mod XYZ {

    #[ink(storage)]
    pub struct Xyz {
        token_id: u32,
        serial_code: String
    }
    ...
}

错误:

             serial_code: String
   |                      ^^^^^^ not found in this scope

【问题讨论】:

  • 你明确排除 std 有什么原因吗?
  • String 不是 Substrate 和 Ink 环境的一部分,因为它会增加二进制/编译后的大小(可能是因为 UTF8 处理)。如果需要,请使用Vec<u8> 存储此类数据。

标签: rust substrate rust-ink


【解决方案1】:

基于this - 您应该使用包含在中的String 类型 ink!

use ink_prelude::string::String;

并包含在正确的 Cargo.toml 文件中:

[Dependencies]
ink_prelude = { version = "2", git = "github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }"

(或任何适合您的版本)

【讨论】:

  • 包含上述内容后,包括"ink_prelude = { version = "2", git = "github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = Cargo.toml 文件的 [dependencies] 中的 false }"。
猜你喜欢
  • 2022-11-27
  • 2021-12-06
  • 1970-01-01
  • 1970-01-01
  • 2019-10-30
  • 1970-01-01
  • 2021-09-24
  • 2021-09-21
  • 2021-08-01
相关资源
最近更新 更多