wp_mini/field/
mod.rs

1//! Defines the field enums used for type-safe field selection in API requests.
2//!
3//! This module contains enums that represent the data fields available for different
4//! Wattpad API objects (e.g., `StoryField`, `UserField`). Using these enums ensures
5//! that only valid fields can be requested from the API.
6//!
7//! It also provides traits to manage default fields and authentication requirements.
8
9// Private modules for each field type.
10mod language_field;
11mod macros;
12mod part_content_field;
13mod part_field;
14mod part_reference_field;
15mod part_stub_field;
16mod story_field;
17mod text_url_field;
18mod user_field;
19mod user_stub_field;
20
21// Publicly export the field enums for use throughout the crate.
22pub use language_field::LanguageField;
23pub use part_content_field::PartContentField;
24pub use part_field::PartField;
25pub use part_reference_field::PartReferenceField;
26pub use part_stub_field::PartStubField;
27pub use story_field::StoryField;
28pub use text_url_field::TextUrlField;
29pub use user_field::UserField;
30pub use user_stub_field::UserStubField;
31
32/// A trait for field enums that can provide a default set of fields.
33///
34/// This is used to request a standard, useful set of data when the user
35/// doesn't specify which fields they want.
36pub trait DefaultableFields {
37    /// Returns a vector of the enum's variants that should be used as the default.
38    fn default_fields() -> Vec<Self>
39    where
40        Self: Sized;
41}
42
43/// A trait to identify which fields in an enum require user authentication.
44pub trait AuthRequiredFields: Sized + PartialEq {
45    /// Returns a vector of enum variants that require authentication.
46    ///
47    /// By default, this returns an empty vector, assuming most fields are public.
48    /// This method should be overridden for enums that have protected fields.
49    fn auth_required_fields() -> Vec<Self> {
50        vec![]
51    }
52
53    /// Checks if a specific field instance requires authentication.
54    ///
55    /// Returns `true` if `self` is present in the list of authentication-required fields.
56    fn auth_required(&self) -> bool {
57        Self::auth_required_fields().contains(self)
58    }
59}