hyperion101010

Untitled

Jan 1st, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. extern crate rand;
  2.  
  3. use std::io;
  4. use std::cmp::Ordering;
  5. use rand::Rng;
  6.  
  7. #[derive(Debug)]
  8. struct person {
  9. name: String::from(""),
  10. age: i32,
  11. }
  12.  
  13. impl person {
  14. fn in_day(&self) -> i32
  15. {
  16. self.age*100
  17. }
  18. }
  19.  
  20. fn main() {
  21. let mut data = person {
  22. name : "hari",
  23. age : 12
  24. };
  25. println! ("{}",data.in_day());
  26. println!("{:?}",data);
  27. }
  28.  
  29. fn do_work (s: &String) -> &str
  30. {
  31. let dummy = s.as_bytes();
  32. for (i ,&item) in dummy.iter().enumerate(){
  33. if item==b' ' {
  34. return &s[0..i];
  35. }
  36. }
  37. &s[..]
  38. }
  39.  
  40.  
  41.  
  42. /*
  43. let er : (i32,f32,char)=(23,23.0,'');
  44. printn;
  45.  
  46. match a.cmp(&b)
  47. {
  48. Ordering::Less => println(),
  49. Ordering::Greater =>,
  50.  
  51. }
  52. let a : u32 ="42".len().expect("bot a number");;
  53.  
  54. let mut a: u32 =String.new().trim().parse();
  55.  
  56. data types are as
  57. i8;i16;164
  58. u64,u32;
  59. isize depends on the architecture
  60. usize depends on the arch
  61. rust floating types are defined as
  62. f32 as 32 bit
  63. f64 as 64 bit
  64. let f :bool = false;
  65. char is the most basic and is thus used as it is
  66. let a = 'a';
  67.  
  68. */
  69.  
  70.  
  71. --------------------terminal output ------------------------------------
  72. error: expected type, found `""`
  73. --> src/main.rs:9:24
  74. |
  75. 9 | name: String::from(""),
  76. | ^^
  77.  
  78. warning: unused import: `std::io`
  79. --> src/main.rs:3:5
  80. |
  81. 3 | use std::io;
  82. | ^^^^^^^
  83. |
  84. = note: #[warn(unused_imports)] on by default
  85.  
  86. warning: unused import: `std::cmp::Ordering`
  87. --> src/main.rs:4:5
  88. |
  89. 4 | use std::cmp::Ordering;
  90. | ^^^^^^^^^^^^^^^^^^
  91.  
  92. warning: unused import: `rand::Rng`
  93. --> src/main.rs:5:5
  94. |
  95. 5 | use rand::Rng;
  96. | ^^^^^^^^^
  97.  
  98. error[E0609]: no field `age` on type `&person`
  99. --> src/main.rs:16:11
  100. |
  101. 16 | self.age*100
  102. | ^^^
  103.  
  104. error[E0560]: struct `person` has no field named `name`
  105. --> src/main.rs:22:9
  106. |
  107. 22 | name : "hari",
  108. | ^^^^ `person` does not have this field
  109.  
  110. error[E0560]: struct `person` has no field named `age`
  111. --> src/main.rs:23:9
  112. |
  113. 23 | age : 12
  114. | ^^^ `person` does not have this field
  115.  
  116. error: aborting due to 4 previous errors
  117.  
  118. Some errors occurred: E0560, E0609.
  119. For more information about an error, try `rustc --explain E0560`.
  120. error: Could not compile `playground`.
Add Comment
Please, Sign In to add comment