summaryrefslogtreecommitdiff
path: root/libnres/src/converter.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2023-09-17 01:45:17 +0300
committerValentin Popov <valentin@popov.link>2023-09-17 01:45:17 +0300
commit0c095125de8840d09cc825dfc241b3e4d3617335 (patch)
treece58f9bc906b08cc094b3d36f9727d6959a76233 /libnres/src/converter.rs
parent4e195ec38657605657dcbcc5b76581cbf5b8c404 (diff)
downloadfparkan-0c095125de8840d09cc825dfc241b3e4d3617335.tar.xz
fparkan-0c095125de8840d09cc825dfc241b3e4d3617335.zip
Перенос старых наработок в новый репозиторий
Diffstat (limited to 'libnres/src/converter.rs')
-rw-r--r--libnres/src/converter.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/libnres/src/converter.rs b/libnres/src/converter.rs
new file mode 100644
index 0000000..bbf0535
--- /dev/null
+++ b/libnres/src/converter.rs
@@ -0,0 +1,33 @@
+use crate::error::ConverterError;
+
+/// Method for converting u32 to u64.
+pub fn u32_to_u64(value: u32) -> Result<u64, ConverterError> {
+ match u64::try_from(value) {
+ Err(error) => Err(ConverterError::Infallible(error)),
+ Ok(result) => Ok(result),
+ }
+}
+
+/// Method for converting u32 to usize.
+pub fn u32_to_usize(value: u32) -> Result<usize, ConverterError> {
+ match usize::try_from(value) {
+ Err(error) => Err(ConverterError::TryFromIntError(error)),
+ Ok(result) => Ok(result),
+ }
+}
+
+/// Method for converting u64 to u32.
+pub fn u64_to_u32(value: u64) -> Result<u32, ConverterError> {
+ match u32::try_from(value) {
+ Err(error) => Err(ConverterError::TryFromIntError(error)),
+ Ok(result) => Ok(result),
+ }
+}
+
+/// Method for converting usize to u32.
+pub fn usize_to_u32(value: usize) -> Result<u32, ConverterError> {
+ match u32::try_from(value) {
+ Err(error) => Err(ConverterError::TryFromIntError(error)),
+ Ok(result) => Ok(result),
+ }
+}