Use impl Into<T> #71

Closed
opened 2024-08-12 09:17:23 +00:00 by suprohub · 4 comments
suprohub commented 2024-08-12 09:17:23 +00:00 (Migrated from github.com)

some functions like set_color or set position use multiple arguments, it bit discomfort if you want set position of tuple or Array4.
Solution: position: impl Into<Array4>

some functions like set_color or set position use multiple arguments, it bit discomfort if you want set position of tuple or Array4. Solution: `position: impl Into<Array4>`
suprohub commented 2024-08-12 09:20:43 +00:00 (Migrated from github.com)

or use from

or use from
ElhamAryanpur commented 2024-08-12 17:27:13 +00:00 (Migrated from github.com)

The issue with that is that the function does more than setting just values, it also updates the uniform buffer and transform matrices.

A solution can be to add a whole new copy of the functions that accepts from array/list and internally maps them. But that will add extra confusion and cluttering.

e.g.

// the main
fn set_position(&mut self, x: f32, y: f32, z: f32);

// for array, an extra function can be added
fn set_position_with_array(&mut self, value: impl Into<[f32; 3]>) {
    self.set_position(value[0], value[1], value[2]);
}
The issue with that is that the function does more than setting just values, it also updates the uniform buffer and transform matrices. A solution can be to add a whole new copy of the functions that accepts from array/list and internally maps them. But that will add extra confusion and cluttering. e.g. ```rs // the main fn set_position(&mut self, x: f32, y: f32, z: f32); // for array, an extra function can be added fn set_position_with_array(&mut self, value: impl Into<[f32; 3]>) { self.set_position(value[0], value[1], value[2]); } ```
ElhamAryanpur commented 2024-08-12 17:30:26 +00:00 (Migrated from github.com)

@Gipson62 @NickJasonHagen What do you guys think?

@Gipson62 @NickJasonHagen What do you guys think?
Gipson62 commented 2025-01-11 13:55:17 +00:00 (Migrated from github.com)

Honestly, having more functions like this would help, it'll help as much as functions overloading is useful in OOP languages and don't most people use the set_position() like this already?

let pos: Position3D = ...;
set_position(pos.x, pos.y, pos.z);

So making it takes an impl Into<[f32; 3]> instead of 3 f32 wouldn't be stupid imho

Honestly, having more functions like this would help, it'll help as much as functions overloading is useful in OOP languages and don't most people use the `set_position()` like this already? > ```rs > let pos: Position3D = ...; > set_position(pos.x, pos.y, pos.z); > ``` So making it takes an `impl Into<[f32; 3]>` instead of 3 `f32` wouldn't be stupid imho
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ArkForgeLabs/BlueEngine#71
No description provided.