Skip to main content

hashcrew/
io.rs

1// Copyright 2026 FastLabs Developers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Standard I/O adapters for streaming hash states.
16
17macro_rules! impl_write {
18    ($feature:literal, $($implementation:tt)*) => {
19        #[cfg(feature = $feature)]
20        $($implementation)* {
21            #[inline]
22            fn write(&mut self, input: &[u8]) -> std::io::Result<usize> {
23                self.update(input);
24                Ok(input.len())
25            }
26
27            #[inline]
28            fn flush(&mut self) -> std::io::Result<()> {
29                Ok(())
30            }
31        }
32    };
33}
34
35impl_write!("fnv", impl std::io::Write for crate::fnv::Fnv1a32);
36impl_write!("fnv", impl std::io::Write for crate::fnv::Fnv1a64);
37impl_write!("md5", impl std::io::Write for crate::md5::Md5);
38impl_write!("murmur", impl std::io::Write for crate::murmur::Murmur3X86_32);
39impl_write!("murmur", impl std::io::Write for crate::murmur::Murmur3X86_128);
40impl_write!("murmur", impl std::io::Write for crate::murmur::Murmur3X64_128);
41impl_write!("xxhash", impl std::io::Write for crate::xxhash::Xxh32);
42impl_write!("xxhash", impl std::io::Write for crate::xxhash::Xxh64);
43impl_write!("xxhash", impl<S: AsRef<[u8]>> std::io::Write for crate::xxhash::Xxh3_64<S>);
44impl_write!("xxhash", impl<S: AsRef<[u8]>> std::io::Write for crate::xxhash::Xxh3_128<S>);