diff options
| author | Valentin Popov <valentin@popov.link> | 2025-06-15 01:42:55 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-15 01:42:55 +0300 |
| commit | 2273fd4263b91a877b043dacf4b9311c98d3bcbb (patch) | |
| tree | e2502636adc081c2a71179402774fa90d5be8a9d /libs/nres/src/converter.rs | |
| parent | d4f104cf5ebca5acf4379e5108c635e008c0c82f (diff) | |
| parent | d274602104892e181205725c6b9c9082a9669942 (diff) | |
| download | fparkan-2273fd4263b91a877b043dacf4b9311c98d3bcbb.tar.xz fparkan-2273fd4263b91a877b043dacf4b9311c98d3bcbb.zip | |
Merge pull request #7 from valentineus/nres
Обновление структуры проекта
Diffstat (limited to 'libs/nres/src/converter.rs')
| -rw-r--r-- | libs/nres/src/converter.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libs/nres/src/converter.rs b/libs/nres/src/converter.rs new file mode 100644 index 0000000..bbf0535 --- /dev/null +++ b/libs/nres/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), + } +} |
