1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This file is part of helpers4.
// Copyright (C) 2025 baxyz
// SPDX-License-Identifier: LGPL-3.0-or-later
use decode_into;
use DecodeError;
/// Decodes a hexadecimal string into `out`, which must be exactly half as long as the string.
///
/// Nothing is allocated; on error `out` may be partially written.
///
/// # Arguments
///
/// - `hex` - The hexadecimal string to decode.
/// - `out` - The buffer to decode into; must be exactly half of `hex`'s length.
///
/// # Errors
///
/// [`DecodeError::OddLength`], [`DecodeError::InvalidLength`] when the string does not match
/// `out.len() * 2`, or [`DecodeError::InvalidChar`].
///
/// # Examples
///
/// ```
/// use helpers4::hex::decode_to_slice;
///
/// let mut buf = [0u8; 2];
/// decode_to_slice("beef", &mut buf)?;
/// assert_eq!(buf, [0xbe, 0xef]);
/// # Ok::<(), helpers4::hex::DecodeError>(())
/// ```