1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
//! Models in struct form, parsed out from JSON in response bodies. use serde_json; use std::collections::HashMap; use ::Result; /// Information about a character. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Character { /// Information about the character. pub attributes: CharacterAttributes, /// The id of the character. pub id: String, /// The type of item this is. This should always be [`Type::Character`]. /// /// [`Type::Character`]: enum.Type.html#variant.Character #[serde(rename = "type")] pub kind: Type, /// Links related to the anime. pub links: HashMap<String, String>, } /// Information about a [`Character`]. /// /// [`Character`]: struct.Character.html #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CharacterAttributes { /// When the entry was created. pub created_at: String, /// A description of the character. pub description: Option<String>, /// URLs to cover images. pub image: Option<CoverImage>, /// The ID of the MAL entry. pub mal_id: i64, /// The name of the character. pub name: String, /// URL slug of the character. pub slug: String, /// When the entry was last updated. pub updated_at: String, } /// Information about a producer #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Producer { /// Information about the producer. pub attributes: ProducerAttributes, /// The id of the producer pub id: String, /// The type of item this is. This should always be [`Type::Producer`]. /// /// [`Type::Character`]: enum.Type.html#variant.Producer #[serde(rename = "type")] pub kind: Type, /// Links to the related anime-productions. pub links: HashMap<String, String>, } /// Information about a [`Producer`]. /// /// [`Producer`]: struct.Producer.html #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ProducerAttributes { /// When the entry was created. pub created_at: String, /// The name of the producer. pub name: String, /// URL slug of the producer. pub slug: String, /// When the entry was last updated. pub updated_at: String, } /// Information about an anime. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Anime { /// Information about the anime. pub attributes: AnimeAttributes, /// The id of the anime. pub id: String, /// The type of item this is. Should always be [`Type::Anime`]. /// /// [`Type::Anime`]: enum.Type.html#variant.Anime #[serde(rename="type")] pub kind: Type, /// Links related to the anime. pub links: HashMap<String, String>, /// List of the anime's relationships. pub relationships: AnimeRelationships, } impl Anime { /// The current airing status of the anime. #[inline] pub fn airing_status(&self) -> AiringStatus { self.attributes.airing_status() } /// Generates a URL to the Kitsu page for the anime. #[inline] pub fn url(&self) -> String { self.attributes.url() } /// Generates a formatted URL to the youtube video. #[inline] pub fn youtube_url(&self) -> Option<String> { self.attributes.youtube_url() } } /// Information about an [`Anime`]. /// /// [`Anime`]: struct.Anime.html #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all= "camelCase")] pub struct AnimeAttributes { /// Shortened nicknames for the [anime][`Anime`]. /// /// # Examples /// /// `Attack on Titan` /// /// [`Anime`]: struct.Anime.html pub abbreviated_titles: Option<Vec<String>>, /// Age rating for the anime. /// /// # Examples /// //// [`AgeRating::R`] pub age_rating: Option<AgeRating>, /// Description of the age rating. /// /// # Examples /// /// `Violence, Profanity` pub age_rating_guide: Option<String>, /// The average of all user ratings for the anime. /// /// # Examples /// /// `4.26984658306698` pub average_rating: Option<String>, /// Canonical title for the anime. /// /// # Examples /// /// `Attack on Titan` pub canonical_title: String, /// The URL template for the cover. /// /// # Examples /// /// `https://static.hummingbird.me/anime/7442/cover/$1.png` pub cover_image: Option<CoverImage>, /// The cover's offset from the top. /// /// This has the possibility of being negative. /// /// # Examples /// /// `263` pub cover_image_top_offset: i16, /// Date the anime finished airing. /// /// # Examples /// /// `2013-09-28` pub end_date: Option<String>, /// How many episodes the anime has. /// /// # Examples /// /// `25` pub episode_count: Option<u32>, /// How many minutes long each episode is. /// /// # Examples /// /// `24` pub episode_length: Option<u32>, /// How many favourites the anime has. /// /// # Examples /// /// `209` pub favourites_count: Option<u32>, /// Show format of the anime. /// /// # Examples /// /// [`AnimeType::TV`], [`AnimeType::Special`]. /// /// [`AnimeType::Special`]: enum.AnimeType.html#variant.Special /// [`AnimeType::TV`]: enum.AnimeType.html#variant.TV #[serde(rename="showType")] pub kind: AnimeType, /// Whether the anime is Not Safe For Work. pub nsfw: bool, /// The rank based on the popularity of the anime. /// /// # Examples /// /// `2` pub popularity_rank: Option<u32>, /// The URL template for the poster. /// /// # Examples /// /// `https://static.hummingbird.me/anime/7442/poster/$1.png` pub poster_image: Image, /// How many times each rating has been given to the anime. pub rating_frequencies: RatingFrequencies, /// The rank of the anime based on its overall rating. /// /// # Examples /// /// `5` pub rating_rank: Option<u32>, /// Unique slug used for page URLs. /// /// # Examples /// /// `attack-on-titan` pub slug: String, /// Date the anime started airing/was released. /// /// # Examples /// /// `2013-04-07` pub start_date: Option<String>, /// The status of the anime /// /// # Examples /// /// [`Status::Current`], [`Status::Finished`]. /// /// [`Status::Current`]: enum.Status.html#variant.Current /// [`Status::Finished`]: enum.Status.html#variant.Finished pub status: Option<Status>, /// The sub type of the anime. pub sub_type: Option<String>, /// Synopsis of the anime. /// /// # Examples /// /// `Several hundred years ago, humans were exterminated by titans...` pub synopsis: String, /// The titles of the anime. pub titles: AnimeTitles, /// The number of users who have marked the anime. /// /// # Examples /// /// `3232532` pub user_count: Option<u32>, /// YouTube video id for PV. /// /// # Examples /// /// `n4Nj6Y_SNYI` pub youtube_video_id: Option<String>, } impl AnimeAttributes { /// The current airing status of the anime. /// /// This is calculated by checking the [`end_date`]. If it exists, then /// [`AiringStatus::Finished`] is returned. Otherwise, /// [`AiringStatus::Airing`] is returned. /// /// This distinction is made because [`status`] may not always be accurate. /// /// [`end_date`]: #structfield.end_date /// [`AiringStatus::Airing`]: enum.AiringStatus.html#variant.Airing /// [`AiringStatus::Finished`]: enum.AiringStatus.html#variant.Finished pub fn airing_status(&self) -> AiringStatus { if self.end_date.is_some() { AiringStatus::Finished } else { AiringStatus::Airing } } /// Generates a URL to the Kitsu page for the anime. #[inline] pub fn url(&self) -> String { format!("https://kitsu.io/anime/{}", self.slug) } /// Generates a formatted URL to the youtube video. #[inline] pub fn youtube_url(&self) -> Option<String> { self.youtube_video_id.as_ref().map(youtube_url) } } /// Links related to the media item. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Links { /// Link to a related media item. pub related: String, /// Direct link to the media item. #[serde(rename="self")] pub own: String, } /// A relationship for a media item. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Relationship { /// Links for one set of the media item's related links. pub links: Links, } /// Relationships for an [`Anime`]. /// /// [`Anime`]: struct.Anime.html #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AnimeRelationships { /// Productions for the anime #[serde(rename="animeProductions")] pub anime_productions: Relationship, /// Castings for the anime. pub castings: Relationship, /// The anime's episodes. pub episodes: Relationship, /// The anime's genres. pub genres: Relationship, /// The anime's installments. pub installments: Relationship, /// The anime's mappings. pub mappings: Relationship, /// The anime's reviews. pub reviews: Relationship, /// The anime's streaming links. #[serde(rename="streamingLinks")] pub streaming_links: Relationship, } /// Information about the cover image for a media item. #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct CoverImage { /// Link to the large copy. pub large: Option<String>, /// Link to the original copy. pub original: Option<String>, /// Link to the small copy. pub small: Option<String>, } impl CoverImage { /// Retrieves the URL to the largest cover image in descending order where /// available, if any. /// /// This places priority on the [`original`] field. /// /// [`original`]: #structfield.original pub fn largest<'a>(&'a self) -> Option<&'a String> { self.original.as_ref().or(self.large.as_ref()).or(self.small.as_ref()) } } /// A list of links to the media's relevant images. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Image { /// Link to a large size of the image. pub large: Option<String>, /// Link to a medium size of the image. pub medium: Option<String>, /// Link to an original size of the image. pub original: Option<String>, /// Link to a small size of the image. pub small: Option<String>, /// Link to a tiny size of the image. pub tiny: Option<String>, } impl Image { /// Retrieves the URL to the largest image in descending order where /// available, if any. /// /// This places priority on the [`original`] field. /// /// [`original`]: #structfield.original pub fn largest<'a>(&'a self) -> Option<&'a String> { self.original.as_ref() .or(self.large.as_ref()) .or(self.medium.as_ref()) .or(self.small.as_ref()) .or(self.tiny.as_ref()) } } /// Information about a manga. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Manga { /// Information about the manga. pub attributes: MangaAttributes, /// The id of the manga. pub id: String, /// The type of item this is. Should always be [`Type::Manga`]. /// /// [`Type::Manga`]: enum.Type.html#variant.Manga #[serde(rename="type")] pub kind: Type, /// Links related to the manga. pub links: HashMap<String, String>, } impl Manga { /// The current airing status of the manga. #[inline] pub fn airing_status(&self) -> AiringStatus { self.attributes.airing_status() } /// Generates a URL to the Kitsu page for the manga. #[inline] pub fn url(&self) -> String { self.attributes.url() } /// Generates a formatted URL to the youtube video. #[inline] pub fn youtube_url(&self) -> Option<String> { self.attributes.youtube_url() } } /// Information about a [`Manga`]. /// /// [`Manga`]: struct.Manga.html #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all="camelCase")] pub struct MangaAttributes { /// Shortened nicknames for the manga. pub abbreviated_titles: Option<Vec<String>>, /// The average of all user ratings for the manga. /// /// # Examples /// /// `4.34926964198231` pub average_rating: Option<String>, /// Canonical title for the manga. /// /// # Examples /// /// `Horimiya` pub canonical_title: String, /// The number of chapters released. pub chapter_count: Option<u64>, /// The URL template for the cover. /// /// # Examples /// /// `https://static.hummingbird.me/manga/22352/cover/$1.png` pub cover_image: Option<CoverImage>, /// The cover's offset from the top. /// /// This has the possibility of being negative. /// /// # Examples /// /// `60` pub cover_image_top_offset: i16, /// Date the manga finished. /// /// # Examples /// /// `2013-09-28` pub end_date: Option<String>, /// Show format of the manga. /// /// # Examples /// /// [`MangaType::Novel`] /// /// [`MangaType::Novel`]: enum.MangaType.html#variant.Novel #[serde(rename="mangaType")] pub kind: MangaType, /// The rank based on the popularityof the manga. /// /// # Examples /// /// `10` pub popularity_rank: Option<u32>, /// The URL template for the poster. /// /// # Examples /// /// `https://static.hummingbird.me/manga/22352/poster/$1.png` pub poster_image: Image, /// How many times each rating has been given to the manga. pub rating_frequencies: RatingFrequencies, /// The rank of the manga based on its overall rating. /// /// # Examples /// /// `13` pub rating_rank: Option<u32>, /// Name of media of serialization. pub serialization: Option<String>, /// Unique slug used for page URLs. /// /// # Examples /// /// `horimiya` pub slug: String, /// Date the manga was serialized. /// /// # Examples /// /// `2013-04-07` pub start_date: Option<String>, /// The status of the manga /// /// # Examples /// /// [`Status::Current`], [`Status::Finished`]. /// /// [`Status::Current`]: enum.Status.html#variant.Current /// [`Status::Finished`]: enum.Status.html#variant.Finished pub status: Option<Status>, /// Synopsis of the manga. /// /// # Examples /// /// `Hori may seem like a normal teenage girl, but she's a completely...` pub synopsis: String, /// The titles of the manga. pub titles: MangaTitles, /// The number of volumes released for the manga. pub volume_count: Option<u64>, /// The id of the related YouTube video. pub youtube_video_id: Option<String>, } impl MangaAttributes { /// The current airing status of the manga. /// /// Refer to [`AnimeAttributes::airing_status`] for more information. /// /// [`AnimeAttributes::airing_status`]: struct.AnimeAttributes.html#method.airing_status pub fn airing_status(&self) -> AiringStatus { if self.end_date.is_some() { AiringStatus::Finished } else { AiringStatus::Airing } } /// Generates a URL to the Kitsu page for the manga. #[inline] pub fn url(&self) -> String { format!("https://kitsu.io/manga/{}", self.slug) } /// Generates a formatted URL to the youtube video. #[inline] pub fn youtube_url(&self) -> Option<String> { self.youtube_video_id.as_ref().map(youtube_url) } } /// How many times each rating has been given to the media item. #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub struct RatingFrequencies { /// Number of 0 stars given. #[serde(default, rename="0.0")] pub rating_0_0: i64, /// Number of 0.5 stars given. #[serde(default, rename="0.5")] pub rating_0_5: i64, /// Number of 1.0 stars given. #[serde(default, rename="1.0")] pub rating_1_0: i64, /// Nubmer of 1.5 stars given. #[serde(default, rename="1.5")] pub rating_1_5: i64, /// Number of 2.0 stars given. #[serde(default, rename="2.0")] pub rating_2_0: i64, /// Number of 2.5 stars given. #[serde(default, rename="2.5")] pub rating_2_5: i64, /// Number of 3.0 stars given. #[serde(default, rename="3.0")] pub rating_3_0: i64, /// Number of 3.5 stars given. #[serde(default, rename="3.5")] pub rating_3_5: i64, /// Number of 4.0 stars given. #[serde(default, rename="4.0")] pub rating_4_0: i64, /// Number of 4.5 stars given. #[serde(default, rename="4.5")] pub rating_4_5: i64, /// Number of 5.0 stars given. #[serde(default, rename="5.0")] pub rating_5_0: i64, } /// The titles of the anime. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AnimeTitles { /// The English title of the anime. /// /// # Examples /// /// `Attack on Titan` pub en: Option<String>, /// The romaji title of the anime. /// /// # Examples /// /// `Shingeki no Kyojin` pub en_jp: Option<String>, /// The Japanese title of the anime. /// /// # Examples /// /// `進撃の巨人` pub ja_jp: Option<String>, } /// The titles of the manga. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct MangaTitles { /// The English title of the manga. /// /// # Examples /// /// `Attack on Titan` pub en: Option<String>, /// The romaji title of the manga. /// /// # Examples /// /// `Shingeki no Kyojin` pub en_jp: Option<String>, } /// Data from a response. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Response<T> { /// The full data from a response. pub data: T, /// Links relevant to the search. #[serde(default)] pub links: HashMap<String, String>, } /// Information about a user. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct User { /// Information about the user. pub attributes: UserAttributes, /// The id of the user. pub id: String, /// The type of item this is. Should always be [`Type::User`]. /// /// [`Type::User`]: enum.Type.html#variant.User #[serde(rename="type")] pub kind: Type, /// Links related to the user. pub links: HashMap<String, String>, /// List of the user's relationships. pub relationships: UserRelationships, } /// Information about a [`User`]. /// /// [`User`]: struct.User.html #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all="camelCase")] pub struct UserAttributes { /// The raw markdown for the user's long-form about text. /// /// # Examples /// /// `I'm curious about https://kitsu.io/anime/nichijou!` pub about: String, /// The processed and sanitized HTML for the user's long form about text. /// /// # Examples /// /// `I'm curious about <a href="https://kitsu.io/anime/nichijou">Nichijou</a>!` pub about_formatted: Option<String>, /// Links to the user's avatar. pub avatar: Option<Image>, /// A short (140 character) biographical blurb about the user. /// /// # Examples /// /// `私、気になります!` pub bio: Option<String>, /// The user's birthday. /// /// # Examples /// /// `1985-07-26` pub birthday: Option<String>, /// Number of comments user has submitted. /// /// # Examples /// /// `15` pub comments_count: u64, /// Links to the user's cover image. pub cover_image: Option<Image>, /// When the user signed up. /// /// # Examples /// /// `1985-07-26T22:13:20.223Z` pub created_at: String, /// The user's Facebook id if they have signed in with Facebook. /// /// # Examples /// /// `1234567890` pub facebook_id: Option<String>, /// The number of media items the user has favorited. pub favorites_count: u64, /// Whether the user's feed is completed. pub feed_completed: bool, /// Number of people following this user. /// /// # Examples /// /// `12` pub followers_count: u64, /// Number of people this user is following. /// /// # Examples /// /// `300` pub following_count: u64, /// The user's gender, if provided. /// /// # Examples /// /// `female` pub gender: Option<String>, /// Number of minutes of anime watched. /// /// # Examples /// /// `550` pub life_spent_on_anime: u64, /// Number of posts user has liked. /// /// # Examples /// /// `12` pub likes_given_count: u64, /// Number of likes the user's post has received. /// /// # Examples /// /// `45` pub likes_received_count: u64, /// A user-provided location. /// /// # Examples /// /// `The Internet` pub location: Option<String>, /// The user's current username. /// /// # Examples /// /// `chitanda` pub name: String, /// An array of previous names the user has gone by, in /// reverse-chronological order. /// /// # Examples /// /// ```rs /// vec![ /// "oldn ame".to_owned(), /// "older name".to_owned() /// ] /// ``` pub past_names: Vec<String>, /// Number of posts user has submitted. /// /// # Examples /// /// `3` pub posts_count: u64, /// Whether the user has finished completing their profile. pub profile_completed: bool, /// When the user's pro subscripten expires. pub pro_expires_at: Option<String>, /// Number of media user has rated. /// /// # Examples /// /// `1` pub ratings_count: u64, /// The number of reviews the user has posted. pub reviews_count: u64, /// The user's title. pub title: Option<String>, /// When the user last updated their profile. /// /// **Note**: This _can_ be the same as the [`created_at`] field, which /// indicates that the profile has not been "updated" since creation. /// /// # Examples /// /// `1985-07-26T22:13:20.223Z` /// /// [`created_at`]: #structfield.created_at pub updated_at: String, /// Whether the user has a waifu or husbando. /// /// # Examples /// /// `None` pub waifu_or_husbando: Option<WaifuOrHusbando>, /// The user's website. /// /// # Examples /// /// `https://en.wikipedia.org/wiki/Nichijou` pub website: Option<String>, } impl User { /// Generates a URL to the Kitsu page for the user. #[inline] pub fn url(&self) -> String { self.attributes.url() } } impl UserAttributes { /// Generates a URL to the Kitsu page for the user. #[inline] pub fn url(&self) -> String { format!("https://kitsu.io/users/{}", self.name) } } /// Relationships for a [`User`]. /// /// [`User`]: struct.User.html #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all="camelCase")] pub struct UserRelationships { /// Links to users the user blocks. pub blocks: Relationship, /// Links to the user's favorite media entries. pub favorites: Relationship, /// Links to users following the user. pub followers: Relationship, /// Links to users the user follows. pub following: Relationship, /// Links to the user's library entries. pub library_entries: Relationship, /// Links to profiles linked to the user. pub linked_profiles: Option<Relationship>, /// Links to the user's media. pub media_follows: Option<Relationship>, /// Links to the user's pinned post on their profile. pub pinned_post: Relationship, /// Links to the user's reviews. pub reviews: Relationship, /// Links to the user's roles. pub user_roles: Relationship, /// Links to the user's waifu or husbando. pub waifu: Relationship, } /// The age rating of the [`Anime`]. /// /// [`Anime`]: struct.Anime.html #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub enum AgeRating { /// Indicator that the anime is rated G. G, /// Indicator that the anime is rated PG. PG, /// Indicator that the anime is rated PG-13. #[serde(rename="PG-13")] PG13, /// Indicator that the anime is rated R. R, /// Indicator that the anime is rated R-17. R17, /// Indicator that the anime is rated R-17+. #[serde(rename="R17+")] R17Plus, /// Indicator that the anime is rated R18. R18, /// Indicator that the anime is rated R-18+. #[serde(rename="R18+")] R18Plus, /// Indicator that the anime is rated TV-Y7. #[serde(rename="TV-Y7")] TvY7, } impl AgeRating { /// The name of the age rating. /// /// # Examples /// /// ```rust /// use kitsu::model::AgeRating; /// /// assert_eq!(AgeRating::PG.name().unwrap(), "PG"); /// ``` pub fn name(&self) -> Result<String> { let mut name = serde_json::to_string(self)?; // Serde wraps the encoded string in quotation marks, so remove those. let _ = name.remove(0); let _ = name.pop(); Ok(name) } } /// The airing status of an [`Anime`]. /// /// [`Anime`]: struct.Anime.html pub enum AiringStatus { /// Indicator that the anime is currently airing. Airing, /// Indicator that the anime has finished airing. Finished, } impl AiringStatus { /// The name of the airing status. pub fn name(&self) -> &str { match *self { AiringStatus::Airing => "airing", AiringStatus::Finished => "finished", } } } /// The status of [`Anime`] and [`Manga`] /// /// [`Anime`]: struct.Anime.html /// [`Manga`]: struct.Manga.html #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub enum Status { /// Indicator that the media is current. #[serde(rename = "current")] Current, /// Indicator that the media is finished. #[serde(rename = "finished")] Finished, /// Indicator that the media is to-be-announced. #[serde(rename = "tba")] TBA, /// Indicator that the media is unreleased. #[serde(rename = "unreleased")] Unreleased, /// Indicator that the media is upcoming. #[serde(rename = "upcoming")] Upcoming } /// The type of [`Anime`]. /// /// [`Anime`]: struct.Anime.html #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub enum AnimeType { /// Indicator that the anime is a movie. #[serde(rename = "movie")] Movie, /// Indicator that the anime is music. #[serde(rename = "music")] Music, /// Indicator that the anime is an Original Net Animation. ONA, /// Indicator that the anime is an Original Video Animation. OVA, /// Indicator that the anime is a special. #[serde(rename = "special")] Special, /// Indicator that the anime is a TV show. TV, } impl AnimeType { /// The name of the [anime][`Anime`] type. /// /// # Examples /// /// ```rust /// use kitsu::model::AnimeType; /// /// assert_eq!(AnimeType::Movie.name().unwrap(), "movie"); /// assert_eq!(AnimeType::TV.name().unwrap(), "TV"); /// ``` /// /// [`Anime`]: struct.Anime.html pub fn name(&self) -> Result<String> { let mut name = serde_json::to_string(self)?; let _ = name.remove(0); let _ = name.pop(); Ok(name) } } /// The type of a [`Manga`]. /// /// [`Manga`]: struct.Manga.html #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] #[serde(rename_all="lowercase")] pub enum MangaType { /// Indicator that the manga is a doujin. Doujin, /// Indicator that the manga is a regular manga. Manga, /// Indicator that the manga is a manhua. Manhua, /// Indicator that the manga is a manhwa. Manhwa, /// Indicator that the manga is a novel. Novel, /// Indicator that the manga is an Original-English-Language manga. OEL, /// Indicator that the manga is a oneshot. Oneshot, } impl MangaType { /// The name of the Manga Type. /// /// # Examples /// /// ```rust /// use kitsu::model::MangaType; /// /// assert_eq!(MangaType::Novel.name().unwrap(), "novel"); /// ``` pub fn name(&self) -> Result<String> { let mut name = serde_json::to_string(self)?; let _ = name.remove(0); let _ = name.pop(); Ok(name) } } /// The type of result from a search or retrieval. #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] #[serde(rename_all="lowercase")] pub enum Type { /// Indicator that the result is an [`Anime`]. /// /// [`Anime`]: struct.Anime.html Anime, /// Indicator that the result is a [`Character`]. /// /// [`Character`]: struct.Character.html #[serde(rename = "characters")] Character, /// Indicator that the result is a drama. Drama, /// Indicator that the result is a [`Manga`]. /// /// [`Manga`]: struct.Manga.html Manga, /// Indicator that the result is a [`Producer`] /// /// [`Producer`]: struct.Producer.html #[serde(rename = "producers")] Producer, /// Indicator that the result is a [`User`]. /// /// [`User`]: struct.User.html Users, } impl Type { /// The name of the Type. /// /// # Examples /// /// ```rust /// use kitsu::model::Type; /// /// assert_eq!(Type::Anime.name().unwrap(), "anime"); /// ``` pub fn name(&self) -> Result<String> { let mut name = serde_json::to_string(self)?; let _ = name.remove(0); let _ = name.pop(); Ok(name) } } /// Indicator of whether a [`User`] has a waifu or husbando. /// /// [`User`]: struct.User.html #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub enum WaifuOrHusbando { /// Indicator that the user has a husbando. Husbando, /// Indicator that the user has a waifu. Waifu, } impl WaifuOrHusbando { /// The name of the Waifu or Husbando. /// /// # Examples /// /// ```rust /// use kitsu::model::WaifuOrHusbando; /// /// assert_eq!(WaifuOrHusbando::Husbando.name().unwrap(), "Husbando"); /// ``` pub fn name(&self) -> Result<String> { let mut name = serde_json::to_string(self)?; let _ = name.remove(0); let _ = name.pop(); Ok(name) } } #[inline] fn youtube_url(id: &String) -> String { format!("https://www.youtube.com/watch?v={}", id) }