pub struct ChunkType(/* private fields */);Expand description
A 4-byte chunk type code.
Implementations§
Source§impl ChunkType
impl ChunkType
Sourcepub const fn private(ty: [u8; 4]) -> Result<Self, ChunkTypeError>
pub const fn private(ty: [u8; 4]) -> Result<Self, ChunkTypeError>
Creates private ChunkType.
§Errors
This function will return an error in the following cases:
- Value contains non-ASCII alphabet characters
- The second character is not lowercase
- The third character is not uppercase
§Examples
assert!(ChunkType::private(*b"myTy").is_ok());
assert_eq!(
ChunkType::private(*b"zeR\0").unwrap_err(),
ChunkTypeError::NonAsciiAlphabetic
);
assert_eq!(
ChunkType::private(*b"pRIv").unwrap_err(),
ChunkTypeError::NonPrivateChunkType
);
assert_eq!(
ChunkType::private(*b"rese").unwrap_err(),
ChunkTypeError::Reserved
);Sourcepub const unsafe fn from_unchecked(ty: [u8; 4]) -> Self
pub const unsafe fn from_unchecked(ty: [u8; 4]) -> Self
Creates custom ChunkType without any check.
§Panic
Printing ChunkType that contains non-utf8 characters will be panicked.
let custom_chunk_type = unsafe { ChunkType::from_unchecked([0xe3, 0x81, 0x82, 0xe3]) };
format!("{}", custom_chunk_type);§Safety
Safe when value consists only of ascii alphabetic characters (‘a’…‘z’ and ‘A’…‘Z’).
let custom_chunk_type = unsafe { ChunkType::from_unchecked(*b"myTy") };
format!("{}", custom_chunk_type);Sourcepub const fn is_critical(&self) -> bool
pub const fn is_critical(&self) -> bool
Returns true if the chunk is critical.
Sourcepub const fn is_private(&self) -> bool
pub const fn is_private(&self) -> bool
Returns true if the chunk is private.
Sourcepub const fn is_set_reserved(&self) -> bool
pub const fn is_set_reserved(&self) -> bool
Checks whether the reserved bit of the chunk name is set. If it is set, the chunk name is invalid.
Sourcepub const fn is_safe_to_copy(&self) -> bool
pub const fn is_safe_to_copy(&self) -> bool
Returns true if the chunk is safe to copy if unknown.
Trait Implementations§
Source§impl Ord for ChunkType
impl Ord for ChunkType
Source§impl PartialOrd for ChunkType
impl PartialOrd for ChunkType
impl Copy for ChunkType
impl Eq for ChunkType
impl StructuralPartialEq for ChunkType
Auto Trait Implementations§
impl Freeze for ChunkType
impl RefUnwindSafe for ChunkType
impl Send for ChunkType
impl Sync for ChunkType
impl Unpin for ChunkType
impl UnwindSafe for ChunkType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more