From 4fe665fc8bc6265baf5bfba6b6a5f3ee2dba63dc Mon Sep 17 00:00:00 2001 From: hozan23 Date: Wed, 8 Nov 2023 13:03:27 +0300 Subject: first commit --- karyons_core/src/utils/decode.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 karyons_core/src/utils/decode.rs (limited to 'karyons_core/src/utils/decode.rs') diff --git a/karyons_core/src/utils/decode.rs b/karyons_core/src/utils/decode.rs new file mode 100644 index 0000000..a8a6522 --- /dev/null +++ b/karyons_core/src/utils/decode.rs @@ -0,0 +1,10 @@ +use bincode::Decode; + +use crate::Result; + +/// Decodes a given type `T` from the given slice. returns the decoded value +/// along with the number of bytes read. +pub fn decode(src: &[u8]) -> Result<(T, usize)> { + let (result, bytes_read) = bincode::decode_from_slice(src, bincode::config::standard())?; + Ok((result, bytes_read)) +} -- cgit v1.2.3