### Copy Result Contents Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=std%3A%3Avec Examples of copying or cloning the contents of a Result. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Result::is_ok Implementation Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example of checking if a Result is Ok. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### Validating Result with Predicate Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Example of using is_ok_and to check if a Result is Ok and matches a predicate. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Result::cloned Implementation Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of using cloned on Result<&T, E> and Result<&mut T, E>. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Cloning Result Contents Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Examples of using the cloned method to convert Result<&T, E> to Result. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut 12); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Copying Result Contents Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Examples of using the copied method to convert Result<&T, E> to Result. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut 12); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### Result::copied Implementation Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of using copied on Result<&T, E> and Result<&mut T, E>. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### Transposing Result and Option Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Example of transposing a Result of an Option into an Option of a Result. ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### Flattening Nested Results Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Examples of flattening nested Result types. ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` -------------------------------- ### Checking Result Status Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Examples of checking if a Result is Ok or Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Result::is_err Implementation Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example of checking if a Result is Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Retrieve Nth Part of Archive Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Get the path for the nth part of a multipart collection or None if not applicable. ```rust let part42 = Archive::new("path/my.archive.part01.rar").nth_part(42).unwrap(); assert_eq!(part42, PathBuf::from("path/my.archive.part42.rar")); ``` ```rust let part42 = Archive::new("path/my.archive.rar").nth_part(42); assert_eq!(part42, None); ``` -------------------------------- ### Retrieve Multipart Archive Glob or Filename Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Get a glob string for all parts of a multipart archive or the filename if it is a single-part archive. ```rust let glob = Archive::new("path/my.archive.part01.rar").all_parts(); assert_eq!(glob, PathBuf::from("path/my.archive.part??.rar")); ``` ```rust let glob = Archive::new("path/my.archive.rar").all_parts(); assert_eq!(glob, PathBuf::from("path/my.archive.rar")); ``` -------------------------------- ### Retrieve Multipart Archive Glob Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Get a glob string for all parts of a multipart archive or None if it is a single-part archive. ```rust let glob = Archive::new("path/my.archive.part01.rar").all_parts_option(); assert_eq!(glob, Some(PathBuf::from("path/my.archive.part??.rar"))); ``` ```rust let glob = Archive::new("path/my.archive.rar").all_parts_option(); assert_eq!(glob, None); ``` -------------------------------- ### Archive Initialization Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods to create a new Archive instance for plain or encrypted RAR files. ```APIDOC ## Archive::new(file: &'a T) ### Description Creates an Archive object to operate on a plain non-encrypted RAR archive. ## Archive::with_password(file: &'a F, password: &'a Pw) ### Description Creates an Archive object to operate on a password encrypted RAR archive. ## Archive::new_owned(file: T) ### Description Creates an Archive object to operate on a plain non-encrypted RAR archive, taking ownership of the input path. ``` -------------------------------- ### Retrieve the first part of an archive as an Option Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Returns the first part of a multipart archive or None if the filename does not indicate a multipart structure. ```rust let part1 = Archive::new("path/my.archive.part42.rar").first_part_option().unwrap(); assert_eq!(part1, PathBuf::from("path/my.archive.part01.rar")); ``` ```rust let part1 = Archive::new("path/my.archive.rar").first_part_option(); assert_eq!(part1, None); ``` -------------------------------- ### Migrate from unrar to unrar-ng Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search= Options for updating projects from the original unrar crate to unrar-ng. ```toml [dependencies] unrar-ng = "0.7" ``` ```rust use unrar_ng::Archive; ``` ```toml [dependencies] unrar = { package = "unrar-ng", version = "0.7" } # Only if you also depend on the FFI crate directly: unrar_sys = { package = "unrar-ng-sys", version = "0.7" } ``` -------------------------------- ### Import Archive in Rust Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Import the Archive struct to begin using the library. ```rust use unrar_ng::Archive; ``` -------------------------------- ### Read archive file content in Rust Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Demonstrates how to open an archive, read a header, and extract the content of the first file into memory. ```rust fn first_file_content>(path: P) -> UnrarResult> { let archive = Archive::new(&path).open_for_processing()?; // cursor: before header let archive = archive.read_header()?.expect("empty archive"); // cursor: before file dbg!(&archive.entry().filename); let (data, _rest) = archive.read()?; // cursor: before header Ok(data) } ``` -------------------------------- ### Configure Minimal-change Dependency Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Use package aliasing in Cargo.toml to maintain compatibility with existing code using the original unrar crate names. ```toml [dependencies] unrar = { package = "unrar-ng", version = "0.7" } # Only if you also depend on the FFI crate directly: unrar_sys = { package = "unrar-ng-sys", version = "0.7" } ``` -------------------------------- ### entry Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Returns the file header for the next file to be processed. ```APIDOC ## pub fn entry(&self) -> &FileHeader ### Description Returns the file header for the file that follows which is to be processed next. ``` -------------------------------- ### Configure unrar-ng dependencies Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html Select the appropriate dependency configuration based on your requirements for UTF-8 enforcement or locale-based encoding. ```toml [dependencies] unrar-ng = "0.7" ``` ```toml [dependencies] unrar-ng = { version = "0.7", default-features = false, features = ["linux-batch-extract-setlocale"] } ``` ```toml [dependencies] unrar-ng = { version = "0.7", default-features = false } ``` -------------------------------- ### Retrieve the first part of an archive Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Returns the first part of a multipart archive or the original filename if no multipart structure is detected. ```rust let part1 = Archive::new("path/archive.part33.rar").first_part(); assert_eq!(part1, PathBuf::from("path/archive.part01.rar")); ``` ```rust let part1 = Archive::new("path/archive.rar").first_part(); assert_eq!(part1, PathBuf::from("path/archive.rar")); ``` ```rust let part1 = Archive::new("https://gibberish").first_part(); assert_eq!(part1, PathBuf::from("https://gibberish")); ``` -------------------------------- ### as_first_part Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Modifies the archive instance to point to the first part of the multipart collection. ```APIDOC ## pub fn as_first_part(self) -> Self ### Description Changes the filename to point to the first part of the multipart collection. Does nothing if the underlying archive does not appear to be a multipart archive. ``` -------------------------------- ### List Archive Entries Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Iterate through archive entries using open_for_listing. ```rust use unrar_ng::Archive; fn main() { for entry in Archive::new("archive.rar").open_for_listing().unwrap() { println!("{}", entry.unwrap()); } } ``` -------------------------------- ### expect Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the contained Ok value, consuming the self value, or panics if Err. ```APIDOC ## pub fn expect(self, msg: &str) -> T ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`, with a panic message including the passed message, and the content of the `Err`. ``` -------------------------------- ### open_for_listing Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Opens the underlying archive for listing its entries, where payloads are skipped automatically. ```APIDOC ## pub fn open_for_listing(self) -> UnrarResult> ### Description Opens the underlying archive for listing its entries, i.e. the payloads are skipped automatically. ``` -------------------------------- ### And Chaining Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the provided Result if the current one is Ok, otherwise returns the Err. ```rust let x: Result = Ok(2); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("late error")); let x: Result = Err("early error"); let y: Result<&str, &str> = Ok("foo"); assert_eq!(x.and(y), Err("early error")); let x: Result = Err("not a 2"); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("not a 2")); let x: Result = Ok(2); let y: Result<&str, &str> = Ok("different result type"); assert_eq!(x.and(y), Ok("different result type")); ``` -------------------------------- ### Extract all files with a progress callback Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Extracts all files while providing a closure to handle progress events. Returning false from the callback can cancel the extraction or reject specific events like large dictionary warnings. ```rust use unrar_ng::{Archive, ExtractEvent, ExtractStatus}; let archive = Archive::new("archive.rar") .open_for_processing() .expect("Failed to open archive"); let status = archive.extract_all_with_callback("./output", |event| { match event { ExtractEvent::Start { filename, size } => { print!("extracting {}... ({} bytes) ", filename.display(), size); true // continue extraction } ExtractEvent::Ok { filename, size } => { println!("ok ({} bytes) {}", size, filename.display()); true } ExtractEvent::Err { filename, error_code } => { println!("error (code: {})", error_code); true // continue with other files } ExtractEvent::LargeDictWarning { dict_size_kb, max_dict_size_kb } => { eprintln!("archive needs {dict_size_kb} KB dict, build supports {max_dict_size_kb} KB"); false // refuse oversized dict; extraction fails with Code::LargeDict } _ => true, } }).expect("Failed to extract archive"); match status { ExtractStatus::Completed => println!("done"), ExtractStatus::Cancelled => println!("user cancelled"), _ => {} } ``` -------------------------------- ### Archive::new Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=std%3A%3Avec Creates an Archive object to operate on a plain non-encrypted RAR archive. ```APIDOC ## pub fn new(file: &'a T) -> Self ### Description Creates an Archive object to operate on a plain non-encrypted RAR archive. ``` -------------------------------- ### first_part_option Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Returns the first part of the multipart collection or None if the archive does not appear to be a multipart archive based on the filename. ```APIDOC ## pub fn first_part_option(&self) -> Option ### Description Returns the first part of the multipart collection or `None` if the underlying archive does not appear to be a multipart archive (based solely on filename). This method does not make any FS operations and operates purely on strings. ``` -------------------------------- ### skip Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Skips over the next file in the archive. ```APIDOC ## pub fn skip(self) -> UnrarResult> ### Description Skips over the next file, not doing anything with it. ``` -------------------------------- ### Archive Methods Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=std%3A%3Avec Methods for interacting with archive paths and opening archives for various operations. ```APIDOC ## pub fn first_part_option(&self) -> Option ### Description Returns the first part of the multipart collection or `None` if the underlying archive does not appear to be a multipart archive based on the filename. This method performs no filesystem operations. ## pub fn first_part(&self) -> PathBuf ### Description Returns the first part of the multipart collection or the original filename if the archive does not appear to be multipart. This method performs no filesystem operations. ## pub fn as_first_part(self) -> Self ### Description Changes the internal filename to point to the first part of the multipart collection. Does nothing if the archive is not detected as multipart. ## pub fn open_for_processing(self) -> UnrarResult> ### Description Opens the archive for processing, allowing the payloads of each entry to be read. Panics if the filename contains nul values. ## pub fn open_for_listing(self) -> UnrarResult> ### Description Opens the archive for listing its entries, automatically skipping payloads. Panics if the filename contains nul values. ## pub fn open_for_listing_split(self) -> UnrarResult> ### Description Opens the archive for listing entries without omitting or pooling split entries. Panics if the filename contains nul values. ## pub fn break_open(self, error: Option<&mut Option>) -> UnrarResult> ### Description Opens the archive with the provided OpenMode, even if the archive is broken. Allows tracking of recoverable errors via an optional mutable reference. ``` -------------------------------- ### open_for_listing_split Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Opens the underlying archive for listing its entries without omitting or pooling split entries. ```APIDOC ## pub fn open_for_listing_split(self) -> UnrarResult> ### Description Opens the underlying archive for listing its entries without omitting or pooling split entries. For a multipart archive, this means a file spanning the border of 2 parts will appear twice. ``` -------------------------------- ### Archive::all_parts Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=std%3A%3Avec Returns a glob string covering all parts of the multipart collection. ```APIDOC ## pub fn all_parts(&self) -> PathBuf ### Description Returns a glob string covering all parts of the multipart collection or the filename if it is not a multipart archive. ``` -------------------------------- ### as_first_part Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Changes the filename to point to the first part of the multipart collection. ```APIDOC ## pub fn as_first_part(self) -> Self ### Description Changes the filename to point to the first part of the multipart collection. Does nothing if the underlying archive does not appear to be a multipart archive (based solely on filename). This method does not make any FS operations and operates purely on strings. ``` -------------------------------- ### Providing defaults with unwrap_or Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the contained Ok value or a provided default value. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### And Then Chaining Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Calls a function to produce a new Result if the current one is Ok. ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } ``` -------------------------------- ### first_part Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Returns the first part of the multipart collection or the original filename if it does not appear to be a multipart archive. ```APIDOC ## pub fn first_part(&self) -> PathBuf ### Description Returns the first part of the multipart collection or `self.filename` if the underlying archive does not appear to be a multipart archive (based solely on filename). This method does not make any FS operations and operates purely on strings. ``` -------------------------------- ### extract Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Extracts the current file into the current working directory. ```APIDOC ## pub fn extract(self) -> UnrarResult> ### Description Extracts the file into the current working directory and returns the OpenArchive for further processing. ``` -------------------------------- ### pub fn unwrap_or_default(self) -> T Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=u32+-%3E+bool Returns the contained Ok value or a default value if the result is an Err. ```APIDOC ## pub fn unwrap_or_default(self) -> T ### Description Consumes the `self` argument then, if `Ok`, returns the contained value, otherwise if `Err`, returns the default value for that type. ``` -------------------------------- ### FileHeader Methods Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.FileHeader.html?search=u32+-%3E+bool Methods available on the FileHeader struct to inspect archive entry properties. ```APIDOC ## pub fn is_split(&self) -> bool ### Description Checks if this entry is split across multiple volumes. This method works in 'List' open mode. ## pub fn is_split_after(&self) -> bool ### Description Checks if this entry is split across multiple volumes, starting at this entry. This method works in 'List' open mode. ## pub fn is_split_before(&self) -> bool ### Description Checks if this entry is split across multiple volumes, starting before this entry. This will always return false in 'List' open mode. ## pub fn is_directory(&self) -> bool ### Description Checks if this entry is a directory. ## pub fn is_encrypted(&self) -> bool ### Description Checks if this entry is encrypted. ## pub fn is_file(&self) -> bool ### Description Checks if this entry is a file. ``` -------------------------------- ### Archive Utility Methods Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods for inspecting archive properties and multipart file paths without performing file system operations. ```APIDOC ## Archive::filename(&self) -> &Path ### Description Returns the archive's path. ## Archive::is_archive(&self) -> bool ### Description Returns true if the filename matches a RAR archive pattern. ## Archive::is_multipart(&self) -> bool ### Description Returns true if the filename matches a part of a multipart collection. ## Archive::all_parts(&self) -> PathBuf ### Description Returns a glob string covering all parts of the multipart collection or the filename if it is a single part archive. ## Archive::nth_part(&self, n: i32) -> Option ### Description Returns the nth part of this multi-part collection or None if the archive is not multipart. ``` -------------------------------- ### Convert Result to Option Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Use ok to convert Result to Option, discarding the error, or err to discard the success value. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` ```rust let x: Result = Ok(2); assert_eq!(x.err(), None); let x: Result = Err("Nothing here"); assert_eq!(x.err(), Some("Nothing here")); ``` -------------------------------- ### Extract Archive Contents Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Use the extract_all method for efficient batch extraction of an archive. ```rust use unrar_ng::Archive; let archive = Archive::new("large_archive.rar") .open_for_processing() .expect("Failed to open archive"); archive.extract_all("./output") .expect("Failed to extract"); ``` -------------------------------- ### pub fn unwrap(self) -> T Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=u32+-%3E+bool Returns the contained Ok value, consuming the self value. Panics if the value is an Err. ```APIDOC ## pub fn unwrap(self) -> T ### Description Returns the contained `Ok` value, consuming the `self` value. Because this function may panic, its use is generally discouraged. ### Panics Panics if the value is an `Err`, with a panic message provided by the `Err`’s value. ``` -------------------------------- ### Reference Conversion Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Use as_ref or as_mut to obtain references to the inner values of a Result. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### Archive::with_password Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=std%3A%3Avec Creates an Archive object to operate on a password encrypted RAR archive. ```APIDOC ## pub fn with_password(file: &'a F, password: &'a Pw) -> Self ### Description Creates an Archive object to operate on a password encrypted RAR archive. ``` -------------------------------- ### Archive::new_owned Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=std%3A%3Avec Creates an Archive object to operate on a plain non-encrypted RAR archive, taking ownership of the input path. ```APIDOC ## pub fn new_owned(file: T) -> Self ### Description Creates an Archive object to operate on a plain non-encrypted RAR archive. This function takes ownership of the input, allowing for the creation of an Archive<'static>. ``` -------------------------------- ### pub fn and_then(self, op: F) -> Result Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=u32+-%3E+bool Calls op if the result is Ok, otherwise returns the Err value of self. ```APIDOC ## pub fn and_then(self, op: F) -> Result ### Description Calls `op` if the result is `Ok`, otherwise returns the `Err` value of `self`. This function can be used for control flow based on `Result` values. ``` -------------------------------- ### Extract all files from an archive Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Extracts all files from an archive to a specified directory. This method is optimized for performance by using batch extraction. ```rust use unrar_ng::Archive; let archive = Archive::new("archive.rar") .open_for_processing() .expect("Failed to open archive"); archive.extract_all("./output") .expect("Failed to extract archive"); ``` -------------------------------- ### extract_with_base Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Extracts the file into the specified directory. ```APIDOC ## pub fn extract_with_base>(self, base: P) -> UnrarResult> ### Description Extracts the file into the specified directory and returns the OpenArchive for further processing. ``` -------------------------------- ### next() Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Advances the iterator and returns the next value, which is a Result containing a FileHeader or an UnrarError. ```APIDOC ## fn next(&mut self) -> Option ### Description Advances the iterator and returns the next value. The returned item is a Result. ### Parameters - **&mut self** - The iterator instance. ``` -------------------------------- ### read Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Reads the underlying file into a byte vector. ```APIDOC ## pub fn read(self) -> UnrarResult<(Vec, OpenArchive)> ### Description Reads the underlying file into a Vec and returns the data along with the owned Archive. ``` -------------------------------- ### extract_all_with_callback Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Extracts all files from the archive with a progress callback for notifications. ```APIDOC ## pub fn extract_all_with_callback(self, dest: P, callback: F) -> UnrarResult ### Description Extracts all files from the archive while providing progress notifications through a callback function. ### Parameters - **dest** (P: AsRef) - Required - The destination directory path. - **callback** (F: FnMut(ExtractEvent) -> bool) - Required - A closure that receives ExtractEvent notifications. ``` -------------------------------- ### extract_all Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Extracts all files from the archive to the specified directory in a single operation. ```APIDOC ## pub fn extract_all>(self, dest: P) -> UnrarResult<()> ### Description Extracts all files from the archive to the specified directory in a single operation. This method is faster than individual extraction as it uses a batch extraction function. ### Parameters - **dest** (P: AsRef) - Required - The destination directory path. If the directory doesn’t exist, it will be created. ``` -------------------------------- ### Configure unrar-ng for locale-respecting behavior Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Enable locale-respecting behavior by disabling UTF-8 forcing and enabling setlocale. This mode mutates process-global libc state. ```toml [dependencies] unrar-ng = { version = "0.7", default-features = false, features = ["linux-batch-extract-setlocale"] } ``` -------------------------------- ### Using or to return alternative results Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the provided result if the current result is Err, otherwise returns the Ok value. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### size_hint() Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the bounds on the remaining length of the iterator. ```APIDOC ## fn size_hint(&self) -> (usize, Option) ### Description Returns the bounds on the remaining length of the iterator. ``` -------------------------------- ### Map Result with Default Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Use map_or, map_or_else, or map_or_default to handle both Ok and Err cases with a fallback. ```rust let x: Result<_, &str> = Ok("foo"); assert_eq!(x.map_or(42, |v| v.len()), 3); let x: Result<&str, _> = Err("bar"); assert_eq!(x.map_or(42, |v| v.len()), 42); ``` ```rust let k = 21; let x : Result<_, &str> = Ok("foo"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 3); let x : Result<&str, _> = Err("bar"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 42); ``` ```rust let x: Result<_, &str> = Ok("foo"); let y: Result<&str, _> = Err("bar"); assert_eq!(x.map_or_default(|x| x.len()), 3); assert_eq!(y.map_or_default(|y| y.len()), 0); ``` -------------------------------- ### pub fn and(self, res: Result) -> Result Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search=u32+-%3E+bool Returns res if the result is Ok, otherwise returns the Err value of self. ```APIDOC ## pub fn and(self, res: Result) -> Result ### Description Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`. ``` -------------------------------- ### Expect Error Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the Err value or panics if the result is an Ok. ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` -------------------------------- ### extract_to Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Extracts the file into the specified file path. ```APIDOC ## pub fn extract_to>(self, file: P) -> UnrarResult> ### Description Extracts the file into the specified file and returns the OpenArchive for further processing. ``` -------------------------------- ### Configure unrar-ng for stock upstream behavior Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Use stock upstream behavior where the caller is responsible for managing the locale. ```toml [dependencies] unrar-ng = { version = "0.7", default-features = false } ``` -------------------------------- ### Add unrar-ng to Cargo.toml Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/index.html?search=u32+-%3E+bool Include the dependency in your project configuration. ```toml [dependencies] unrar-ng = "0.7" ``` -------------------------------- ### Unwrap with Default Value Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the Ok value or the default value of the type if the result is an Err. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### Define Process struct Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Process.html The definition of the Process struct used for archive entry operations. ```rust pub struct Process; ``` -------------------------------- ### Expect Result Value Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the Ok value or panics with a provided message if the result is Err. ```rust let x: Result = Err("emergency failure"); x.expect("Testing expect"); // panics with `Testing expect: emergency failure` ``` ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### Chaining operations with and_then Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Demonstrates chaining fallible operations that may return Err. ```rust assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Modify archive path to the first part Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Updates the internal filename to point to the first part of a multipart collection. ```rust let mut archive = Archive::new("path/some.004.rar").as_first_part(); assert_eq!(archive.filename(), PathBuf::from("path/some.001.rar")); ``` -------------------------------- ### Computing defaults with unwrap_or_else Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the contained Ok value or computes a default value from a closure. ```rust fn count(x: &str) -> usize { x.len() } ``` -------------------------------- ### OpenArchive Struct Definition Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html?search=u32+-%3E+bool The primary structure for interacting with RAR archives, parameterized by open mode and cursor type. ```rust pub struct OpenArchive { /* private fields */ } ``` -------------------------------- ### Open a potentially broken archive Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Opens an archive in a specific mode even if it is malformed, with optional error tracking. ```rust let mut open_archive = Archive::new("file").break_open::(None)?; // use open_archive ``` ```rust let mut possible_error = None; let mut open_archive = Archive::new("file").break_open::(Some(&mut possible_error))?; // check the error, e.g.: possible_error.map(|error| eprintln!("recoverable error occurred: {error}")); // use open_archive ``` -------------------------------- ### OpenArchive Methods Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.OpenArchive.html Methods available on the OpenArchive struct for inspecting archive metadata and state. ```APIDOC ## pub fn is_locked(&self) -> bool ### Description Checks if the archive is locked. ## pub fn has_encrypted_headers(&self) -> bool ### Description Checks if the archive headers are encrypted. ## pub fn has_recovery_record(&self) -> bool ### Description Checks if the archive contains a recovery record. ## pub fn has_comment(&self) -> bool ### Description Checks if the archive contains comments. ## pub fn is_solid(&self) -> bool ### Description Checks if the archive is solid (all files in a single compressed block). ## pub fn volume_info(&self) -> VolumeInfo ### Description Returns volume information on the file that was initially opened. Returns `VolumeInfo::None` for single-part, `VolumeInfo::First` for the first volume, or `VolumeInfo::Subsequent` for other volumes. ``` -------------------------------- ### Unwrap Error Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/error/type.UnrarResult.html?search= Returns the Err value or panics if the result is an Ok. ```rust let x: Result = Ok(2); x.unwrap_err(); // panics with `2` ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Archive::nth_part Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html?search=std%3A%3Avec Returns the path for the nth part of a multipart collection. ```APIDOC ## pub fn nth_part(&self, n: i32) -> Option ### Description Returns the nth part of this multi-part collection or None if the archive does not appear to be a multipart archive. ``` -------------------------------- ### open_for_processing Source: https://docs.rs/unrar-ng/0.7.7/unrar_ng/struct.Archive.html Opens the underlying archive for processing, allowing payloads of each archive entry to be read. ```APIDOC ## pub fn open_for_processing(self) -> UnrarResult> ### Description Opens the underlying archive for processing, that is, the payloads of each archive entry can be actively read. What actually happens with individual entries (e.g. read, extract, skip, test), can be specified during processing. ```