mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
70da903cec
# Objective Currently in order to retrieve the inner values from direction types is that you need to use the `Deref` trait or `From`/`Into`. `Deref` that is currently implemented is an anti-pattern that I believe should be less relied upon. This pull-request add getters for retrieving the inner values for direction types. Advantages of getters: - Let rust-analyzer to list out available methods for users to understand better to on how to get the inner value. (This happens to me. I really don't know how to get the value until I look through the source code.) - They are simple. - Generally won't be ambiguous in most context. Traits such as `From`/`Into` will require fully qualified syntax from time to time. - Unsurprising result. Disadvantages of getters: - More verbose Advantages of deref polymorphism: - You reduce boilerplate for getting the value and call inner methods by: ```rust let dir = Dir3::new(Vec3::UP).unwrap(); // getting value let value = *dir; // instead of using getters let value = dir.vec3(); // calling methods for the inner vector dir.xy(); // instead of using getters dir.vec3().xy(); ``` Disadvantages of deref polymorphism: - When under more level of indirection, it will requires more dereferencing which will get ugly in some part: ```rust // getting value let value = **dir; // instead of using getters let value = dir.vec3(); // calling methods for the inner vector dir.xy(); // instead of using getters dir.vec3().xy(); ``` [More detail here](https://rust-unofficial.github.io/patterns/anti_patterns/deref.html). Edit: Update information for From/Into trait. Edit: Advantages and disadvantages. ## Solution Add `vec2` method for Dir2. Add `vec3` method for Dir3. Add `vec3a` method for Dir3A. |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_color | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_dev_tools | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_dynamic_plugin | ||
bevy_ecs | ||
bevy_ecs_compile_fail_tests | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_macros_compile_fail_tests | ||
bevy_math | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_reflect_compile_fail_tests | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |