Creating your first window
Now we're ready to start using GTK+ from Rust. Let's create a new project for our music player:
cargo new rusic --binAdd the dependency on the gio and gtk crates in your Cargo.toml file:
gio = "^0.3.0" gtk = "^0.3.0"
Replace the content of the src/main.rs file with this:
extern crate gio;
extern crate gtk;
use std::env;
use gio::{ApplicationExt, ApplicationExtManual, ApplicationFlags};
use gtk::{
Application,
ApplicationWindow,
WidgetExt,
GtkWindowExt,
};
fn main() {
let application = Application::new("com.github.rust-by-
example", ApplicationFlags::empty())
.expect("Application initialization failed");
application.connect_startup(|application| {
let window = ApplicationWindow::new(&application);
window.set_title("Rusic");
window.show();
});
application.connect_activate(|_| {});
application.run(&env::args().collect::<Vec<_>>());
}Then, run the application with cargo run...