Texture2D 类型与 raylib Rust 的预期不符

问题描述 投票:0回答:1

我有以下代码块,我试图在其中创建一个新的

Texture2D

let texture: Texture2D = *handle
        .load_texture(&thread, &path)
        .expect(&format!("Failed to load texture: {}", path));

根据文档,

load_texture()
函数应该返回一个
Texture2D

raylib::core::texture::RaylibHandle
pub fn load_texture(&mut self, _: &RaylibThread, filename: &str) -> Result<Texture2D, String>

但是,当尝试这样做时,我遇到了不匹配的类型,

Texture
而不是预期的
Texture2D

error[E0308]: mismatched types
  --> src/engine/texture.rs:13:30
   |
13 |       let texture: Texture2D = *handle
   |  __________________---------___^
   | |                  |
   | |                  expected due to this
14 | |         .load_texture(&thread, &path)
15 | |         .expect(&format!("Failed to load texture: {}", path));
   | |_____________________________________________________________^ expected `Texture2D`, found `Texture`
rust types textures raylib
1个回答
0
投票

请注意,错误专门指向

*

load_texture
does 返回
Texture2D
,但您会立即将其取消引用为
raylib::ffi::Texture

我怀疑你只是想取消引用

handle
,而不是整个表达式。为此,您需要执行
(*handle)
- 尽管这可能只会导致不同的错误,因为您将尝试移出不可变的引用。

我认为真正的解决方案就是完全删除

*

© www.soinside.com 2019 - 2024. All rights reserved.