ytmapi_rs/
process.rs

1use crate::auth::AuthToken;
2use crate::parse::ProcessedResult;
3use crate::query::Query;
4use crate::Result;
5use std::marker::PhantomData;
6
7/// The raw result of a query to the API.
8// NOTE: The reason this is exposed in the public API, is that it is required to implement
9// AuthToken.
10#[derive(PartialEq, Debug)]
11pub struct RawResult<'a, Q, A>
12where
13    Q: Query<A>,
14    A: AuthToken,
15{
16    // A PhantomData is held to ensure token is processed correctly depending on the AuthToken that
17    // generated it.
18    token: PhantomData<A>,
19    /// The query that generated this RawResult.
20    pub query: &'a Q,
21    /// The raw string output returned from the web request to YouTube.
22    pub json: String,
23}
24
25impl<'a, Q: Query<A>, A: AuthToken> RawResult<'a, Q, A> {
26    pub fn from_raw(json: String, query: &'a Q) -> Self {
27        Self {
28            query,
29            token: PhantomData,
30            json,
31        }
32    }
33    pub fn destructure_json(self) -> String {
34        self.json
35    }
36    pub fn process(self) -> Result<ProcessedResult<'a, Q>> {
37        A::deserialize_json(self)
38    }
39}
40
41pub fn fixed_column_item_pointer(col_idx: usize) -> String {
42    format!("/fixedColumns/{col_idx}/musicResponsiveListItemFixedColumnRenderer")
43}
44
45pub fn flex_column_item_pointer(col_idx: usize) -> String {
46    format!("/flexColumns/{col_idx}/musicResponsiveListItemFlexColumnRenderer")
47}