Preface
I have notified some improvements for rust.
But I don't know how to make an RFC.
Sorry for my English I'm french
Optionals arguments, Overloading and Multitypes
Overloading exemple:
fn substring(string: String,i: usize) -> String {
return (&string[i..string.len()]).to_string();
}
fn substring(string: String,x: usize,y: usize) -> String {
return (&string[x..y]).to_string();
}
fn substring(string: &str,i: usize) -> String {
return (&string[i..string.len()]).to_string();
}
fn substring(string: &str,x: usize,y: usize) -> String {
return (&string[x..y]).to_string();
}
With the overloading you can make two functions with differents arguments length or different arguments types.
The return type can be overloaded as well.
Optionals arguments example:
//test is optional if it is not passed it value equals to undefined or something like that
fn testprinter(string: String,?test: usize) {
//I don't know the condition for null testing in rust so i going to make a javascript like code
if test==undefined {
printlnt!("{}",string);
} else {
println!("{} with {}",string,test);
}
}
//Test is optional and if it is not passed it's value is 32
fn testprinter(string: String,test = 32: usize) {
println!("{} with {}",string,test);
}
Optional arguments can easily replace the Option<>
in rust function arguments.
Multitype example
//Test can be typed has all the types between {}
fn testprinter(string: String,test: {usize,i32,f64,String,&str}) {
println!("{} with {}",string,test);
//We can test the with the expression I have invented
if (test instanceof usize) {
println!("{}","Type is usize");
}
}
//Test can be typed has all the types in rust
fn testprinter(string: String,test: *) {
println!("{} with {}",string,test);
//We can test the with the expression I have invented
if (test instanceof usize) {
println!("{}","Type is usize");
}
}
Multitypes can be useful for many things and can improve rust ergonomy.
Finally
I don't know how to make an RFC and if my ideas has been already added.
I think all this tweaks can make rust better.
Best regards ccgauche.