Re:Should small Rust structs be passed by-copy or by-borrow?
by crave_ on Monday August 26, 2019 @10:13AM
(#20800004)
This has irked me as well.
Is there an acceptable way to make this less verbose?
A crate with a derive macro for example?
Re:Should small Rust structs be passed by-copy or by-borrow?
by pornel on Monday August 26, 2019 @11:13AM
(#20800513)
There is, https://lib.rs/derive_more
Re:Should small Rust structs be passed by-copy or by-borrow?
by hcs on Monday August 26, 2019 @11:55AM
(#20800858)
As danieldk mentioned elsewhere, you could get partway there with std::borrow::Borrow
impl<T> Add<T> for &Vector3 where T: Borrow<Vector3>
Re:Should small Rust structs be passed by-copy or by-borrow?
by shmerl on Monday August 26, 2019 @03:04PM
(#20802686)
Does that essentially overload + for it?
Re:Should small Rust structs be passed by-copy or by-borrow?
by saghm on Monday August 26, 2019 @04:11PM
(#20803248)
Yes; Rust uses traits to implement behavior for operators on custom types (see the full list here: https://doc.rust-lang.org/std/ops/#traits)
You can cut down on a lot of that by implementing basic operations (Add, Mul, etc.) for both value and reference types.
(The first three can delegate to the last one, unless there are value-specific optimizations you want to apply.)