[英]Can't use the conrod library in my Rust project: can't find crate piston_window
我是Rust的新手,我想使用canvas.rs
庫打開一個窗口,就像在canvas.rs
示例中所做的canvas.rs
:
#[macro_use] extern crate conrod;
extern crate find_folder;
extern crate piston_window;
use conrod::{Canvas, Theme, Widget, color};
use piston_window::{EventLoop, OpenGL, PistonWindow, UpdateEvent, WindowSettings};
fn main() {
const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
// Change this to OpenGL::V2_1 if not working.
let opengl = OpenGL::V3_2;
// Construct the window.
let mut window: PistonWindow =
WindowSettings::new("Canvas Demo", [WIDTH, HEIGHT].opengl(opengl).exit_on_esc(true).vsync(true).build().unwrap();
window.set_ups(60);
}
當我在Conrod項目(從GitHub下載的那個)的一個文件中使用它時,此代碼有效,但是當我在自己的代碼中使用它時,此代碼不起作用:
extern crate conrod;
extern crate piston_window;
fn main() {
println!("Hello, world!");
}
使用以下Cargo.toml:
[package]
name = "hello_conrod"
version = "0.1.0"
authors = ["omega"]
[dependencies]
conrod = "0.37.2"
然后編譯器告訴我:
error: can't find crate for `piston_window` [E0463]
我猜我的Cargo.toml
是錯誤的,但是我不知道該怎么辦。
您需要從crates.io中找到piston_window板條箱 。 只需將其添加到依賴Cargo.toml
下的Cargo.toml
:
piston_window = "0.51.1"
每當看到extern crate _
,您都需要在Cargo.toml
文件中添加包裝箱。 crates.io上的文檔顯示了導入包裝箱的不同方式(本地,可選地,從Git等)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.