pub struct Palette {Show 14 fields
pub id: u64,
pub user_id: u64,
pub date: String,
pub likes: u32,
pub block_one: String,
pub block_two: String,
pub block_three: String,
pub block_four: String,
pub block_five: String,
pub block_six: String,
pub hidden: Option<u8>,
pub featured: Option<u8>,
pub hash: Option<String>,
pub time_ago: String,
}Expand description
Represents a single palette returned by the Block Palettes API.
This struct contains core information about a palette, including its ID, associated blocks, likes, and creation date.
Fields§
§id: u64The unique identifier for the palette.
user_id: u64The ID of the user who created the palette.
date: StringThe creation date of the palette as a string (e.g., “YYYY-MM-DD HH:MM:SS”).
likes: u32The number of likes the palette has received.
block_one: StringThe first block in the palette.
block_two: StringThe second block in the palette.
block_three: StringThe third block in the palette.
block_four: StringThe fourth block in the palette.
block_five: StringThe fifth block in the palette.
block_six: StringThe sixth block in the palette.
A flag indicating if the palette is hidden (0 for not hidden, 1 for hidden).
featured: Option<u8>A flag indicating if the palette is featured (0 for not featured, 1 for featured).
hash: Option<String>An optional hash associated with the palette.
time_ago: StringA human-readable string indicating how long ago the palette was created (e.g., “2 days ago”).
Implementations§
Source§impl Palette
impl Palette
Sourcepub fn name(&self) -> Vec<String>
pub fn name(&self) -> Vec<String>
Returns a vector containing all six block names from the palette.
This is a convenience method to access all blocks without individually
referencing block_one, block_two, etc.
§Returns
A Vec<String> containing the names of the six blocks in the palette.
§Examples
let blocks = palette.name();
assert_eq!(blocks.len(), 6);
assert!(blocks.contains(&"stone".to_string()));Sourcepub fn contains_all_blocks(&self, blocks: &[&str]) -> bool
pub fn contains_all_blocks(&self, blocks: &[&str]) -> bool
Checks if the palette contains all the specified blocks.
This method is useful for client-side filtering of palettes.
§Arguments
blocks- A slice of string references, where each string is a block name to check for.
§Returns
true if the palette contains all blocks specified in the blocks slice,
false otherwise. The comparison is case-sensitive.
§Examples
assert!(palette.contains_all_blocks(&["stone", "dirt"]));
assert!(!palette.contains_all_blocks(&["stone", "diamond_block"]));Sourcepub fn parse_date(&self) -> Result<NaiveDateTime>
pub fn parse_date(&self) -> Result<NaiveDateTime>
Parses the date string of the palette into a NaiveDateTime object.
This provides a more structured way to work with the palette’s creation date.
§Returns
A Result containing a NaiveDateTime if the date string is successfully parsed,
or a BlockPalettesError::InvalidDateFormat if the string does not match
the expected format (“YYYY-MM-DD HH:MM:SS”).
§Examples
let datetime = palette.parse_date().unwrap();
assert_eq!(datetime.date(), NaiveDate::from_ymd_opt(2023, 1, 1).unwrap());
assert_eq!(datetime.hour(), 12);