### Publish a New Release Source: https://github.com/oyvindln/adler2/blob/main/RELEASE_PROCESS.md Execute this command to bump versions, tag, and publish. Ensure cargo-release is installed. Use 'major', 'minor', or 'patch' for the level. ```bash cargo release ``` -------------------------------- ### Get Current Adler32 Checksum Source: https://context7.com/oyvindln/adler2/llms.txt Call checksum() at any point to retrieve the current Adler-32 value without altering the internal state. ```rust use adler2::Adler32; let mut adler = Adler32::new(); adler.write_slice(b"Wiki"); let intermediate = adler.checksum(); println!("After 'Wiki': 0x{:08X}", intermediate); // Output: After 'Wiki': 0x04720127 adler.write_slice(b"pedia"); let final_checksum = adler.checksum(); println!("After 'Wikipedia': 0x{:08X}", final_checksum); // Output: After 'Wikipedia': 0x11E60398 // Matches Wikipedia's Adler-32 example assert_eq!(final_checksum, 0x11E60398); ``` -------------------------------- ### Adler32::new Source: https://context7.com/oyvindln/adler2/llms.txt Creates a new Adler-32 checksum calculator instance with the default initial state (a=1, b=0). This is the primary way to create an `Adler32` instance for incremental checksum computation. ```APIDOC ## Adler32::new ### Description Creates a new Adler-32 checksum calculator instance with the default initial state (a=1, b=0). This is the primary way to create an `Adler32` instance for incremental checksum computation. ### Method `new()` ### Parameters None ### Request Example ```rust use adler2::Adler32; // Create a new Adler32 instance let mut adler = Adler32::new(); // Add data incrementally adler.write_slice(b"Hello, "); adler.write_slice(b"World!"); // Get the final checksum let checksum = adler.checksum(); println!("Checksum: 0x{:08X}", checksum); // Output: Checksum: 0x1F9E046A ``` ### Response #### Success Response (200) An `Adler32` instance. #### Response Example ```rust // No direct response example, but the instance is used as shown in the Request Example. ``` ``` -------------------------------- ### Create and Use Adler32 for Incremental Checksum Source: https://context7.com/oyvindln/adler2/llms.txt Use Adler32::new() to create a calculator and write_slice() to add data incrementally. Retrieve the final checksum with checksum(). ```rust use adler2::Adler32; // Create a new Adler32 instance let mut adler = Adler32::new(); // Add data incrementally adler.write_slice(b"Hello, "); adler.write_slice(b"World!"); // Get the final checksum let checksum = adler.checksum(); println!("Checksum: 0x{:08X}", checksum); // Output: Checksum: 0x1F9E046A ``` -------------------------------- ### Resume Adler32 Checksum Calculation Source: https://context7.com/oyvindln/adler2/llms.txt Use Adler32::from_checksum() to create an instance from a previous checksum value, allowing calculation to be resumed. ```rust use adler2::Adler32; // First session: compute partial checksum let mut adler = Adler32::new(); adler.write_slice(b"rust"); let partial_checksum = adler.checksum(); println!("Partial: 0x{:08X}", partial_checksum); // Output: Partial: 0x03E70147 // Later session: resume from saved checksum let mut resumed = Adler32::from_checksum(partial_checksum); resumed.write_slice(b"acean"); let final_checksum = resumed.checksum(); println!("Final: 0x{:08X}", final_checksum); // Output: Final: 0x0C1D02D5 // Verify it matches computing all at once assert_eq!(final_checksum, adler2::adler32_slice(b"rustacean")); ``` -------------------------------- ### Compute Adler-32 Checksum in no_std Environment Source: https://context7.com/oyvindln/adler2/llms.txt Demonstrates computing Adler-32 checksums in a `#![no_std]` environment using `adler32_slice` for direct computation and `Adler32` struct for incremental updates. ```rust // In a no_std environment #![no_std] use adler2::{Adler32, adler32_slice}; fn compute_checksum(data: &[u8]) -> u32 { // Using the convenience function adler32_slice(data) } fn compute_incremental(chunks: &[&[u8]]) -> u32 { // Using the stateful struct let mut adler = Adler32::new(); for chunk in chunks { adler.write_slice(chunk); } adler.checksum() } // Both approaches yield identical results let data = b"test data"; let result1 = compute_checksum(data); let result2 = compute_incremental(&[b"test ", b"data"]); assert_eq!(result1, result2); ``` -------------------------------- ### Add Adler2 Dependency to Cargo.toml Source: https://github.com/oyvindln/adler2/blob/main/README.md Add this entry to your Cargo.toml file to include the adler2 crate in your project. ```toml [dependencies] adler2 = "2.0.0" ``` -------------------------------- ### Adler2 no_std Support Configuration Source: https://context7.com/oyvindln/adler2/llms.txt Configures the Adler2 library for `#![no_std]` environments by disabling the default `std` feature in Cargo.toml. ```toml # Cargo.toml for no_std usage [dependencies] adler2 = { version = "2.0", default-features = false } ``` -------------------------------- ### Process Data in Chunks with Adler32 Source: https://context7.com/oyvindln/adler2/llms.txt Use write_slice() to add byte slices to the ongoing checksum. For best performance, use slices with at least a few thousand bytes. ```rust use adler2::Adler32; let mut adler = Adler32::new(); // Process data in chunks (simulating streaming data) let chunks = [ &[0u8, 1, 2][..], &[3u8, 4, 5][..], ]; for chunk in chunks { adler.write_slice(chunk); } let checksum = adler.checksum(); assert_eq!(checksum, 0x00290010); println!("Checksum of [0,1,2,3,4,5]: 0x{:08X}", checksum); // Output: Checksum of [0,1,2,3,4,5]: 0x00290010 ``` -------------------------------- ### Adler32::from_checksum Source: https://context7.com/oyvindln/adler2/llms.txt Creates an `Adler32` instance from a precomputed checksum value, allowing resumption of checksum calculation without keeping the original instance. This is useful for persisting and resuming checksum state across sessions. ```APIDOC ## Adler32::from_checksum ### Description Creates an `Adler32` instance from a precomputed checksum value, allowing resumption of checksum calculation without keeping the original instance. This is useful for persisting and resuming checksum state across sessions. ### Method `from_checksum(checksum: u32)` ### Parameters #### Path Parameters - **checksum** (u32) - Required - The precomputed Adler-32 checksum value. ### Request Example ```rust use adler2::Adler32; // First session: compute partial checksum let mut adler = Adler32::new(); adler.write_slice(b"rust"); let partial_checksum = adler.checksum(); println!("Partial: 0x{:08X}", partial_checksum); // Output: Partial: 0x03E70147 // Later session: resume from saved checksum let mut resumed = Adler32::from_checksum(partial_checksum); resumed.write_slice(b"acean"); let final_checksum = resumed.checksum(); println!("Final: 0x{:08X}", final_checksum); // Output: Final: 0x0C1D02D5 // Verify it matches computing all at once assert_eq!(final_checksum, adler2::adler32_slice(b"rustacean")); ``` ### Response #### Success Response (200) An `Adler32` instance initialized with the provided checksum. #### Response Example ```rust // No direct response example, but the instance is used as shown in the Request Example. ``` ``` -------------------------------- ### Compute Adler-32 Checksum from BufRead Source: https://context7.com/oyvindln/adler2/llms.txt Computes the Adler-32 checksum from any type implementing BufRead, suitable for files or streams. Requires the `std` feature. ```rust use adler2::adler32; use std::io::{BufReader, Cursor}; // Compute checksum from an in-memory buffer let data = b"Hello, World!"; let mut reader = BufReader::new(Cursor::new(data)); let checksum = adler32(&mut reader).unwrap(); println!("Checksum: 0x{:08X}", checksum); // Output: Checksum: 0x1C49043D ``` ```rust // Computing checksum from a file use std::fs::File; use std::io; fn compute_file_checksum(path: &str) -> io::Result { let file = File::open(path)?; let mut reader = BufReader::new(file); adler32(&mut reader) } // Example usage: // let file_checksum = compute_file_checksum("data.bin")?; // println!("File checksum: 0x{:08X}", file_checksum); ``` -------------------------------- ### Implement Hasher Trait with Adler32 Source: https://context7.com/oyvindln/adler2/llms.txt Integrates Adler32 with Rust's hashing infrastructure by implementing the standard library's Hasher trait. Allows using Adler32 with any hashable type. ```rust use adler2::Adler32; use std::hash::{Hash, Hasher}; #[derive(Hash)] struct DataPacket { id: u32, payload: [u8; 4], } let mut adler = Adler32::new(); let packet = DataPacket { id: 12345, payload: [0xDE, 0xAD, 0xBE, 0xEF], }; packet.hash(&mut adler); // Using Hasher::finish() returns checksum as u64 let hash_value = adler.finish(); println!("Hash value: 0x{:016X}", hash_value); // Or use checksum() for u32 let checksum = adler.checksum(); println!("Checksum: 0x{:08X}", checksum); // Works with any hashable type let mut adler2 = Adler32::new(); "test string".hash(&mut adler2); println!("String hash: 0x{:08X}", adler2.checksum()); ``` -------------------------------- ### Compute Adler32 Checksum for a Byte Slice Source: https://context7.com/oyvindln/adler2/llms.txt Use adler32_slice() for a quick, one-time checksum calculation on a complete byte slice. Handles empty slices by returning 1. ```rust use adler2::adler32_slice; // Compute checksum of a string let text = b"Wikipedia"; let checksum = adler32_slice(text); assert_eq!(checksum, 0x11E60398); println!("Adler-32 of 'Wikipedia': 0x{:08X}", checksum); // Output: Adler-32 of 'Wikipedia': 0x11E60398 // Compute checksum of binary data let binary_data: Vec = (0..=255).collect(); let binary_checksum = adler32_slice(&binary_data); println!("Checksum of 0-255: 0x{:08X}", binary_checksum); // Output: Checksum of 0-255: 0x00F00100 // Empty data has checksum of 1 assert_eq!(adler32_slice(&[]), 1); ``` -------------------------------- ### adler32_slice Source: https://context7.com/oyvindln/adler2/llms.txt A convenience function that computes the Adler-32 checksum of a byte slice in a single call. This is the simplest way to compute a checksum when all data is available in memory. ```APIDOC ## adler32_slice ### Description A convenience function that computes the Adler-32 checksum of a byte slice in a single call. This is the simplest way to compute a checksum when all data is available in memory. ### Method `adler32_slice(data: &[u8]) -> u32` ### Parameters #### Path Parameters - **data** (&[u8]) - Required - The byte slice for which to compute the checksum. ### Request Example ```rust use adler2::adler32_slice; // Compute checksum of a string let text = b"Wikipedia"; let checksum = adler32_slice(text); assert_eq!(checksum, 0x11E60398); println!("Adler-32 of 'Wikipedia': 0x{:08X}", checksum); // Output: Adler-32 of 'Wikipedia': 0x11E60398 // Compute checksum of binary data let binary_data: Vec = (0..=255).collect(); let binary_checksum = adler32_slice(&binary_data); println!("Checksum of 0-255: 0x{:08X}", binary_checksum); // Output: Checksum of 0-255: 0x00F00100 // Empty data has checksum of 1 assert_eq!(adler32_slice(&[]), 1); ``` ### Response #### Success Response (200) - **checksum** (u32) - The computed Adler-32 checksum value. #### Response Example ```rust // The checksum value is returned as a u32, as shown in the Request Example. ``` ``` -------------------------------- ### Adler32::write_slice Source: https://context7.com/oyvindln/adler2/llms.txt Adds a byte slice to the ongoing checksum calculation. For optimal performance, call this method with slices containing at least a few thousand bytes to maximize the benefits of the internal SIMD-friendly algorithm. ```APIDOC ## Adler32::write_slice ### Description Adds a byte slice to the ongoing checksum calculation. For optimal performance, call this method with slices containing at least a few thousand bytes to maximize the benefits of the internal SIMD-friendly algorithm. ### Method `write_slice(&mut self, data: &[u8])` ### Parameters #### Path Parameters - **data** (&[u8]) - Required - The byte slice to add to the checksum calculation. ### Request Example ```rust use adler2::Adler32; let mut adler = Adler32::new(); // Process data in chunks (simulating streaming data) let chunks = [ &[0u8, 1, 2][..], &[3u8, 4, 5][..], ]; for chunk in chunks { adler.write_slice(chunk); } let checksum = adler.checksum(); assert_eq!(checksum, 0x00290010); println!("Checksum of [0,1,2,3,4,5]: 0x{:08X}", checksum); // Output: Checksum of [0,1,2,3,4,5]: 0x00290010 ``` ### Response #### Success Response (200) None. This method modifies the internal state of the `Adler32` instance. #### Response Example ```rust // No direct response example. ``` ``` -------------------------------- ### Adler32::checksum Source: https://context7.com/oyvindln/adler2/llms.txt Returns the current Adler-32 checksum value as a 32-bit unsigned integer. The checksum can be retrieved at any point during computation without affecting the internal state. ```APIDOC ## Adler32::checksum ### Description Returns the current Adler-32 checksum value as a 32-bit unsigned integer. The checksum can be retrieved at any point during computation without affecting the internal state. ### Method `checksum(&self) -> u32` ### Parameters None ### Request Example ```rust use adler2::Adler32; let mut adler = Adler32::new(); adler.write_slice(b"Wiki"); let intermediate = adler.checksum(); println!("After 'Wiki': 0x{:08X}", intermediate); // Output: After 'Wiki': 0x04720127 adler.write_slice(b"pedia"); let final_checksum = adler.checksum(); println!("After 'Wikipedia': 0x{:08X}", final_checksum); // Output: After 'Wikipedia': 0x11E60398 // Matches Wikipedia's Adler-32 example assert_eq!(final_checksum, 0x11E60398); ``` ### Response #### Success Response (200) - **checksum** (u32) - The current Adler-32 checksum value. #### Response Example ```rust // The checksum value is returned as a u32, as shown in the Request Example. ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.