【发布时间】:2015-03-23 09:59:59
【问题描述】:
我有一个代码转储,我在其中放置了 rust 代码的示例,以防我忘记了什么。我不断收到error: expected item, found 'let' 41+ 行。
可能是我的代码结构不正确吗?我只是将我学到的代码片段粘贴到 main.rs 中。我想枚举有某种特殊的格式或位置。
我尝试更改名称,认为这是名称约定;但这没有帮助。同样的错误。
这是垃圾场(实际上还没有那么大)
#[allow(dead_code)]
fn main()
{
}
/////////////////////////////////////////tutorial functoins i made
fn if_statements()
{
//let (x, y) = (5, 10);
let x = 5;
let y = if x == 5 { 10 } else { 15 };
if y == 15 {println!("y = {}", y);}
}
////////////////////////////////////////// tutoiral functions
#[allow(dead_code)]
fn add(a: i32, b: i32) -> i32
{
a + b
}
#[allow(dead_code)]
fn crash(exception: &str) -> !
{
panic!("{}", exception);
}
//TUPLES//
let y = (1, "hello");
let x: (i32, &str) = (1, "hello");
//STRUCTS//
struct Point {
x: i32,
y: i32,
}
fn structs() {
let origin = Point { x: 0, y: 0 }; // origin: Point
println!("The origin is at ({}, {})", origin.x, origin.y);
}
//ENUMS//
enum Character {
Digit(i32),
Other,
}
let ten = Character::Digit(10);
let four = Character::Digit(4);
【问题讨论】:
标签: rust