How it works...

In this recipe, we compress the source code directory into archive.tar.gz. We create a file with File::create("archive.tar.gz") and assign it to the tar_gz variable. We then wrap it using flate2::write::GzEncoder and tar::Builder. Lastly, we add the contents of the ../sample_com directory recursively into the archive under ./backup with Builder::append_dir_all.

flate2::write::GzEncoder is responsible for transparently compressing the data prior to writing it to archive.tar.gz.

The error-chain crate is a library for consistent and reliable error handling that makes it easier to take full advantage of Rust's powerful error-handling features, without the overhead of maintaining boilerplate error types and conversions. It implements a strategy for defining your own error types, as well as conversions from others' error types.

The basic pattern we use here has a function named run() that produces a Result that acts like a real main function. We use the error-chain crate to make ? work within run. This is using the error_chain! macro from the error-chain to define a custom Error and Result type, along with automatic conversions from the crate error types. The automatic conversions make the ? operator work. The quick_main! macro generates the actual main function and prints out the error if it occurs during the course of execution.

We return Ok(()) to the quick_run! macro to ensure that the program executed successfully without any errors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.242