Skip to main content

yt_dlp/model/utils/
mod.rs

1//! Utility functions for the model module.
2
3use std::clone::Clone;
4use std::cmp::{Eq, PartialEq};
5use std::fmt::{Debug, Display};
6use std::hash::Hash;
7
8pub mod serde;
9
10pub use serde::{serialize_json, serialize_json_opt};
11
12/// Trait that combines the basic traits that any structure should implement.
13///
14/// This trait combines:
15/// - `Debug` for debug display
16/// - `Clone` for duplication
17/// - `PartialEq` for comparison
18/// - `Display` for formatted display
19pub trait CommonTraits: Debug + Clone + PartialEq + Display {}
20
21/// Trait that combines basic and advanced traits for a complete structure.
22///
23/// This trait combines:
24/// - All traits from `CommonTraits`
25/// - `Eq` for total equality
26/// - `Hash` for hashing
27pub trait AllTraits: CommonTraits + Eq + Hash {}
28
29/// Automatic implementation of the `CommonTraits` trait for any type that implements
30/// the required traits.
31impl<T: Debug + Clone + PartialEq + Display> CommonTraits for T {}
32
33/// Automatic implementation of the `AllTraits` trait for any type that implements
34/// the required traits.
35impl<T: Debug + Clone + PartialEq + Display + Eq + Hash> AllTraits for T {}