You would define a trait. Traits are the paradigm through which rust creates type-dependent behavior.
pub trait Foo {
fn foo() -> f32;
}
Then you can implement it for the types you want.
impl Foo for i32 {
fn foo() -> f32 {
1.0
}
}
impl Foo for i64 {
fn foo() -> f32 {
2.0
}
}
impl Foo for f32 {
fn foo() -> f32 {
3.0
}
}
And now you can call it using your specific types.
i32::foo() // 1.0
You can also use the trait to create type-specific behavior in other functions.
pub fn foo_plus_one<T: Foo>() -> f32 {
T::foo() + 1.0
}
foo_plus_one::<i64>() // 3.0