Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate rand;
- use std::io;
- use std::cmp::Ordering;
- use rand::Rng;
- #[derive(Debug)]
- struct person {
- name: String::from(""),
- age: i32,
- }
- impl person {
- fn in_day(&self) -> i32
- {
- self.age*100
- }
- }
- fn main() {
- let mut data = person {
- name : "hari",
- age : 12
- };
- println! ("{}",data.in_day());
- println!("{:?}",data);
- }
- fn do_work (s: &String) -> &str
- {
- let dummy = s.as_bytes();
- for (i ,&item) in dummy.iter().enumerate(){
- if item==b' ' {
- return &s[0..i];
- }
- }
- &s[..]
- }
- /*
- let er : (i32,f32,char)=(23,23.0,'');
- printn;
- match a.cmp(&b)
- {
- Ordering::Less => println(),
- Ordering::Greater =>,
- }
- let a : u32 ="42".len().expect("bot a number");;
- let mut a: u32 =String.new().trim().parse();
- data types are as
- i8;i16;164
- u64,u32;
- isize depends on the architecture
- usize depends on the arch
- rust floating types are defined as
- f32 as 32 bit
- f64 as 64 bit
- let f :bool = false;
- char is the most basic and is thus used as it is
- let a = 'a';
- */
- --------------------terminal output ------------------------------------
- error: expected type, found `""`
- --> src/main.rs:9:24
- |
- 9 | name: String::from(""),
- | ^^
- warning: unused import: `std::io`
- --> src/main.rs:3:5
- |
- 3 | use std::io;
- | ^^^^^^^
- |
- = note: #[warn(unused_imports)] on by default
- warning: unused import: `std::cmp::Ordering`
- --> src/main.rs:4:5
- |
- 4 | use std::cmp::Ordering;
- | ^^^^^^^^^^^^^^^^^^
- warning: unused import: `rand::Rng`
- --> src/main.rs:5:5
- |
- 5 | use rand::Rng;
- | ^^^^^^^^^
- error[E0609]: no field `age` on type `&person`
- --> src/main.rs:16:11
- |
- 16 | self.age*100
- | ^^^
- error[E0560]: struct `person` has no field named `name`
- --> src/main.rs:22:9
- |
- 22 | name : "hari",
- | ^^^^ `person` does not have this field
- error[E0560]: struct `person` has no field named `age`
- --> src/main.rs:23:9
- |
- 23 | age : 12
- | ^^^ `person` does not have this field
- error: aborting due to 4 previous errors
- Some errors occurred: E0560, E0609.
- For more information about an error, try `rustc --explain E0560`.
- error: Could not compile `playground`.
Add Comment
Please, Sign In to add comment