Damn you, clippy

This commit is contained in:
Joonas Javanainen 2020-09-19 20:31:31 +03:00
parent 646d7d6de4
commit 50c630bb58
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
2 changed files with 30 additions and 19 deletions

View File

@ -119,47 +119,58 @@ pub enum DataType {
/// representation in memory as the primitive value described by the associated `KIND` constant.
pub unsafe trait DataTypeKind: Copy {
const KIND: DataType;
const SLIDER_RANGE: RangeInclusive<Self>;
const SLIDER_MIN: Self;
const SLIDER_MAX: Self;
}
unsafe impl DataTypeKind for i8 {
const KIND: DataType = DataType::I8;
const SLIDER_RANGE: RangeInclusive<i8> = i8::MIN..=i8::MAX;
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for u8 {
const KIND: DataType = DataType::U8;
const SLIDER_RANGE: RangeInclusive<u8> = u8::MIN..=u8::MAX;
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for i16 {
const KIND: DataType = DataType::I16;
const SLIDER_RANGE: RangeInclusive<i16> = i16::MIN..=i16::MAX;
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for u16 {
const KIND: DataType = DataType::U16;
const SLIDER_RANGE: RangeInclusive<u16> = u16::MIN..=u16::MAX;
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for i32 {
const KIND: DataType = DataType::I32;
const SLIDER_RANGE: RangeInclusive<i32> = (i32::MIN / 2)..=(i32::MAX / 2);
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for u32 {
const KIND: DataType = DataType::U32;
const SLIDER_RANGE: RangeInclusive<u32> = (u32::MIN / 2)..=(u32::MAX / 2);
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for i64 {
const KIND: DataType = DataType::I64;
const SLIDER_RANGE: RangeInclusive<i64> = (i64::MIN / 2)..=(i64::MAX / 2);
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for u64 {
const KIND: DataType = DataType::U64;
const SLIDER_RANGE: RangeInclusive<u64> = (u64::MIN / 2)..=(u64::MAX / 2);
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for f32 {
const KIND: DataType = DataType::F32;
const SLIDER_RANGE: RangeInclusive<f32> = (f32::MIN / 2.0)..=(f32::MAX / 2.0);
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
unsafe impl DataTypeKind for f64 {
const KIND: DataType = DataType::F64;
const SLIDER_RANGE: RangeInclusive<f64> = (f64::MIN / 2.0)..=(f64::MAX / 2.0);
const SLIDER_MIN: Self = Self::MIN;
const SLIDER_MAX: Self = Self::MAX;
}
pub trait InclusiveRangeBounds<T: Copy> {

View File

@ -40,8 +40,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
pub fn new(label: &ImStr) -> Slider<T> {
Slider {
label,
min: *T::SLIDER_RANGE.start(),
max: *T::SLIDER_RANGE.end(),
min: T::SLIDER_MIN,
max: T::SLIDER_MAX,
display_format: None,
flags: SliderFlags::empty(),
}
@ -49,8 +49,8 @@ impl<'a, T: DataTypeKind> Slider<'a, T> {
/// Sets the range (inclusive)
#[inline]
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
self.min = *range.start_bound().unwrap_or(T::SLIDER_RANGE.start());
self.max = *range.end_bound().unwrap_or(T::SLIDER_RANGE.end());
self.min = range.start_bound().copied().unwrap_or(T::SLIDER_MIN);
self.max = range.end_bound().copied().unwrap_or(T::SLIDER_MAX);
self
}
/// Sets the display format using *a C-style printf string*
@ -122,8 +122,8 @@ impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
VerticalSlider {
label,
size,
min: *T::SLIDER_RANGE.start(),
max: *T::SLIDER_RANGE.end(),
min: T::SLIDER_MIN,
max: T::SLIDER_MAX,
display_format: None,
flags: SliderFlags::empty(),
}
@ -131,8 +131,8 @@ impl<'a, T: DataTypeKind> VerticalSlider<'a, T> {
/// Sets the range (inclusive)
#[inline]
pub fn range<R: InclusiveRangeBounds<T>>(mut self, range: R) -> Self {
self.min = *range.start_bound().unwrap_or(T::SLIDER_RANGE.start());
self.max = *range.end_bound().unwrap_or(T::SLIDER_RANGE.end());
self.min = range.start_bound().copied().unwrap_or(T::SLIDER_MIN);
self.max = range.end_bound().copied().unwrap_or(T::SLIDER_MAX);
self
}
/// Sets the display format using *a C-style printf string*