Guest User

Untitled

a guest
Jun 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #[macro_use]
  2. extern crate serde_derive;
  3. extern crate serde;
  4. extern crate serde_json;
  5.  
  6. fn main() {
  7. }
  8.  
  9. fn get_file_id(update: &Update) {
  10. let file_id = match (update.message.document, update.message.photo) {
  11. (Some(ref document), _) => Some(&document.file_id),
  12. (_, Some(ref photo)) => photo.get(0).map(|x| &x.file_id),
  13. _ => None
  14. };
  15. }
  16.  
  17.  
  18. #[derive(Debug, Clone, Deserialize)]
  19. pub struct Chat {
  20. pub id: i64,
  21. #[serde(rename = "type")]
  22. pub chat_type: String,
  23. pub first_name: Option<String>,
  24. pub last_name: Option<String>,
  25. pub username: Option<String>,
  26. }
  27.  
  28. #[derive(Debug, Clone, Deserialize)]
  29. pub struct Document {
  30. pub file_id: String,
  31. pub file_name: Option<String>,
  32. pub mime_type: Option<String>,
  33. pub thumb: Option<PhotoSize>,
  34. pub file_size: Option<i64>,
  35. }
  36.  
  37. #[derive(Debug, Clone, Deserialize)]
  38. pub struct PhotoSize {
  39. pub file_id: String,
  40. pub file_size: Option<i64>,
  41. pub width: i64,
  42. pub height: i64,
  43. }
  44.  
  45. #[derive(Debug, Clone, Deserialize)]
  46. pub struct User {
  47. pub id: i64,
  48. pub is_bot: bool,
  49. pub first_name: String,
  50. pub last_name: Option<String>,
  51. pub username: Option<String>,
  52. pub language_code: Option<String>,
  53. }
  54.  
  55. #[derive(Debug, Clone, Deserialize)]
  56. pub struct Message {
  57. pub message_id: i64,
  58. pub from: Option<User>,
  59. pub chat: Chat,
  60. pub date: i64,
  61. pub text: Option<String>,
  62. pub photo: Option<Vec<PhotoSize>>,
  63. pub document: Option<Document>,
  64. }
  65.  
  66. #[derive(Debug, Clone, Deserialize)]
  67. pub struct File {
  68. pub file_id: String,
  69. pub file_size: Option<i64>,
  70. pub file_path: Option<String>,
  71. }
  72.  
  73. #[derive(Debug, Clone, Deserialize)]
  74. pub struct GetFileResponse {
  75. pub ok: bool,
  76. pub result: File,
  77. }
  78.  
  79. #[derive(Debug, Clone, Deserialize)]
  80. pub struct Update {
  81. pub update_id: i64,
  82. pub message: Message,
  83. }
  84.  
  85. #[derive(Debug, Clone, Deserialize)]
  86. pub struct ApiResult<T> {
  87. pub ok: bool,
  88. pub result: T,
  89. }
Add Comment
Please, Sign In to add comment