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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! This module provides utility functions for converting between `usize`, `i32`, and string representations.
//! It includes methods for converting `usize` to a string, converting a string to a `usize`, and converting
//! a non-negative `i32` to a `usize`.
/// Converts a `usize` number into a string slice (`&'static str`).
///
/// This function manually converts the digits of a `usize` into a string representation stored in a static buffer.
/// It handles the case where `num` is zero and reverses the digits to ensure correct order in the final string.
///
/// # Example
///
/// ```rust
/// let num = 12345;
/// let result = usize_to_str(num);
/// assert_eq!(result, "12345");
/// ```
/// Converts a string slice (`&str`) into a `usize`, returning `None` if the string is invalid.
///
/// This function assumes that the string contains only digits. If any non-digit characters are encountered, it will
/// return `None`. The conversion uses safe methods to prevent overflow.
///
/// # Example
///
/// ```rust
/// let s = "12345";
/// let result = str_to_usize(s);
/// assert_eq!(result, Some(12345));
/// ```
///
/// # Errors
///
/// Returns `None` if the string contains any non-digit characters or if the conversion overflows.
/// Converts a non-negative `i32` to a `usize`, returning `None` if the number is negative.
///
/// This function safely converts a non-negative `i32` value to a `usize`. If the number is negative, it returns `None`.
///
/// # Example
///
/// ```rust
/// let num = 123;
/// let result = i32_to_usize(num);
/// assert_eq!(result, Some(123));
/// ```
///
/// # Errors
///
/// Returns `None` if the input number is negative.