Apply clippy::use_self
This commit is contained in:
parent
93da9c7f04
commit
c399dffff5
3 changed files with 19 additions and 21 deletions
|
|
@ -31,11 +31,11 @@ pub struct Frame {
|
||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
/// Construct a new Frame from the data in a fcTL chunk
|
/// Construct a new Frame from the data in a fcTL chunk
|
||||||
pub fn from_fctl_data(byte_data: &[u8]) -> PngResult<Frame> {
|
pub fn from_fctl_data(byte_data: &[u8]) -> PngResult<Self> {
|
||||||
if byte_data.len() < 26 {
|
if byte_data.len() < 26 {
|
||||||
return Err(PngError::TruncatedData);
|
return Err(PngError::TruncatedData);
|
||||||
}
|
}
|
||||||
Ok(Frame {
|
Ok(Self {
|
||||||
width: read_be_u32(&byte_data[4..8]),
|
width: read_be_u32(&byte_data[4..8]),
|
||||||
height: read_be_u32(&byte_data[8..12]),
|
height: read_be_u32(&byte_data[8..12]),
|
||||||
x_offset: read_be_u32(&byte_data[12..16]),
|
x_offset: read_be_u32(&byte_data[12..16]),
|
||||||
|
|
|
||||||
34
src/error.rs
34
src/error.rs
|
|
@ -28,36 +28,34 @@ impl fmt::Display for PngError {
|
||||||
#[cold]
|
#[cold]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
PngError::APNGOutOfOrder => f.write_str("APNG chunks are out of order"),
|
Self::APNGOutOfOrder => f.write_str("APNG chunks are out of order"),
|
||||||
PngError::C2PAMetadataPreventsChanges => f.write_str(
|
Self::C2PAMetadataPreventsChanges => f.write_str(
|
||||||
"The image contains C2PA manifest that would be invalidated by any file changes",
|
"The image contains C2PA manifest that would be invalidated by any file changes",
|
||||||
),
|
),
|
||||||
PngError::ChunkMissing(s) => write!(f, "Chunk {s} missing or empty"),
|
Self::ChunkMissing(s) => write!(f, "Chunk {s} missing or empty"),
|
||||||
PngError::CRCMismatch(ref c) => write!(
|
Self::CRCMismatch(ref c) => write!(
|
||||||
f,
|
f,
|
||||||
"CRC mismatch in {} chunk; May be recoverable by using --fix",
|
"CRC mismatch in {} chunk; May be recoverable by using --fix",
|
||||||
String::from_utf8_lossy(c)
|
String::from_utf8_lossy(c)
|
||||||
),
|
),
|
||||||
PngError::DeflatedDataTooLong(_) => f.write_str("Deflated data too long"),
|
Self::DeflatedDataTooLong(_) => f.write_str("Deflated data too long"),
|
||||||
PngError::IncorrectDataLength(l1, l2) => write!(
|
Self::IncorrectDataLength(l1, l2) => write!(
|
||||||
f,
|
f,
|
||||||
"Data length {l1} does not match the expected length {l2}"
|
"Data length {l1} does not match the expected length {l2}"
|
||||||
),
|
),
|
||||||
PngError::InflatedDataTooLong(max) => write!(
|
Self::InflatedDataTooLong(max) => write!(
|
||||||
f,
|
f,
|
||||||
"Inflated data would exceed the maximum size ({max} bytes)"
|
"Inflated data would exceed the maximum size ({max} bytes)"
|
||||||
),
|
),
|
||||||
PngError::InvalidData => f.write_str("Invalid data found; unable to read PNG file"),
|
Self::InvalidData => f.write_str("Invalid data found; unable to read PNG file"),
|
||||||
PngError::InvalidDepthForType(d, ref c) => {
|
Self::InvalidDepthForType(d, ref c) => {
|
||||||
write!(f, "Invalid bit depth {d} for color type {c}")
|
write!(f, "Invalid bit depth {d} for color type {c}")
|
||||||
}
|
}
|
||||||
PngError::NotPNG => f.write_str("Invalid header detected; Not a PNG file"),
|
Self::NotPNG => f.write_str("Invalid header detected; Not a PNG file"),
|
||||||
PngError::ReadFailed(ref s, ref e) => write!(f, "Failed to read from {s}: {e}"),
|
Self::ReadFailed(ref s, ref e) => write!(f, "Failed to read from {s}: {e}"),
|
||||||
PngError::TruncatedData => {
|
Self::TruncatedData => f.write_str("Missing data in the file; the file is truncated"),
|
||||||
f.write_str("Missing data in the file; the file is truncated")
|
Self::WriteFailed(ref s, ref e) => write!(f, "Failed to write to {s}: {e}"),
|
||||||
}
|
Self::Other(ref s) => f.write_str(s),
|
||||||
PngError::WriteFailed(ref s, ref e) => write!(f, "Failed to write to {s}: {e}"),
|
|
||||||
PngError::Other(ref s) => f.write_str(s),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +63,7 @@ impl fmt::Display for PngError {
|
||||||
impl PngError {
|
impl PngError {
|
||||||
#[cold]
|
#[cold]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(description: &str) -> PngError {
|
pub fn new(description: &str) -> Self {
|
||||||
PngError::Other(description.into())
|
Self::Other(description.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ impl OutFile {
|
||||||
/// This is a convenience method for `OutFile::Path { path: Some(path), preserve_attrs: false }`.
|
/// This is a convenience method for `OutFile::Path { path: Some(path), preserve_attrs: false }`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_path(path: PathBuf) -> Self {
|
pub fn from_path(path: PathBuf) -> Self {
|
||||||
OutFile::Path {
|
Self::Path {
|
||||||
path: Some(path),
|
path: Some(path),
|
||||||
preserve_attrs: false,
|
preserve_attrs: false,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue