This is a followup to Inlined code for operating on scala > operating on vec
(but the topic has shifted as the implementation strategy changed thanks to @alice 's strategy)
pub trait MessyT {
fn do_scalar(lhs: i32, rhs: i32) > i32 { todo!(); }
fn do_vec(lhs: Vec<i32>, rhs: Vec<i32>) > Vec<i32> {
let n = lhs.len();
assert!(n == rhs.len());
let mut ans = Vec::with_capacity(n);
for i in 0..n {
ans.push(
Self::do_scalar(lhs[i], rhs[i]), // Fniii(lhs[i], rhs[i])
// how do I call this function on these two args?
)
}
ans
}
}
pub struct ScalarPlus {}
pub struct ScalarMul {}
impl MessyT for ScalarPlus {
#[inline(always)]
fn do_scalar(a: i32, b: i32) > i32 {
a + b
}
}
impl MessyT for ScalarMul {
#[inline(always)]
fn do_scalar(a: i32, b: i32) > i32 {
a * b
}
}
The goal of this code here is:

we have some functions defined on scalars (say plus, mul)

we want to auto generate ways to run them on Vecs

we want to 100% inline the scalar functions
Question is: is the above guaranteed to inline? Why / why not? If not, how do we fix it?
Thanks!