Skip to main content

tmdb_rs/
lib.rs

1//! # tmdb-rs
2//!
3//! An async, fully-typed client for [TMDB](https://www.themoviedb.org)
4//! (the movie database), covering API v3 and v4.
5//!
6//! The signature feature is compile-time `append_to_response`: each `with_*`
7//! call fills one slot of the response type, so an appended payload is a plain
8//! field rather than an `Option`:
9//!
10//! ```no_run
11//! # async fn example() -> tmdb_rs::Result<()> {
12//! let tmdb = tmdb_rs::Client::with_read_token(std::env::var("TMDB_READ_TOKEN").unwrap());
13//!
14//! let movie = tmdb.movie(550).with_credits().with_similar().send().await?;
15//! println!("{}", movie.name);
16//! println!("{} cast members", movie.credits.cast.len());
17//! println!("{} similar movies", movie.similar.results.len());
18//! // movie.images is () — it wasn't requested, and the type says so
19//! # Ok(())
20//! # }
21//! ```
22
23#![cfg_attr(docsrs, feature(doc_cfg))]
24
25#[macro_use]
26mod macros;
27
28mod append;
29mod client;
30mod common;
31mod credentials;
32mod endpoints;
33mod image;
34mod param;
35#[cfg(feature = "stream")]
36pub mod stream;
37#[cfg(feature = "v4")]
38mod v4;
39
40pub use append::Append;
41pub use client::Client;
42pub use common::*;
43#[cfg(feature = "v4")]
44pub use credentials::AccessToken;
45pub use credentials::{GuestSessionId, SessionId};
46pub use endpoints::account::*;
47pub use endpoints::authentication::*;
48pub use endpoints::certification::*;
49pub use endpoints::collection::*;
50pub use endpoints::company::*;
51pub use endpoints::configuration::*;
52pub use endpoints::credit::*;
53pub use endpoints::discover::*;
54pub use endpoints::find::*;
55pub use endpoints::genre::*;
56pub use endpoints::keyword::*;
57pub use endpoints::list::*;
58pub use endpoints::movie::*;
59pub use endpoints::network::*;
60pub use endpoints::person::*;
61pub use endpoints::review::*;
62pub use endpoints::search::*;
63pub use endpoints::trending::*;
64pub use endpoints::tv::*;
65pub use endpoints::watch_provider::*;
66pub use image::{Backdrop, Logo, Poster, Profile, Still};
67pub use isocountry::CountryCode;
68pub use isolang::Language;
69pub use param::ToParam;
70pub use time::Date;
71#[cfg(feature = "v4")]
72pub use v4::*;
73
74/// every failure the client can produce
75#[derive(Debug, thiserror::Error)]
76pub enum Error {
77    #[error("transport: {0}")]
78    Transport(#[from] reqwest::Error),
79    /// TMDB's own error body, with its status code
80    #[error("tmdb error {code}: {message}")]
81    Tmdb { code: i32, message: String },
82    /// status code 34, or a bare http 404
83    #[error("not found")]
84    NotFound,
85    /// a 429 that was still in effect after one retry
86    #[error("rate limited; retry after {retry_after:?}")]
87    RateLimited {
88        retry_after: Option<std::time::Duration>,
89    },
90    /// a requested append_to_response payload was absent from the response
91    #[error("requested append `{0}` missing from the response")]
92    MissingAppend(&'static str),
93    #[error("decode: {0}")]
94    Decode(#[from] serde_json::Error),
95}
96
97pub type Result<T> = std::result::Result<T, Error>;