Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #[macro_use]
  2. extern crate log;
  3.  
  4. use std::collections::HashMap;
  5. use std::rc::Rc;
  6.  
  7. mod stuff;
  8.  
  9. pub enum Flag {
  10. Good,
  11. Bad,
  12. Ugly
  13. }
  14.  
  15. const QUALITY: Flag = Flag::Good;
  16.  
  17. struct Table<const N: usize>([[i32; N]; N])
  18.  
  19. pub trait Write {
  20. fn write(&mut self, buf: &[u8]) -> Result<usize>;
  21. }
  22.  
  23. struct Object<T> {
  24. flag: Flag,
  25. fields: HashMap<T, u64>
  26. }
  27.  
  28. union MyUnion {
  29. f1: u32,
  30. f2: f32,
  31. }
  32.  
  33. type RcObject<T> = Rc<Object<T>>;
  34.  
  35. impl<T> Write for Object<T> {
  36. fn write(&mut self, buf: &[u8]) -> Result<usize> {
  37. let s = stuff::write_map(&self.fields, buf)?;
  38. info!("{} byte(s) written", s);
  39. Ok(s)
  40. }
  41. }
  42.  
  43. impl<T> Default for Object<T> {
  44. fn default() -> Self {
  45. Object { flag: Flag::Good, fields: HashMap::new() }
  46. }
  47. }
  48.  
  49. /* Block comment */
  50. fn main() {
  51. // A simple integer calculator:
  52. // `+` or `-` means add or subtract by 1
  53. // `*` or `/` means multiply or divide by 2
  54. stuff::AppVersion::print();
  55.  
  56. let input = Option::None;
  57. let program = input.unwrap_or_else(|| "+ + * - /");
  58. let mut accumulator = 0;
  59.  
  60. for token in program.chars() {
  61. match token {
  62. '+' => accumulator += 1,
  63. '-' => accumulator -= 1,
  64. '*' => accumulator *= 2,
  65. '/' => accumulator /= 2,
  66. _ => { /* ignore everything else */ }
  67. }
  68. }
  69.  
  70. info!("The program \"{}\" calculates the value {}",
  71. program, accumulator);
  72. }
  73.  
  74. /// Some documentation `with code`
  75. /// # Heading
  76. /// [Rust](https://www.rust-lang.org/)
  77. #[cfg(target_os="linux")]
  78. unsafe fn a_function<T: 'lifetime>(count: &mut i64) -> ! {
  79. count += 1;
  80. 'label: loop {
  81. println!("Hello\x20W\u{f3}rld!\u{abcdef}");
  82. }
  83. }
  84.  
  85. fn test() {
  86. unsafe {
  87. a_function(1);
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement