iced-yoda/core/src/window/id.rs
Bingus d53ccc857d
refactored window storage;
new helper window events (Destroyed, Created);
clippy + fmt;
2023-07-21 13:53:38 -07:00

21 lines
597 B
Rust

use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
/// The id of the window.
///
/// Internally Iced reserves `window::Id::MAIN` for the first window spawned.
pub struct Id(u64);
impl Id {
/// The reserved window [`Id`] for the first window in an Iced application.
pub const MAIN: Self = Id(0);
/// Creates a new unique window [`Id`].
pub fn new(id: impl Hash) -> Id {
let mut hasher = DefaultHasher::new();
id.hash(&mut hasher);
Id(hasher.finish())
}
}