Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Last active August 29, 2015 14:07
Show Gist options
  • Save bvssvni/84108e1da75267ec19ba to your computer and use it in GitHub Desktop.
Save bvssvni/84108e1da75267ec19ba to your computer and use it in GitHub Desktop.
pub: + ? + &' to simplify public structs
#[deriving(Show)]
pub struct Stuff<'a> {
pub desc: &'a str,
pub owner: Option<&'a str>,
// pub borrower: Option<&'a str>,
pub using: Option<&'a str>,
pub key_to: Option<&'a str>,
// pub left_hand: Option<&'a str>,
// pub right_hand: Option<&'a str>,
// pub mother: Option<&'a str>,
// pub father: Option<&'a str>,
pub strength: i32,
// pub lift_strength: i32,
// pub push_strength: i32,
pub money: i64,
pub time: i64,
pub speed: i32,
pub locked: bool,
// pub influence: i32,
}
#[deriving(Show)]
pub: struct Stuff {
desc: &'str,
owner? &'str,
// borrower? &'str,
using? &'str,
key_to? &'str,
// left_hand? &'str,
// right_hand? &'str,
// mother? &'str,
// father? &'str,
strength: i32,
// lift_strength: i32,
// push_strength: i32,
money: i64,
time: i64,
speed: i32,
locked: bool,
// influence: i32,
}
@bvssvni
Copy link
Author

bvssvni commented Sep 29, 2014

A colon after pub makes all the members public.

@bvssvni
Copy link
Author

bvssvni commented Sep 29, 2014

A question mark instead of : wraps the type in Option.

@bvssvni
Copy link
Author

bvssvni commented Sep 29, 2014

A &' is a short hand for "lifetime to this struct".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment