Skip to main content

RarError

Enum RarError 

Source
pub enum RarError {
Show 13 variants InvalidSignature, InvalidHeader, InvalidHeaderType(u8), DecompressionNotSupported(u8), EncryptedNotSupported, PasswordRequired, DecryptionFailed(String), BufferTooSmall { needed: usize, have: usize, }, InvalidOffset { offset: u64, length: u64, }, Io(Error), NoFilesFound, Rar5NotFullySupported, EncryptedHeaders,
}
Expand description

Error type for RAR operations.

This enum covers all possible errors that can occur when parsing, decompressing, or decrypting RAR archives. It implements std::error::Error for integration with the Rust error handling ecosystem.

§Example

use rar_stream::RarError;

fn handle_error(err: RarError) {
    match err {
        RarError::InvalidSignature => {
            // File doesn't start with RAR magic bytes
        }
        RarError::PasswordRequired => {
            // Need to provide password in ParseOptions
        }
        RarError::Io(io_err) => {
            // Underlying I/O error (file not found, permission denied, etc.)
        }
        _ => {}
    }
}

Variants§

§

InvalidSignature

The file does not have a valid RAR signature.

RAR files must start with either:

  • RAR4: Rar!\x1a\x07\x00 (7 bytes)
  • RAR5: Rar!\x1a\x07\x01\x00 (8 bytes)
§

InvalidHeader

A header in the archive is malformed or corrupt.

This usually indicates file corruption or an incomplete download.

§

InvalidHeaderType(u8)

An unknown or unsupported header type was encountered.

The u8 value is the header type byte. Standard types are:

  • 0x72 (114): Marker header
  • 0x73 (115): Archive header
  • 0x74 (116): File header
  • 0x7B (123): End of archive
§

DecompressionNotSupported(u8)

The compression method is not supported.

The u8 value is the method byte:

  • 0x30: Store (no compression) - always supported
  • 0x31-0x35: LZSS variants - supported
  • 0x36+: Future methods - may not be supported
§

EncryptedNotSupported

The archive is encrypted but the crypto feature is not enabled.

Enable the crypto feature in Cargo.toml:

rar-stream = { version = "4", features = ["async", "crypto"] }
§

PasswordRequired

The archive is encrypted but no password was provided.

Provide a password in ParseOptions:

let opts = ParseOptions {
    password: Some("secret".to_string()),
    ..Default::default()
};
§

DecryptionFailed(String)

Decryption failed (wrong password or corrupt data).

The String contains additional context about the failure. Common causes:

  • Incorrect password
  • Corrupt encrypted data
  • Truncated archive
§

BufferTooSmall

The provided buffer is too small.

This occurs when reading into a fixed-size buffer that cannot hold the required data.

Fields

§needed: usize

Number of bytes needed.

§have: usize

Number of bytes available.

§

InvalidOffset

An invalid file offset was requested.

This occurs when seeking beyond the end of a file or archive.

Fields

§offset: u64

The requested offset.

§length: u64

The actual file length.

§

Io(Error)

An I/O error occurred.

Wraps std::io::Error for file system operations.

§

NoFilesFound

No files were found in the archive.

The archive may be empty, or all files may have been filtered out.

§

Rar5NotFullySupported

RAR5 format detected but a specific feature is not supported.

This is a legacy error that should rarely occur with current versions.

§

EncryptedHeaders

The archive has encrypted headers and requires a password to list files.

RAR5 archives created with rar -hp encrypt both file data and headers. Without the correct password, even file names cannot be read.

Trait Implementations§

Source§

impl Debug for RarError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RarError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for RarError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecompressError> for RarError

Source§

fn from(e: DecompressError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for RarError

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.