Skip to content

Commit 455f3fb

Browse files
cyrganinot-fl3
authored andcommitted
make all methods const that can be const on 1.70.0
1 parent 9ce2f73 commit 455f3fb

31 files changed

+88
-88
lines changed

src/color.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ impl Color {
132132
}
133133

134134
/// Create a vec4 of red, green, blue, and alpha components.
135-
pub fn to_vec(&self) -> glam::Vec4 {
135+
pub const fn to_vec(&self) -> glam::Vec4 {
136136
glam::Vec4::new(self.r, self.g, self.b, self.a)
137137
}
138138

139139
/// Create a color from a vec4 of red, green, blue, and alpha components.
140-
pub fn from_vec(vec: glam::Vec4) -> Self {
140+
pub const fn from_vec(vec: glam::Vec4) -> Self {
141141
Self::new(vec.x, vec.y, vec.z, vec.w)
142142
}
143143
}

src/experimental/animation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl AnimatedSprite {
121121
}
122122

123123
/// Currently chosen animation
124-
pub fn current_animation(&self) -> usize {
124+
pub const fn current_animation(&self) -> usize {
125125
self.current_animation
126126
}
127127

src/experimental/camera/mouse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Default for Camera {
2020
}
2121

2222
impl Camera {
23-
pub fn new(offset: Vec2, scale: f32) -> Self {
23+
pub const fn new(offset: Vec2, scale: f32) -> Self {
2424
Self {
2525
offset,
2626
scale,

src/experimental/coroutines.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ enum CoroutineState {
3333
}
3434

3535
impl CoroutineState {
36-
pub fn is_value(&self) -> bool {
36+
pub const fn is_value(&self) -> bool {
3737
matches!(self, CoroutineState::Value(_))
3838
}
3939

40-
pub fn is_nothing(&self) -> bool {
40+
pub const fn is_nothing(&self) -> bool {
4141
matches!(self, CoroutineState::Nothing)
4242
}
4343

@@ -256,7 +256,7 @@ impl Future for TimerDelayFuture {
256256
}
257257
}
258258

259-
pub fn wait_seconds(time: f32) -> TimerDelayFuture {
259+
pub const fn wait_seconds(time: f32) -> TimerDelayFuture {
260260
TimerDelayFuture {
261261
remaining_time: time,
262262
}

src/experimental/scene.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<T: 'static> Clone for Handle<T> {
6464
impl<T: 'static> Copy for Handle<T> {}
6565

6666
impl<T> Handle<T> {
67-
pub fn null() -> Handle<T> {
67+
pub const fn null() -> Handle<T> {
6868
Handle {
6969
id: None,
7070
_marker: PhantomData,
@@ -75,7 +75,7 @@ impl<T> Handle<T> {
7575
HandleUntyped(self.id.unwrap())
7676
}
7777

78-
pub fn as_trait<T1: ?Sized>(&self) {}
78+
pub const fn as_trait<T1: ?Sized>(&self) {}
7979
}
8080

8181
pub(crate) struct Lens<T> {
@@ -127,7 +127,7 @@ pub struct RefMut<T: 'static> {
127127
}
128128

129129
impl<T: 'static> RefMut<T> {
130-
pub fn handle(&self) -> Handle<T> {
130+
pub const fn handle(&self) -> Handle<T> {
131131
Handle {
132132
id: self.handle.id,
133133
_marker: PhantomData,
@@ -190,7 +190,7 @@ pub struct RefMutAny<'a> {
190190
}
191191

192192
impl<'a> RefMutAny<'a> {
193-
pub fn handle<T>(&self) -> Handle<T> {
193+
pub const fn handle<T>(&self) -> Handle<T> {
194194
Handle {
195195
id: Some(self.handle.0),
196196
_marker: PhantomData,
@@ -700,6 +700,6 @@ pub(crate) fn in_fixed_update() -> bool {
700700
unsafe { get_scene() }.in_fixed_update
701701
}
702702

703-
pub(crate) fn fixed_frame_time() -> f32 {
703+
pub(crate) const fn fixed_frame_time() -> f32 {
704704
CONST_FPS as _
705705
}

src/experimental/state_machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<T: scene::Node + 'static> StateMachine<T> {
105105
}
106106
}
107107

108-
pub fn state(&self) -> usize {
108+
pub const fn state(&self) -> usize {
109109
match self {
110110
StateMachine::Ready(state_machine) => state_machine.state(),
111111
StateMachine::InUse {
@@ -178,7 +178,7 @@ impl<T: 'static> StateMachineOwned<T> {
178178
self.next_state = Some(state);
179179
}
180180

181-
pub fn state(&self) -> usize {
181+
pub const fn state(&self) -> usize {
182182
self.current_state
183183
}
184184

src/math/circle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ pub struct Circle {
88
}
99

1010
impl Circle {
11-
pub fn new(x: f32, y: f32, r: f32) -> Self {
11+
pub const fn new(x: f32, y: f32, r: f32) -> Self {
1212
Circle { x, y, r }
1313
}
1414

15-
pub fn point(&self) -> Vec2 {
15+
pub const fn point(&self) -> Vec2 {
1616
vec2(self.x, self.y)
1717
}
1818

19-
pub fn radius(&self) -> f32 {
19+
pub const fn radius(&self) -> f32 {
2020
self.r
2121
}
2222

src/math/rect.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ impl Rect {
1717
/// * `y` - y-coordinate of the top-left corner.
1818
/// * `w` - width of the `Rect`, going to the right.
1919
/// * `h` - height of the `Rect`, going down.
20-
pub fn new(x: f32, y: f32, w: f32, h: f32) -> Rect {
20+
pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Rect {
2121
Rect { x, y, w, h }
2222
}
2323

2424
/// Returns the top-left corner of the `Rect`.
25-
pub fn point(&self) -> Vec2 {
25+
pub const fn point(&self) -> Vec2 {
2626
vec2(self.x, self.y)
2727
}
2828

2929
/// Returns the size (width and height) of the `Rect`.
30-
pub fn size(&self) -> Vec2 {
30+
pub const fn size(&self) -> Vec2 {
3131
vec2(self.w, self.h)
3232
}
3333

@@ -37,7 +37,7 @@ impl Rect {
3737
}
3838

3939
/// Returns the left edge of the `Rect`
40-
pub fn left(&self) -> f32 {
40+
pub const fn left(&self) -> f32 {
4141
self.x
4242
}
4343

@@ -47,7 +47,7 @@ impl Rect {
4747
}
4848

4949
/// Returns the top edge of the `Rect`
50-
pub fn top(&self) -> f32 {
50+
pub const fn top(&self) -> f32 {
5151
self.y
5252
}
5353

@@ -128,7 +128,7 @@ pub struct RectOffset {
128128
}
129129

130130
impl RectOffset {
131-
pub fn new(left: f32, right: f32, top: f32, bottom: f32) -> RectOffset {
131+
pub const fn new(left: f32, right: f32, top: f32, bottom: f32) -> RectOffset {
132132
RectOffset {
133133
left,
134134
right,

src/quad_gl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct DrawCall {
3939
}
4040

4141
impl DrawCall {
42-
fn new(
42+
const fn new(
4343
texture: Option<miniquad::TextureId>,
4444
model: glam::Mat4,
4545
draw_mode: DrawMode,
@@ -534,7 +534,7 @@ impl PipelinesStorage {
534534
GlPipeline(id)
535535
}
536536

537-
fn get(&self, draw_mode: DrawMode, depth_enabled: bool) -> GlPipeline {
537+
const fn get(&self, draw_mode: DrawMode, depth_enabled: bool) -> GlPipeline {
538538
match (draw_mode, depth_enabled) {
539539
(DrawMode::Triangles, false) => Self::TRIANGLES_PIPELINE,
540540
(DrawMode::Triangles, true) => Self::TRIANGLES_DEPTH_PIPELINE,
@@ -814,11 +814,11 @@ impl QuadGl {
814814
crate::get_context().projection_matrix()
815815
}
816816

817-
pub fn get_active_render_pass(&self) -> Option<RenderPass> {
817+
pub const fn get_active_render_pass(&self) -> Option<RenderPass> {
818818
self.state.render_pass
819819
}
820820

821-
pub fn is_depth_test_enabled(&self) -> bool {
821+
pub const fn is_depth_test_enabled(&self) -> bool {
822822
self.state.depth_test_enable
823823
}
824824

src/telemetry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub struct Frame {
145145
}
146146

147147
impl Frame {
148-
fn new() -> Frame {
148+
const fn new() -> Frame {
149149
Frame {
150150
full_frame_time: 0.0,
151151
zones: vec![],

src/text/atlas.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ impl Atlas {
7878
self.sprites.get(&key).cloned()
7979
}
8080

81-
pub fn width(&self) -> u16 {
81+
pub const fn width(&self) -> u16 {
8282
self.image.width
8383
}
8484

85-
pub fn height(&self) -> u16 {
85+
pub const fn height(&self) -> u16 {
8686
self.image.height
8787
}
8888

src/texture.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl TexturesContext {
4848
// fn remove(&mut self, texture: TextureSlotId) {
4949
// self.textures.remove(texture);
5050
// }
51-
pub fn len(&self) -> usize {
51+
pub const fn len(&self) -> usize {
5252
self.textures.len()
5353
}
5454
pub fn garbage_collect(&mut self, ctx: &mut miniquad::Context) {
@@ -86,7 +86,7 @@ impl Image {
8686
/// # use macroquad::prelude::*;
8787
/// let image = Image::empty();
8888
/// ```
89-
pub fn empty() -> Image {
89+
pub const fn empty() -> Image {
9090
Image {
9191
width: 0,
9292
height: 0,
@@ -157,12 +157,12 @@ impl Image {
157157
}
158158

159159
/// Returns the width of this image.
160-
pub fn width(&self) -> usize {
160+
pub const fn width(&self) -> usize {
161161
self.width as usize
162162
}
163163

164164
/// Returns the height of this image.
165-
pub fn height(&self) -> usize {
165+
pub const fn height(&self) -> usize {
166166
self.height as usize
167167
}
168168

@@ -611,7 +611,7 @@ impl Texture2D {
611611
},
612612
}
613613
}
614-
pub(crate) fn unmanaged(texture: miniquad::TextureId) -> Texture2D {
614+
pub(crate) const fn unmanaged(texture: miniquad::TextureId) -> Texture2D {
615615
Texture2D {
616616
texture: TextureHandle::Unmanaged(texture),
617617
}
@@ -672,7 +672,7 @@ impl Texture2D {
672672

673673
/// Creates a Texture2D from a miniquad
674674
/// [Texture](https://docs.rs/miniquad/0.3.0-alpha/miniquad/graphics/struct.Texture.html)
675-
pub fn from_miniquad_texture(texture: miniquad::TextureId) -> Texture2D {
675+
pub const fn from_miniquad_texture(texture: miniquad::TextureId) -> Texture2D {
676676
Texture2D {
677677
texture: TextureHandle::Unmanaged(texture),
678678
}

src/texture/slotmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl TextureIdSlotMap {
6262
}
6363

6464
/// Returns the number of elements in the slot map.
65-
pub fn len(&self) -> usize {
65+
pub const fn len(&self) -> usize {
6666
self.num_elems as usize
6767
}
6868

src/ui.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ impl Window {
192192
);
193193
}
194194

195-
pub fn top_level(&self) -> bool {
195+
pub const fn top_level(&self) -> bool {
196196
self.parent.is_none()
197197
}
198198

199-
pub fn full_rect(&self) -> Rect {
199+
pub const fn full_rect(&self) -> Rect {
200200
Rect::new(self.position.x, self.position.y, self.size.x, self.size.y)
201201
}
202202

@@ -215,7 +215,7 @@ impl Window {
215215
self.cursor.area.y = position.y + self.title_height + self.window_margin.top;
216216
}
217217

218-
pub fn title_rect(&self) -> Rect {
218+
pub const fn title_rect(&self) -> Rect {
219219
Rect::new(
220220
self.position.x,
221221
self.position.y,
@@ -267,7 +267,7 @@ pub(crate) struct TabSelector {
267267
}
268268

269269
impl TabSelector {
270-
fn new() -> Self {
270+
const fn new() -> Self {
271271
TabSelector {
272272
counter: 0,
273273
wants: None,
@@ -970,7 +970,7 @@ impl Ui {
970970
)
971971
}
972972

973-
pub fn is_mouse_captured(&self) -> bool {
973+
pub const fn is_mouse_captured(&self) -> bool {
974974
self.input.cursor_grabbed
975975
}
976976

@@ -998,7 +998,7 @@ impl Ui {
998998
self.active_window.map_or(false, |wnd| self.is_focused(wnd))
999999
}
10001000

1001-
pub fn is_dragging(&self) -> bool {
1001+
pub const fn is_dragging(&self) -> bool {
10021002
self.dragging.is_some()
10031003
}
10041004

src/ui/cursor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct Cursor {
5454
}
5555

5656
impl Cursor {
57-
pub fn new(area: Rect, margin: f32) -> Cursor {
57+
pub const fn new(area: Rect, margin: f32) -> Cursor {
5858
Cursor {
5959
margin,
6060
x: margin,

src/ui/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ pub struct Input {
3131
}
3232

3333
impl Input {
34-
pub fn is_mouse_down(&self) -> bool {
34+
pub const fn is_mouse_down(&self) -> bool {
3535
self.is_mouse_down && self.cursor_grabbed == false && self.window_active
3636
}
3737

38-
pub fn click_down(&self) -> bool {
38+
pub const fn click_down(&self) -> bool {
3939
self.click_down && self.cursor_grabbed == false && self.window_active
4040
}
4141

42-
pub fn click_up(&self) -> bool {
42+
pub const fn click_up(&self) -> bool {
4343
self.click_up && self.cursor_grabbed == false && self.window_active
4444
}
4545

src/ui/render/mesh_rasterizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct DrawList {
2121
}
2222

2323
impl DrawList {
24-
pub fn new() -> DrawList {
24+
pub const fn new() -> DrawList {
2525
DrawList {
2626
vertices: vec![],
2727
indices: vec![],

0 commit comments

Comments
 (0)