一个Rust编写的脚本语言
import std
import api from http
const PI = 3.14
const PI :f32 = 3.14
let title = 'hello'
let title :string = 'hello'
if (a = 10) {
//to do something
return true
}else {
//to do something
return false
}
for (let i = 0; i < 10; i++) {
//to do
}
let arr = [1,2,3,4,5]
let arr :[]int = [1,2,3,4,5]
arr[0] = 10
arr.push()
arr.pop()
arr.contan()
let t = (1,"hello",1010)
let t :(int,string,int) = (1,"hello",1010)
let mut map :HashMap<string, int> = HashMap::new();
map.insert("Alice", 100);
map.insert("Bob", 90);
map.insert("Charlie", 95);
let alice_map = map.get("Alice");
func main(){
//to do
setTextProperties({title:"hello"})
<p></p>
}
func setTextProperties(p:Properties) -> Properties{
//to do
return p
}
//匿名函数
const variable = func() -> Properties {
return
}
//箭头函数
const variable = () -> Properties => {
return
}
func createParagraphs() {
<段落 属性=p>
<文字 属性=p></文本>
</段落>
<p properties=p>
<text properties=p></text>
</p>
}
struct Properties{
title: string,
setTitle: func()-> string {
//to do something
return self.title = "hello"
},
getTitle: ()-> string => {
//to do something
return self.title
}
}
struct Preson :Properties {
}
//语法糖
struct Preson {
super :Properties
}
let person = new Person({
title : "hello"
})
person.super.title = "hello"
enum Result<S, E>{
Ok(S),
Err(E)
}
enum Option<T> {
Some(T),
None,
}
func getName(p: Peolpe) -> string {
}
func getName(p: Student) -> string {
}
func value_in_cents(coin: Coin) -> int {
match coin {
Coin::Penny => 1,
Coin::Nickel => 5,
Coin::Dime => 10,
Coin::Quarter => 25,
}
}
@name(value=2)
func name() -> string {
}
try {
// to do
throw new Exception()
} catch (e: SomeException) {
// 处理程序
} finally {
// 可选的 finally 块
}