小编n3r*_*3x3的帖子

期望一个具有固定大小 x 元素的数组,找到一个具有 y 元素的数组

我正在尝试根据正在编译应用程序的设备来更改应用程序的图标(我正在使用 crate 加载image) 。不幸的是,当尝试运行代码时:

    let (icon_rgba, icon_width, icon_height) = {
        let icon = if cfg!(target_os = "macos") {
            include_bytes!("../assets/icon-macos.png")
        } else {
            include_bytes!("../assets/icon.png")
        };
        let image = image::load_from_memory(icon)
            .expect("Failed to open icon path")
            .into_rgba8();
        let (width, height) = image.dimensions();
        let rgba = image.into_raw();
        (rgba, width, height)
    };
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

error[E0308]: `if` and `else` have incompatible types
 --> src/main.rs:6:13
  |
3 |           let icon = if cfg!(target_os = "macos") {
  |  ____________________-
4 | |             include_bytes!("../assets/icon-macos.png")
  | |             ------------------------------- …
Run Code Online (Sandbox Code Playgroud)

rust

1
推荐指数
2
解决办法
180
查看次数

标签 统计

rust ×1