Guest User

Untitled

a guest
Jun 25th, 2018
90
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 = if let Some(document) = update.message.document {
  11. Some(&document.file_id)
  12. } else if let Some(photo) = update.message.photo {
  13. photo.get(0).map(|x| &x.file_id)
  14. } else {
  15. None
  16. };
  17. }
  18.  
  19.  
  20. #[derive(Debug, Clone, Deserialize)]
  21. pub struct Chat {
  22. pub id: i64,
  23. #[serde(rename = "type")]
  24. pub chat_type: String,
  25. pub first_name: Option<String>,
  26. pub last_name: Option<String>,
  27. pub username: Option<String>,
  28. }
  29.  
  30. #[derive(Debug, Clone, Deserialize)]
  31. pub struct Document {
  32. pub file_id: String,
  33. pub file_name: Option<String>,
  34. pub mime_type: Option<String>,
  35. pub thumb: Option<PhotoSize>,
  36. pub file_size: Option<i64>,
  37. }
  38.  
  39. #[derive(Debug, Clone, Deserialize)]
  40. pub struct PhotoSize {
  41. pub file_id: String,
  42. pub file_size: Option<i64>,
  43. pub width: i64,
  44. pub height: i64,
  45. }
  46.  
  47. #[derive(Debug, Clone, Deserialize)]
  48. pub struct User {
  49. pub id: i64,
  50. pub is_bot: bool,
  51. pub first_name: String,
  52. pub last_name: Option<String>,
  53. pub username: Option<String>,
  54. pub language_code: Option<String>,
  55. }
  56.  
  57. #[derive(Debug, Clone, Deserialize)]
  58. pub struct Message {
  59. pub message_id: i64,
  60. pub from: Option<User>,
  61. pub chat: Chat,
  62. pub date: i64,
  63. pub text: Option<String>,
  64. pub photo: Option<Vec<PhotoSize>>,
  65. pub document: Option<Document>,
  66. }
  67.  
  68. #[derive(Debug, Clone, Deserialize)]
  69. pub struct File {
  70. pub file_id: String,
  71. pub file_size: Option<i64>,
  72. pub file_path: Option<String>,
  73. }
  74.  
  75. #[derive(Debug, Clone, Deserialize)]
  76. pub struct GetFileResponse {
  77. pub ok: bool,
  78. pub result: File,
  79. }
  80.  
  81. #[derive(Debug, Clone, Deserialize)]
  82. pub struct Update {
  83. pub update_id: i64,
  84. pub message: Message,
  85. }
  86.  
  87. #[derive(Debug, Clone, Deserialize)]
  88. pub struct ApiResult<T> {
  89. pub ok: bool,
  90. pub result: T,
  91. }
Add Comment
Please, Sign In to add comment