new const trait syntax
This commit is contained in:
@@ -44,8 +44,7 @@ impl<T: ColorNum> Color<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[const_trait]
|
||||
pub trait F32Conversion {
|
||||
pub const trait F32Conversion {
|
||||
fn to(self) -> f32;
|
||||
fn from(x: f32) -> Self;
|
||||
}
|
||||
|
||||
27
src/layout/data.rs
Normal file
27
src/layout/data.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::any::{Any, TypeId};
|
||||
|
||||
use crate::util::{HashMap, Id};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UiData {
|
||||
map: HashMap<TypeId, Box<dyn Any>>,
|
||||
}
|
||||
|
||||
impl UiData {
|
||||
pub fn get<T: 'static>(&self) -> Option<&T> {
|
||||
self.map
|
||||
.get(&TypeId::of::<T>())
|
||||
.map(|d| d.downcast_ref().unwrap())
|
||||
}
|
||||
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T> {
|
||||
self.map
|
||||
.get_mut(&TypeId::of::<T>())
|
||||
.map(|d| d.downcast_mut().unwrap())
|
||||
}
|
||||
|
||||
pub fn emit_remove(&mut self, id: &Id) {
|
||||
for (tid, f) in &mut self.on_remove {
|
||||
let data = self.map.get_mut(tid).unwrap().downcast_ref().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#[const_trait]
|
||||
pub trait UiNum {
|
||||
pub const trait UiNum {
|
||||
fn to_f32(self) -> f32;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
use std::ops::*;
|
||||
|
||||
#[const_trait]
|
||||
pub trait LerpUtil {
|
||||
pub const trait LerpUtil {
|
||||
fn lerp(self, from: Self, to: Self) -> Self;
|
||||
fn lerp_inv(self, from: Self, to: Self) -> Self;
|
||||
}
|
||||
|
||||
#[const_trait]
|
||||
pub trait DivOr {
|
||||
pub const trait DivOr {
|
||||
fn div_or(self, rhs: Self, other: Self) -> Self;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user