#Struggling with partially moved variables

10 messages · Page 1 of 1 (latest)

sweet sand
#

-errors ferrisPlead

brave marshBOT
#

If you're getting large or confusing errors please post the full error message from cargo check in a code block instead of the errors in your IDE so that we can understand your problem better:

```rust
// error from cargo check here
```

coarse cairn
sweet sand
#

do you need the ownership of any of the variables?

#

any of the mode, multicast, join, version

coarse cairn
#

I think I do? I got it working eventually like so:

async fn start_software(
        &self,
        request: Request<StartSoftwareReq>,
    ) -> Result<Response<CommonResponse>, Status> {
        let request_data = request.into_inner();

        // Note: gRPC wants all of the fields defined!
        // If the field is 'oneof' or 'optional' it won't be required as it's defined as Option<T>
        match request_data.software {
            Some(styx::start_software_req::Software::Vbs(r)) => {
                let styx::Vbs { mode, multicast, join, version, .. } = &r;

                // Get .exe name from the version parameter of the gRPC call.
                // Versions are defined in styx.proto
                let module = match version.as_ref() {
                    "VBS183" => "VBS3_64", // VBS3 version 18.3
                    "VBS390" => "VBS3_64", // VBS3 version 3.9.0 FDF
                    "VBS221" => "VBS4", // VBS4 version 22.1
                    _ => "Default"
                };

                match get_path_from_regkey(&styx::start_software_req::Software::Vbs(r.clone())) {
// Rest of the function
#

I am relatively new to Rust and still struggling with ownership but this compiles and works fine, even though it's probably spaghetti

sweet sand
#

as with it all the variables are references