Guest User

Untitled

a guest
Jun 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. fn main() {
  2. create_model_test();
  3. }
  4.  
  5. fn create_model_test() {
  6. let call_model: Model<*const u8, u8, u8, u8, u8> = Model::new(
  7. "addPost".to_string(),
  8. 0x00423B40,
  9. Some(b"test_z5" as *const u8),
  10. None,
  11. None,
  12. None,
  13. None,
  14. );
  15.  
  16. println!("func model: \n\n{:#?}", call_model);
  17. }
  18.  
  19. #[derive(Debug)]
  20. struct Model<T, U, V, W, X> {
  21. name: String,
  22. addr: usize,
  23. arg1: Option<T>,
  24. arg2: Option<U>,
  25. arg3: Option<V>,
  26. arg4: Option<W>,
  27. degree: u8,
  28. ret: Option<X>,
  29. }
  30.  
  31. impl<T, U, V, W, X> Model<T, U, V, W, X> {
  32. fn new(
  33. name: String,
  34. addr: usize,
  35. arg1: Option<T>,
  36. arg2: Option<U>,
  37. arg3: Option<V>,
  38. arg4: Option<W>,
  39. ret: Option<X>,
  40. ) -> Model<T, U, V, W, X> {
  41. let mut func = Model {
  42. name: name,
  43. addr: addr,
  44. arg1: arg1,
  45. arg2: arg2,
  46. arg3: arg3,
  47. arg4: arg4,
  48. degree: 0,
  49. ret: ret,
  50. };
  51.  
  52. func.set_degree();
  53. func
  54. }
  55.  
  56. fn set_degree(&mut self) {
  57. if let Some(_) = &self.arg1 {
  58. self.degree += 1;
  59. }
  60.  
  61. if let Some(_) = &self.arg2 {
  62. self.degree += 1;
  63. }
  64.  
  65. if let Some(_) = &self.arg3 {
  66. self.degree += 1;
  67. }
  68.  
  69. if let Some(_) = &self.arg4 {
  70. self.degree += 1;
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment