The size for values of type `[NiteUserData]` cannot be known at compilation time

Hello, I am a beginner at rust, and recently I tried using NiTE 2.2 in my rust project, but an issue I noticed is that the compiler is unable to find the Sized trait of NiteUserData, I tried implementing it manually but the compiler returns "explicit impls for the Sized trait are not permitted impl of 'Sized' not allowed". How should I fix this issue?

fn main

fn main() {
    let mut userTracker:NiteUserTracker = unsafe {std::mem::zeroed()};
    let mut userTrackerHandle:NiteUserTrackerHandle = &mut userTracker;
    let mut niteRc:NiteStatus;

    unsafe {
        niteInitialize();
        niteRc = niteInitializeUserTracker(&mut userTrackerHandle);
    }

    if niteRc != NiteStatus_NITE_STATUS_OK {
        println!("Couldn't create user tracker");
        dbg!(niteRc);
        std::process::exit(3);
    }

    println!("Start moving around to get detected...");
    println!("(PSI pose may be required for skeleton calibration, depending on the configuration)");

    let mut userTrackerFrame:NiteUserTrackerFrame = unsafe {std::mem::zeroed()};
    while(!wasKeyboardHit()){
        niteRc = unsafe {niteReadUserTrackerFrame(userTrackerHandle, &mut userTrackerFrame as *mut NiteUserTrackerFrame as *mut *mut NiteUserTrackerFrame)};

        if niteRc != NiteStatus_NITE_STATUS_OK {
            println!("Get next frame failed");
            continue;
        }

        let users = unsafe {std::slice::from_raw_parts_mut(userTrackerFrame.pUser, userTrackerFrame.userCount as usize)}; //error here

    }

    unsafe {NiTE::niteShutdown()};
}

This might mean that the pUser field has type *mut [NiteUserData], when what you want is probably *mut NiteUserData.

Being Sized or not is a fundamental property of the type, and you can't just change it by implementing it. It sounds like you've got a type somewhere that isn't what you expect it to be, but it's unclear what exactly.

Sorry for the vagueness, *mut [NiteUserData] is the correct datatype, userTrackerFrame.pUser is a C array written in the include as a pointer. I am trying to iterate through that array.

*mut [T] is a “fat pointer” type that contains both a pointer to the slice, and its length. But slice::from_raw_parts_mut expects just a “thin” pointer to the first element (*mut T). You can use the as keyword to cast your slice pointer to a thin pointer:

let users = unsafe {
    std::slice::from_raw_parts_mut(
        userTrackerFrame.pUser as *mut NiteUserData,
        userTrackerFrame.userCount as usize)
};

However, since you have separate fields for the pointer (pUser) and length (userCount), you probably don't need to store a fat pointer, and can use a thin pointer (*mut NiteUserData) everywhere.

You would generally have either *mut [T] with no separate length field, or a *mut T with a separate length field.

I understand now, Thank you

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.