Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Update From trait implementation for the RawNtpPacket #34

Open
vpetrigo opened this issue Dec 8, 2024 · 0 comments
Open

[FEATURE] Update From trait implementation for the RawNtpPacket #34

vpetrigo opened this issue Dec 8, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@vpetrigo
Copy link
Owner

vpetrigo commented Dec 8, 2024

Is your feature request related to a problem? Please describe.
Currently there is two lambdas that converts u32 and u64 into an array:

    fn from(val: RawNtpPacket) -> Self {
        // left it here for a while, maybe in future Rust releases there
        // will be a way to use such a generic function with compile-time
        // size determination
        // const fn to_array<T: Sized>(x: &[u8]) -> [u8; mem::size_of::<T>()] {
        //     let mut temp_buf = [0u8; mem::size_of::<T>()];
        //
        //     temp_buf.copy_from_slice(x);
        //     temp_buf
        // }
        let to_array_u32 = |x: &[u8]| {
            let mut temp_buf = [0u8; mem::size_of::<u32>()];
            temp_buf.copy_from_slice(x);
            temp_buf
        };
        let to_array_u64 = |x: &[u8]| {
            let mut temp_buf = [0u8; mem::size_of::<u64>()];
            temp_buf.copy_from_slice(x);
            temp_buf
        };

Describe the solution you'd like
When this rust-lang/rust#43408 would be resolved let's update the implementation with generic size_of::<T>() usage.

Describe alternatives you've considered
N/A

Additional context
N/A

@vpetrigo vpetrigo added the enhancement New feature or request label Dec 8, 2024
@vpetrigo vpetrigo self-assigned this Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant