### Create Digest with Custom Initial State Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Shows how to initialize a `Digest` with a specific starting state for a given CRC algorithm, allowing for variations in checksum computation based on the initial state. This is useful for specific CRC standards or testing. ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc); // CRC-32/ISO-HDLC with initial state of 0x00000000, instead of the default initial state // of 0xffffffff, let mut digest = Digest::new_with_init_state(Crc32IsoHdlc, 0x00000000); digest.update(b"123456789"); let checksum = digest.finalize(); // different initial state, so checksum will be different assert_eq!(checksum, 0xd202d277); let mut digest = Digest::new_with_init_state(Crc32IsoHdlc, 0xffffffff); digest.update(b"123456789"); let checksum = digest.finalize(); // same initial state as the default, so checksum will be the same assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Get Calculator Target Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Retrieves the target architecture used for CRC calculation optimization for a given algorithm. ```APIDOC ## Get Calculator Target Returns the target used to calculate the CRC checksum for the specified algorithm. ### Method ```rust use crc_fast::{get_calculator_target, CrcAlgorithm::Crc32IsoHdlc}; let target = get_calculator_target(Crc32IsoHdlc); println!("Target for CRC32IsoHdlc: {:?}", target); ``` ``` -------------------------------- ### Get Calculator Target for CRC Algorithm (Rust) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/fn Retrieves the target string for calculating CRC checksums for a given CRC algorithm. The returned strings are for informational purposes and may not be stable across versions. ```Rust pub fn get_calculator_target(_algorithm: CrcAlgorithm) -> String ``` ```Rust use crc_fast::{get_calculator_target, CrcAlgorithm::Crc32IsoHdlc); let target = get_calculator_target(Crc32IsoHdlc); ``` -------------------------------- ### Rust: Get Owned Type Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Defines the `Owned` associated type, typically the same as the source type for cloning. ```rust type Owned = T ``` -------------------------------- ### Rust: Get Type ID Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Retrieves the `TypeId` of the current object. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get Current CRC State Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Shows how to retrieve the current internal state of the CRC computation without finalizing it. This can be useful for debugging or for specific intermediate state tracking in complex algorithms. ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc); let mut digest = Digest::new(Crc32IsoHdlc); digest.update(b"123456789"); let state = digest.get_state(); // non-finalized state, so it won't match the final checksum assert_eq!(state, 0x340bc6d9); // finalized state will match the checksum assert_eq!(digest.finalize(), 0xcbf43926); ``` -------------------------------- ### Utility Functions Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Details on utility functions like `get_calculator_target`. ```APIDOC ## Functions ### get_calculator_target Returns the target used to calculate the CRC checksum for the specified algorithm. #### Usage Example ```rust use crc_fast::get_calculator_target; let target = get_calculator_target(crc_fast::CrcAlgorithm::Crc32IsoHdlc); println!("Target: {:?}", target); ``` ### Method `get_calculator_target(algorithm)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "algorithm": "Crc32IsoHdlc" } ``` ### Response #### Success Response (200) - **target** (string) - The target architecture or feature used for calculation (e.g., "SSE4.2", "AVX2", "NEON"). #### Response Example ```json { "target": "SSE4.2" } ``` ``` -------------------------------- ### Rust: Create Writer Adapter by Reference Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Creates a "by reference" adapter for the current writer instance. This allows for borrowing the writer's functionality. ```rust fn by_ref(&mut self) -> &mut Self ``` -------------------------------- ### Generic Blanket Implementations (e.g., Any, Borrow, CloneToUninit) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/enum Demonstrates blanket implementations of various generic traits for any type `T`. These include traits like `Any`, `Borrow`, `BorrowMut`, `CloneToUninit`, `From`, `Into`, `Same`, `ToOwned`, `TryFrom`, and `TryInto`, showcasing standard Rust practices. ```rust impl Any for T where T: 'static + ?Sized { fn type_id(&self) -> TypeId } impl Borrow for T where T: ?Sized { fn borrow(&self) -> &T } impl BorrowMut for T where T: ?Sized { fn borrow_mut(&mut self) -> &mut T } unsafe impl CloneToUninit for T where T: Clone { unsafe fn clone_to_uninit(&self, dest: *mut u8) } impl From for T { fn from(t: T) -> T } impl Into for T where U: From { fn into(self) -> U } impl Same for T { type Output = T } impl ToOwned for T where T: Clone { type Owned = T; fn to_owned(&self) -> T; fn clone_into(&self, target: &mut T); } impl TryFrom for T where U: Into { type Error = Infallible; fn try_from(value: U) -> Result>::Error> } impl TryInto for T where U: TryFrom { type Error = >::Error; fn try_into(self) -> Result>::Error> } ``` -------------------------------- ### Create Digest with Custom CRC Parameters Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Illustrates creating a `Digest` using custom CRC parameters, such as polynomial, initial state, and final XOR value. This allows for the implementation of any CRC variant not covered by predefined algorithms. ```rust use crc_fast::{Digest, CrcParams}; // Define custom CRC-32 parameters (equivalent to CRC-32/ISO-HDLC) let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let mut digest = Digest::new_with_params(custom_params); digest.update(b"123456789"); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Create and Use Digest with Default CRC32/ISO-HDLC Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Demonstrates how to create a new `Digest` instance using the default `Crc32IsoHdlc` algorithm, update it with data, and finalize the checksum. This is the most common way to compute CRC32/ISO-HDLC checksums. ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc); let mut digest = Digest::new(Crc32IsoHdlc); digest.update(b"123456789"); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Structs and Enums Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Information about the `CrcParams`, `Digest`, `CrcAlgorithm`, and `CrcKeysStorage` structs and enums. ```APIDOC ## Structs ### CrcParams Parameters for CRC computation, including polynomial, initial value, and other settings. ### Digest Represents a CRC Digest, which is used to compute CRC checksums. ## Enums ### CrcAlgorithm Supported CRC-32 and CRC-64 variants. ### CrcKeysStorage Internal storage for CRC folding keys that can accommodate different array sizes. This enum allows future expansion to support larger folding distances while maintaining backwards compatibility with existing const definitions. ``` -------------------------------- ### Custom CRC Parameters Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Allows defining and using custom CRC parameters for non-standard CRC algorithms. ```APIDOC ## Custom CRC Parameters For cases where you need to use CRC variants not included in the predefined algorithms, you can define custom CRC parameters using `CrcParams::new()` and use the `*_with_params` functions. ### checksum_with_params Computes the CRC checksum for the given data using custom CRC parameters. #### Usage Example ```rust use crc_fast::{checksum_with_params, CrcParams}; // Define custom CRC-32 parameters (equivalent to CRC-32/ISO-HDLC) let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let checksum = checksum_with_params(custom_params, b"123456789"); assert_eq!(checksum, 0xcbf43926); ``` ### Method `checksum_with_params(custom_params, data)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body ```json { "custom_params": { "name": "CRC-32/CUSTOM", "width": 32, "poly": "0x04c11db7", "init": "0xffffffff", "refin": true, "refout": true, "xorout": "0xffffffff" }, "data": "123456789" } ``` ### Response #### Success Response (200) - **checksum** (u32 or u64) - The computed CRC checksum using custom parameters. #### Response Example ```json { "checksum": 3152025094 } ``` --- ### checksum_combine_with_params Combines two CRC checksums using custom CRC parameters. ### Method `checksum_combine_with_params(custom_params, checksum1, checksum2, length2)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body ```json { "custom_params": { "name": "CRC-32/CUSTOM", "width": 32, "poly": "0x04c11db7", "init": "0xffffffff", "refin": true, "refout": true, "xorout": "0xffffffff" }, "checksum1": 1234, "checksum2": 56789, "length2": 5 } ``` ### Response #### Success Response (200) - **combined_checksum** (u32 or u64) - The combined CRC checksum using custom parameters. #### Response Example ```json { "combined_checksum": 3152025094 } ``` --- ### checksum_file_with_params Computes the CRC checksum for the given file using custom CRC parameters. ### Method `checksum_file_with_params(custom_params, file_path, limit)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body ```json { "custom_params": { "name": "CRC-32/CUSTOM", "width": 32, "poly": "0x04c11db7", "init": "0xffffffff", "refin": true, "refout": true, "xorout": "0xffffffff" }, "file_path": "/path/to/your/file.txt", "limit": null } ``` ### Response #### Success Response (200) - **checksum** (u32 or u64) - The computed CRC checksum for the file using custom parameters. #### Response Example ```json { "checksum": 3152025094 } ``` ``` -------------------------------- ### Rust: Try Conversion (TryFrom) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Performs a conversion that might fail, returning a `Result`. This is a generic implementation of `TryFrom`. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Digest Usage Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Demonstrates how to use the `Digest` struct to compute CRC checksums incrementally. ```APIDOC ## Digest Usage Implements the `digest::DynDigest` trait for easier integration with existing code. ### Method ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; let mut digest = Digest::new(Crc32IsoHdlc); digest.update(b"1234"); digest.update(b"56789"); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` ``` -------------------------------- ### Digest Write Trait Implementation Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Shows how to implement the `std::io::Write` trait with `Digest` for writing data directly from files. ```APIDOC ## Digest Write Implements the `std::io::Write` trait for easier integration with existing code. ### Usage Example ```rust use std::env; use std::fs::File; use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); // actual usage let mut digest = Digest::new(Crc32IsoHdlc); let mut file = File::open(file_on_disk).unwrap(); std::io::copy(&mut file, &mut digest).unwrap(); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` ### Method `std::io::copy(reader, digest)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (uses reader and writer traits) ### Request Example (Simulated file content) ``` 123456789 ``` ### Response #### Success Response (200) - **checksum** (u32 or u64) - The computed CRC checksum from the file content. #### Response Example ```json { "checksum": 3152025094 } ``` ``` -------------------------------- ### Rust: Try Conversion (TryInto) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Attempts to convert the value into another type, returning a `Result`. This is a generic implementation of `TryInto`. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Rust: Clone to Uninitialized Memory (Nightly) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Performs copy-assignment from `self` to uninitialized memory. This is a nightly-only experimental API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Checksum File Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Computes the CRC checksum for a file, optionally with a size limit. ```APIDOC ## checksum_file Computes the CRC checksum for the given file using the specified algorithm. ### Usage Example ```rust use std::env; use crc_fast::{checksum_file, CrcAlgorithm::Crc32IsoHdlc}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); let checksum = checksum_file(Crc32IsoHdlc, file_on_disk, None); assert_eq!(checksum.unwrap(), 0xcbf43926); ``` ### Method `checksum_file(algorithm, file_path, limit)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "algorithm": "Crc32IsoHdlc", "file_path": "/path/to/your/file.txt", "limit": null } ``` ### Response #### Success Response (200) - **checksum** (u32 or u64) - The computed CRC checksum for the file. #### Response Example ```json { "checksum": 3152025094 } ``` ``` -------------------------------- ### Digest Usage Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Demonstrates how to use the `Digest` trait to compute CRC checksums by updating with data chunks. ```APIDOC ## Digest Implements the `digest::DynDigest` trait for easier integration with existing code. ### Usage Example ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; let mut digest = Digest::new(Crc32IsoHdlc); digest.update(b"1234"); digest.update(b"56789"); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` ### Method `Digest::new(algorithm)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "data_chunk_1": "1234", "data_chunk_2": "56789" } ``` ### Response #### Success Response (200) - **checksum** (u32 or u64) - The computed CRC checksum. #### Response Example ```json { "checksum": 3152025094 } ``` ``` -------------------------------- ### Rust: Write Formatted String Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Writes a formatted string into the writer, handling any potential errors during the process. ```rust fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error> ``` -------------------------------- ### Compute CRC with custom parameters in Rust Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Calculates a CRC checksum using user-defined CRC parameters, such as polynomial, initial value, and reflection settings. This provides flexibility for non-standard CRC algorithms. Requires the 'crc-fast' crate. ```rust use crc_fast::{checksum_with_params, CrcParams}; // Define custom CRC-32 parameters (equivalent to CRC-32/ISO-HDLC) let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let checksum = checksum_with_params(custom_params, b"123456789"); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Checksum with Custom Parameters Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Enables calculation of CRC checksums using custom parameters for non-standard CRC algorithms. ```APIDOC ## Checksum with Custom Parameters For cases where you need to use CRC variants not included in the predefined algorithms, you can define custom CRC parameters using `CrcParams::new()` and use the `*_with_params` functions. ### Method ```rust use crc_fast::{checksum_with_params, CrcParams}; // Define custom CRC-32 parameters (equivalent to CRC-32/ISO-HDLC) let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let checksum = checksum_with_params(custom_params, b"123456789"); assert_eq!(checksum, 0xcbf43926); ``` ``` -------------------------------- ### Checksum File Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Calculates the CRC checksum for an entire file. ```APIDOC ## Checksum File Computes the CRC checksum for the given file using the specified algorithm. ### Method ```rust use std::env; use crc_fast::{checksum_file, CrcAlgorithm::Crc32IsoHdlc}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); let checksum = checksum_file(Crc32IsoHdlc, file_on_disk, None); assert_eq!(checksum.unwrap(), 0xcbf43926); ``` ``` -------------------------------- ### Rust: Check for Vectored Write Support Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Determines if the writer supports efficient vectorized write operations. This is a nightly-only experimental API. ```rust fn is_write_vectored(&self) -> bool ``` -------------------------------- ### Checksum Combine with Custom Parameters Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Combines two CRC checksums using custom CRC parameters, extending the flexibility for custom CRC algorithms. ```APIDOC ## Checksum Combine with Custom Parameters Combines two CRC checksums using custom CRC parameters. ### Method ```rust use crc_fast::{checksum_combine_with_params, CrcParams}; // Define custom CRC-32 parameters let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let checksum_1 = checksum_with_params(custom_params.clone(), b"1234"); let checksum_2 = checksum_with_params(custom_params.clone(), b"56789"); let checksum = checksum_combine_with_params(custom_params, checksum_1, checksum_2, 5); assert_eq!(checksum, 0xcbf43926); ``` ``` -------------------------------- ### Rust: Write Multiple Buffers (Vectored) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Attempts to write multiple buffers into the writer efficiently. This is a nightly-only experimental API. ```rust fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error> ``` -------------------------------- ### Simple Checksum Calculation Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Calculates the CRC checksum for a given byte slice using a specified algorithm. ```APIDOC ## checksum Computes the CRC checksum for the given data using the specified algorithm. ### Usage Example ```rust use crc_fast::{checksum, CrcAlgorithm::Crc32IsoHdlc}; let checksum = checksum(Crc32IsoHdlc, b"123456789"); assert_eq!(checksum, 0xcbf43926); ``` ### Method `checksum(algorithm, data)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "algorithm": "Crc32IsoHdlc", "data": "123456789" } ``` ### Response #### Success Response (200) - **checksum** (u32 or u64) - The computed CRC checksum. #### Response Example ```json { "checksum": 3152025094 } ``` ``` -------------------------------- ### Rust: Compute CRC32 Checksum using std::io::Write Trait Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Shows how to use the `std::io::Write` trait implementation provided by `crc-fast` for computing CRC checksums directly from file content. This allows seamless integration with file I/O operations. It requires `std::env`, `std::fs::File`, `crc_fast`, and a specified `CrcAlgorithm`. ```rust use std::env; use std::fs::File; use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); // actual usage let mut digest = Digest::new(Crc32IsoHdlc); let mut file = File::open(file_on_disk).unwrap(); std::io::copy(&mut file, &mut digest).unwrap(); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Checksum File with Custom Parameters Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Calculates the CRC checksum for a file using custom CRC parameters. ```APIDOC ## Checksum File with Custom Parameters Computes the CRC checksum for the given file using custom CRC parameters. ### Method ```rust use std::env; use crc_fast::{checksum_file_with_params, CrcParams}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); // Define custom CRC-32 parameters let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let checksum = checksum_file_with_params(custom_params, file_on_disk, None); assert_eq!(checksum.unwrap(), 0xcbf43926); ``` ``` -------------------------------- ### Digest Write Usage Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Shows how to implement the `std::io::Write` trait with the `Digest` struct for writing data to a CRC calculation. ```APIDOC ## Digest Write Usage Implements the `std::io::Write` trait for easier integration with existing code. ### Method ```rust use std::env; use std::fs::File; use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); // actual usage let mut digest = Digest::new(Crc32IsoHdlc); let mut file = File::open(file_on_disk).unwrap(); std::io::copy(&mut file, &mut digest).unwrap(); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` ``` -------------------------------- ### Compute CRC checksum for a file in Rust Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Computes the CRC checksum for the entire content of a file. This function takes the CRC algorithm and the file path as arguments. It can optionally take a progress callback. Requires the 'crc-fast' crate. ```rust use std::env; use crc_fast::{checksum_file, CrcAlgorithm::Crc32IsoHdlc}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); let checksum = checksum_file(Crc32IsoHdlc, file_on_disk, None); assert_eq!(checksum.unwrap(), 0xcbf43926); ``` -------------------------------- ### Rust: Compute CRC32 Checksum for a File Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Provides a function to compute the CRC32 checksum of an entire file. This is efficient for validating file integrity. It requires the `crc-fast` crate, a specified `CrcAlgorithm`, and the file path. An optional parameter can be provided to limit the checksum computation to a specific number of bytes. ```rust use std::env; use crc_fast::{checksum_file, CrcAlgorithm::Crc32IsoHdlc}; // for example/test purposes only, use your own file path let file_path = env::current_dir().expect("missing working dir").join("crc-check.txt"); let file_on_disk = file_path.to_str().unwrap(); let checksum = checksum_file(Crc32IsoHdlc, file_on_disk, None); assert_eq!(checksum.unwrap(), 0xcbf43926); ``` -------------------------------- ### Rust: Write All Bytes to Writer Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Attempts to write an entire buffer of bytes into the writer. This method is crucial for sequential data transfer. ```rust fn write_all(&mut self, buf: &[u8]) -> Result<()> ``` -------------------------------- ### Checksum Calculation Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Provides a direct function to calculate the CRC checksum for a given byte slice. ```APIDOC ## Checksum Calculation Computes the CRC checksum for the given data using the specified algorithm. ### Method ```rust use crc_fast::{checksum, CrcAlgorithm::Crc32IsoHdlc}; let checksum = checksum(Crc32IsoHdlc, b"123456789"); assert_eq!(checksum, 0xcbf43926); ``` ``` -------------------------------- ### Rust: Compute CRC32 Checksum with Custom Parameters Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Enables the computation of CRC checksums using custom parameters, allowing for CRC variants not pre-defined in the `CrcAlgorithm` enum. This is achieved by creating a `CrcParams` struct and using the `checksum_with_params` function. It requires the `crc-fast` crate and the `CrcParams` struct. ```rust use crc_fast::{checksum_with_params, CrcParams}; // Define custom CRC-32 parameters (equivalent to CRC-32/ISO-HDLC) let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let checksum = checksum_with_params(custom_params, b"123456789"); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Clone Implementation for CrcKeysStorage Source: https://docs.rs/crc-fast/1.5.0/crc_fast/enum Implements the Clone trait for the CrcKeysStorage enum, allowing instances to be duplicated. This ensures that the enum's data can be copied. ```rust impl Clone for CrcKeysStorage { fn clone(&self) -> CrcKeysStorage } ``` -------------------------------- ### Rust: Flush Output Stream Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Ensures all buffered contents are written to their destination. This is a fundamental operation for output streams. ```rust fn flush(&mut self) -> Result<()> ``` -------------------------------- ### Debug Implementation for CrcKeysStorage Source: https://docs.rs/crc-fast/1.5.0/crc_fast/enum Implements the Debug trait for the CrcKeysStorage enum, enabling formatted output for debugging purposes. This allows the enum's state to be inspected when printing. ```rust impl Debug for CrcKeysStorage { fn fmt(&self, f: &mut Formatter<'_>) -> Result } ``` -------------------------------- ### PartialEq Implementation for CrcKeysStorage and [u64; 23] Source: https://docs.rs/crc-fast/1.5.0/crc_fast/enum Implements the PartialEq trait for comparing CrcKeysStorage enum variants with [u64; 23] arrays and vice versa. This allows for direct equality checks between the enum and array types. ```rust impl PartialEq<[u64; 23]> for CrcKeysStorage { fn eq(&self, other: &[u64; 23]) -> bool } impl PartialEq for [u64; 23] { fn eq(&self, other: &CrcKeysStorage) -> bool } ``` -------------------------------- ### Combine CRC checksums in Rust Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Combines two previously computed CRC checksums into a single checksum, representing the CRC of concatenated data. Requires the CRC algorithm, the two checksums, and the length of the second data segment. Uses the 'crc-fast' crate. ```rust use crc_fast::{checksum, checksum_combine, CrcAlgorithm::Crc32IsoHdlc}; let checksum_1 = checksum(Crc32IsoHdlc, b"1234"); let checksum_2 = checksum(Crc32IsoHdlc, b"56789"); let checksum = checksum_combine(Crc32IsoHdlc, checksum_1, checksum_2, 5); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Checksum Combine Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Allows combining two CRC checksums, useful for parallel processing or segmented data. ```APIDOC ## Checksum Combine Combines two CRC checksums using the specified algorithm. ### Method ```rust use crc_fast::{checksum, checksum_combine, CrcAlgorithm::Crc32IsoHdlc}; let checksum_1 = checksum(Crc32IsoHdlc, b"1234"); let checksum_2 = checksum(Crc32IsoHdlc, b"56789"); let checksum = checksum_combine(Crc32IsoHdlc, checksum_1, checksum_2, 5); assert_eq!(checksum, 0xcbf43926); ``` ``` -------------------------------- ### Rust: Identity Conversion (From) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Returns the argument unchanged. This is a generic implementation of the `From` trait. ```rust fn from(t: T) -> T ``` -------------------------------- ### Digest API Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct The Digest struct provides methods for calculating CRC checksums. You can create a new Digest with a specific algorithm, an initial state, or custom parameters. The `update` method processes data, and `finalize` returns the computed checksum. ```APIDOC ## Digest Struct ### Description Represents a CRC Digest, which is used to compute CRC checksums. The `Digest` struct maintains the state of the CRC computation, including the current state, the amount of data processed, the CRC parameters, and the calculator function used to perform the CRC calculation. ## Implementations ### `impl Digest` #### `pub fn new(algorithm: CrcAlgorithm) -> Self` ##### Description Creates a new `Digest` instance for the specified CRC algorithm. ##### Examples ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; let mut digest = Digest::new(Crc32IsoHdlc); digest.update(b"123456789"); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` #### `pub fn new_with_init_state(algorithm: CrcAlgorithm, init_state: u64) -> Self` ##### Description Creates a new `Digest` instance for the specified CRC algorithm with a custom initial state. ##### Examples ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; // CRC-32/ISO-HDLC with initial state of 0x00000000, instead of the default initial state // of 0xffffffff, let mut digest = Digest::new_with_init_state(Crc32IsoHdlc, 0x00000000); digest.update(b"123456789"); let checksum = digest.finalize(); // different initial state, so checksum will be different assert_eq!(checksum, 0xd202d277); let mut digest = Digest::new_with_init_state(Crc32IsoHdlc, 0xffffffff); digest.update(b"123456789"); let checksum = digest.finalize(); // same initial state as the default, so checksum will be the same assert_eq!(checksum, 0xcbf43926); ``` #### `pub fn new_with_params(params: CrcParams) -> Self` ##### Description Creates a new `Digest` instance with custom CRC parameters. ##### Examples ```rust use crc_fast::{Digest, CrcParams}; // Define custom CRC-32 parameters (equivalent to CRC-32/ISO-HDLC) let custom_params = CrcParams::new( "CRC-32/CUSTOM", 32, 0x04c11db7, 0xffffffff, true, 0xffffffff, 0xcbf43926, ); let mut digest = Digest::new_with_params(custom_params); digest.update(b"123456789"); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` #### `pub fn update(&mut self, data: &[u8])` ##### Description Updates the CRC state with the given data. #### `pub fn finalize(&self) -> u64` ##### Description Finalizes the CRC computation and returns the result. #### `pub fn finalize_reset(&mut self) -> u64` ##### Description Finalizes the CRC computation, resets the state, and returns the result. #### `pub fn reset(&mut self)` ##### Description Resets the CRC state to its initial value. #### `pub fn combine(&mut self, other: &Self)` ##### Description Combines the CRC state with a second `Digest` instance. #### `pub fn get_amount(&self) -> u64` ##### Description Gets the amount of data processed so far. #### `pub fn get_state(&self) -> u64` ##### Description Gets the current CRC state. ##### Examples ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; let mut digest = Digest::new(Crc32IsoHdlc); digest.update(b"123456789"); let state = digest.get_state(); // non-finalized state, so it won't match the final checksum assert_eq!(state, 0x340bc6d9); // finalized state will match the checksum assert_eq!(digest.finalize(), 0xcbf43926); ``` ### `impl Clone for Digest` #### `fn clone(&self) -> Digest` ##### Description Returns a duplicate of the value. #### `fn clone_from(&mut self, source: &Self)` ##### Description Performs copy-assignment from `source`. ### `impl Debug for Digest` #### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` ##### Description Formats the value using the given formatter. ### `impl DynDigest for Digest` #### `fn update(&mut self, data: &[u8])` ##### Description Digest input data. #### `fn finalize_into(self, buf: &mut [u8]) -> Result<(), InvalidBufferSize>` ##### Description Write result into provided array and consume the hasher instance. #### `fn finalize_into_reset( &mut self, out: &mut [u8], ) -> Result<(), InvalidBufferSize>` ##### Description Write result into provided array and reset the hasher instance. #### `fn reset(&mut self)` ##### Description Reset hasher instance to its initial state. #### `fn output_size(&self) -> usize` ##### Description Get output size of the hasher. #### `fn box_clone(&self) -> Box` ##### Description Clone hasher state into a boxed trait object. #### `fn finalize_reset(&mut self) -> Box<[u8]>` ##### Description Retrieve result and reset hasher instance. #### `fn finalize(self: Box) -> Box<[u8]>` ##### Description Retrieve result and consume boxed hasher instance. ### `impl Write for Digest` #### `fn write(&mut self, buf: &[u8]) -> Result` ##### Description Writes a buffer into this writer, returning how many bytes were written. #### `fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result` ##### Description Like `write`, except that it writes from a slice of buffers. ``` -------------------------------- ### Checksum Combine Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Combines two CRC checksums, useful for calculating CRC of concatenated data without recomputing the whole sequence. ```APIDOC ## checksum_combine Combines two CRC checksums using the specified algorithm. ### Usage Example ```rust use crc_fast::{checksum, checksum_combine, CrcAlgorithm::Crc32IsoHdlc}; let checksum_1 = checksum(Crc32IsoHdlc, b"1234"); let checksum_2 = checksum(Crc32IsoHdlc, b"56789"); let checksum = checksum_combine(Crc32IsoHdlc, checksum_1, checksum_2, 5); assert_eq!(checksum, 0xcbf43926); ``` ### Method `checksum_combine(algorithm, checksum1, checksum2, length2)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "algorithm": "Crc32IsoHdlc", "checksum1": 1234, "checksum2": 56789, "length2": 5 } ``` ### Response #### Success Response (200) - **combined_checksum** (u32 or u64) - The combined CRC checksum. #### Response Example ```json { "combined_checksum": 3152025094 } ``` ``` -------------------------------- ### Rust: Compute CRC32 Digest using Digest Trait Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Demonstrates how to compute a CRC32 checksum using the `Digest` trait from the `crc-fast` crate. This is useful for incremental checksumming of data streams. It requires the `crc-fast` crate and a specified `CrcAlgorithm`. ```rust use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc}; let mut digest = Digest::new(Crc32IsoHdlc); digest.update(b"1234"); digest.update(b"56789"); let checksum = digest.finalize(); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Rust: Clone Into Existing Data Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Uses borrowed data to replace the contents of owned data, typically by cloning. This is a method from the `ToOwned` trait. ```rust fn clone_into(&self, target: &mut T) ``` -------------------------------- ### Rust: Borrow Immutably Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Provides immutable access to the underlying data. This is a method from the `Borrow` trait. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### Rust: Compute CRC32 Checksum Directly Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index A straightforward method to compute a CRC32 checksum for a given byte slice using the `checksum` function from the `crc-fast` crate. This is suitable for computing checksums of complete data chunks. It requires the `crc-fast` crate and a specified `CrcAlgorithm`. ```rust use crc_fast::{checksum, CrcAlgorithm::Crc32IsoHdlc}; let checksum = checksum(Crc32IsoHdlc, b"123456789"); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Rust: Identity Conversion (Into) Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Converts the value into another type using the `From` trait. This is a generic implementation of the `Into` trait. ```rust fn into(self) -> U ``` -------------------------------- ### Rust: Combine Two CRC32 Checksums Source: https://docs.rs/crc-fast/1.5.0/crc_fast/index Illustrates how to combine two previously computed CRC32 checksums into a single checksum, useful for distributed or segmented data processing. This function requires the `crc-fast` crate, a specified `CrcAlgorithm`, and the two checksums along with the length of the second data segment. ```rust use crc_fast::{checksum, checksum_combine, CrcAlgorithm::Crc32IsoHdlc}; let checksum_1 = checksum(Crc32IsoHdlc, b"1234"); let checksum_2 = checksum(Crc32IsoHdlc, b"56789"); let checksum = checksum_combine(Crc32IsoHdlc, checksum_1, checksum_2, 5); assert_eq!(checksum, 0xcbf43926); ``` -------------------------------- ### Rust: Borrow Mutably Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Provides mutable access to the underlying data. This is a method from the `BorrowMut` trait. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### Copy Implementation for CrcKeysStorage Source: https://docs.rs/crc-fast/1.5.0/crc_fast/enum Implements the Copy trait for the CrcKeysStorage enum. This indicates that the enum can be copied implicitly (stack-based copying) rather than moved. ```rust impl Copy for CrcKeysStorage ``` -------------------------------- ### CrcKeysStorage Enum Definition Source: https://docs.rs/crc-fast/1.5.0/crc_fast/enum Defines an enum for internal storage of CRC folding keys, supporting different array sizes for flexibility and future expansion. It includes variants for the current 23-key format and a future 25-key format for testing. ```rust pub enum CrcKeysStorage { KeysFold256([u64; 23]), KeysFutureTest([u64; 25]), } ``` -------------------------------- ### Rust: Create Owned Data Source: https://docs.rs/crc-fast/1.5.0/crc_fast/struct Creates owned data from borrowed data, usually by cloning. This is a method from the `ToOwned` trait. ```rust fn to_owned(&self) -> T ``` -------------------------------- ### Compute CRC checksum directly in Rust Source: https://docs.rs/crc-fast/1.5.0/crc_fast/crc-fast/1 Computes the CRC checksum for a given byte slice using a specified CRC algorithm. This is a straightforward function call from the 'crc-fast' crate. ```rust use crc_fast::{checksum, CrcAlgorithm::Crc32IsoHdlc}; let checksum = checksum(Crc32IsoHdlc, b"123456789"); assert_eq!(checksum, 0xcbf43926); ```