Skip to content

Commit

Permalink
make dummy() functions const
Browse files Browse the repository at this point in the history
  • Loading branch information
filnet committed Aug 24, 2021
1 parent 898a6af commit 7b36070
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 51 deletions.
70 changes: 37 additions & 33 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,51 +446,55 @@ impl Clone for WindowEvent<'static> {
}

impl<'a> WindowEvent<'a> {
pub fn to_static(self) -> Option<WindowEvent<'static>> {
pub fn to_static(&self) -> Option<WindowEvent<'static>> {
use self::WindowEvent::*;
match self {
Resized(size) => Some(Resized(size)),
Moved(position) => Some(Moved(position)),
Resized(size) => Some(Resized(*size)),
Moved(position) => Some(Moved(*position)),
CloseRequested => Some(CloseRequested),
Destroyed => Some(Destroyed),
DroppedFile(file) => Some(DroppedFile(file)),
HoveredFile(file) => Some(HoveredFile(file)),
DroppedFile(file) => Some(DroppedFile(file.clone())),
HoveredFile(file) => Some(HoveredFile(file.clone())),
HoveredFileCancelled => Some(HoveredFileCancelled),
ReceivedCharacter(c) => Some(ReceivedCharacter(c)),
Focused(focused) => Some(Focused(focused)),
ReceivedCharacter(c) => Some(ReceivedCharacter(*c)),
Focused(focused) => Some(Focused(*focused)),
KeyboardInput {
device_id,
input,
is_synthetic,
} => Some(KeyboardInput {
device_id,
input,
is_synthetic,
device_id: *device_id,
input: *input,
is_synthetic: *is_synthetic,
}),
ModifiersChanged(modifiers) => Some(ModifiersChanged(modifiers)),
ModifiersChanged(modifiers) => Some(ModifiersChanged(*modifiers)),
#[allow(deprecated)]
CursorMoved {
device_id,
position,
modifiers,
} => Some(CursorMoved {
device_id,
position,
modifiers,
device_id: *device_id,
position: *position,
modifiers: *modifiers,
}),
CursorEntered { device_id } => Some(CursorEntered {
device_id: *device_id,
}),
CursorLeft { device_id } => Some(CursorLeft {
device_id: *device_id,
}),
CursorEntered { device_id } => Some(CursorEntered { device_id }),
CursorLeft { device_id } => Some(CursorLeft { device_id }),
#[allow(deprecated)]
MouseWheel {
device_id,
delta,
phase,
modifiers,
} => Some(MouseWheel {
device_id,
delta,
phase,
modifiers,
device_id: *device_id,
delta: *delta,
phase: *phase,
modifiers: *modifiers,
}),
#[allow(deprecated)]
MouseInput {
Expand All @@ -499,31 +503,31 @@ impl<'a> WindowEvent<'a> {
button,
modifiers,
} => Some(MouseInput {
device_id,
state,
button,
modifiers,
device_id: *device_id,
state: *state,
button: *button,
modifiers: *modifiers,
}),
TouchpadPressure {
device_id,
pressure,
stage,
} => Some(TouchpadPressure {
device_id,
pressure,
stage,
device_id: *device_id,
pressure: *pressure,
stage: *stage,
}),
AxisMotion {
device_id,
axis,
value,
} => Some(AxisMotion {
device_id,
axis,
value,
device_id: *device_id,
axis: *axis,
value: *value,
}),
Touch(touch) => Some(Touch(touch)),
ThemeChanged(theme) => Some(ThemeChanged(theme)),
Touch(touch) => Some(Touch(*touch)),
ThemeChanged(theme) => Some(ThemeChanged(*theme)),
ScaleFactorChanged { .. } => None,
}
}
Expand All @@ -547,7 +551,7 @@ impl DeviceId {
/// No other guarantees are made. This may be equal to a real `DeviceId`.
///
/// **Passing this into a winit function will result in undefined behavior.**
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId(platform_impl::DeviceId::dummy())
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl<T: 'static> EventLoopWindowTarget<T> {
pub struct WindowId;

impl WindowId {
pub fn dummy() -> Self {
pub const fn dummy() -> Self {
WindowId
}
}
Expand All @@ -452,7 +452,7 @@ impl WindowId {
pub struct DeviceId;

impl DeviceId {
pub fn dummy() -> Self {
pub const fn dummy() -> Self {
DeviceId
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct DeviceId {
}

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId {
uiscreen: std::ptr::null_mut(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub struct WindowId {
}

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
WindowId {
window: std::ptr::null_mut(),
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub enum WindowId {
}

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
#[cfg(feature = "wayland")]
return WindowId::Wayland(wayland::WindowId::dummy());
#[cfg(all(not(feature = "wayland"), feature = "x11"))]
Expand All @@ -158,7 +158,7 @@ pub enum DeviceId {
}

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
#[cfg(feature = "wayland")]
return DeviceId::Wayland(wayland::DeviceId::dummy());
#[cfg(all(not(feature = "wayland"), feature = "x11"))]
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod window;
pub struct DeviceId;

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId
}
}
Expand All @@ -31,7 +31,7 @@ impl DeviceId {
pub struct WindowId(usize);

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
WindowId(0)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl<'a> Deref for DeviceInfo<'a> {
pub struct WindowId(ffi::Window);

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
WindowId(0)
}
}
Expand All @@ -499,7 +499,7 @@ impl WindowId {
pub struct DeviceId(c_int);

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId(0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) use crate::icon::NoIcon as PlatformIcon;
pub struct DeviceId;

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use objc::{
pub struct Id(pub usize);

impl Id {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
Id(0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/web/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub struct Id(pub i32);

impl Id {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
Id(0)
}
}
5 changes: 3 additions & 2 deletions src/platform_impl/windows/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::dpi::PhysicalSize;
use crate::icon::*;

impl Pixel {
fn to_bgra(&mut self) {
/// In place convert pixel from (assumed) rgba to bgra
fn convert_to_bgra(&mut self) {
mem::swap(&mut self.r, &mut self.b);
}
}
Expand All @@ -28,7 +29,7 @@ impl RgbaIcon {
unsafe { std::slice::from_raw_parts_mut(rgba.as_mut_ptr() as *mut Pixel, pixel_count) };
for pixel in pixels {
and_mask.push(pixel.a.wrapping_sub(std::u8::MAX)); // invert alpha channel
pixel.to_bgra();
pixel.convert_to_bgra();
}
assert_eq!(and_mask.len(), pixel_count);
let handle = unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ unsafe impl Sync for Cursor {}
pub struct DeviceId(u32);

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId(0)
}
}
Expand Down Expand Up @@ -88,7 +88,7 @@ unsafe impl Send for WindowId {}
unsafe impl Sync for WindowId {}

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
use std::ptr::null_mut;

WindowId(null_mut())
Expand Down
2 changes: 1 addition & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl WindowId {
/// No other guarantees are made. This may be equal to a real `WindowId`.
///
/// **Passing this into a winit function will result in undefined behavior.**
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
WindowId(platform_impl::WindowId::dummy())
}
}
Expand Down

0 comments on commit 7b36070

Please sign in to comment.