rust3ds / ctru-rs

Rust wrapper for libctru
https://rust3ds.github.io/ctru-rs/
Other
117 stars 17 forks source link

Improve the ergonomics of calling ``ctru_sys`` functions #74

Closed Techie-Pi closed 1 year ago

Techie-Pi commented 1 year ago

Right now, most calls to ctru_sys functions look like this:

let r = ctru_sys::aptInit();
if r < 0 {
    Err(r.into())
} else {
    Ok(Apt(()))
}

This PR adds the LibCtruResult struct (though the name can be changed), which implements the Try trait to allow the usage of the ? operator. The example above now looks like this:

LibCtruResult(ctru_sys::appInit())?;
Ok(Apt(()))

This makes the code much more simpler, and both do exactly the same thing as it can be seen here.

This could be implemented in a macro, but putting the i32 returned from the ctru_sys functions into a struct defined by the crate allows the future implementation of further abstractions around the raw errors provided by ctru_sys to cover cases that can't be covered right now.

CI is failing due to this cam function not being used (maybe it was meant to be public?, @SteveCookTU)

SteveCookTU commented 1 year ago

Apologies, I would have removed the cam function in the PR but there were CI issues and I guess it went through accidentally. The function is used for when both cameras are taking a picture at the same time. Since this isn't implemented yet it can removed for now (whether a small addition to this PR or a small commit by an author to the main branch).

Techie-Pi commented 1 year ago

Since this isn't implemented yet it can removed for now (whether a small addition to this PR or a small commit by an author to the main branch).

Alright, I'll remove the function then. No problem

Techie-Pi commented 1 year ago

The last commits were done to fix the CI, if this PR isn't merged I'll make them a separate PR

Techie-Pi commented 1 year ago

Hmmm CI fails to compile cargo-3ds with latest nightly

ian-h-chamberlain commented 1 year ago

Hmmm CI fails to compile cargo-3ds with latest nightly

The CI on latest nightly failing shouldn't prevent merge, it's just there as a sort of canary to tell us whether stuff works on latest nightly. I think this instance is some kind of issue with the CARGO_UNSTABLE_SPARSE_REGISTRY: "true" flag we use, maybe it got destabilized or something.