diff --git a/.github/workflows/rust-codestyle.yml b/.github/workflows/rust-codestyle.yml index bcfa721a..1f79c546 100644 --- a/.github/workflows/rust-codestyle.yml +++ b/.github/workflows/rust-codestyle.yml @@ -44,6 +44,10 @@ jobs: toolchain: stable override: true + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust + - name: Run clippy run: cargo clippy -- -D warnings working-directory: binding/rust @@ -85,6 +89,10 @@ jobs: profile: minimal toolchain: stable override: true + + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust - name: Run clippy run: cargo clippy -- -D warnings diff --git a/.github/workflows/rust-demos.yml b/.github/workflows/rust-demos.yml index f783001f..8d83500a 100644 --- a/.github/workflows/rust-demos.yml +++ b/.github/workflows/rust-demos.yml @@ -50,6 +50,10 @@ jobs: profile: minimal toolchain: stable override: true + + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust - name: Rust build micdemo run: cargo build --verbose @@ -89,6 +93,10 @@ jobs: with: toolchain: nightly override: true + + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust - name: Rust build micdemo run: cargo build --verbose diff --git a/binding/rust/src/rhino.rs b/binding/rust/src/rhino.rs index b90daec4..5954c568 100644 --- a/binding/rust/src/rhino.rs +++ b/binding/rust/src/rhino.rs @@ -27,7 +27,11 @@ use libloading::os::unix::Symbol as RawSymbol; use libloading::os::windows::Symbol as RawSymbol; #[repr(C)] -struct CRhino {} +struct CRhino { + // Fields suggested by the Rustonomicon: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} #[repr(C)] #[derive(PartialEq, Clone, Debug)] @@ -87,6 +91,7 @@ type PvGetErrorStackFn = type PvFreeErrorStackFn = unsafe extern "C" fn(message_stack: *mut *mut c_char); type PvSetSdkFn = unsafe extern "C" fn(sdk: *const c_char); + #[derive(PartialEq, Clone, Debug)] pub enum RhinoErrorStatus { LibraryError(PvStatus), @@ -129,16 +134,13 @@ impl std::fmt::Display for RhinoError { let mut message_string = String::new(); message_string.push_str(&format!("{} with status '{:?}'", self.message, self.status)); - if self.message_stack.len() == 0 { - message_string.push_str("."); - write!(f, "{}", message_string) - } else { - message_string.push_str(":"); + if !self.message_stack.is_empty() { + message_string.push(':'); for x in 0..self.message_stack.len() { message_string.push_str(&format!(" [{}] {}\n", x, self.message_stack[x])) - } - write!(f, "{}", message_string) + }; } + write!(f, "{}", message_string) } } diff --git a/demo/rust/filedemo/Cargo.lock b/demo/rust/filedemo/Cargo.lock index 12c7fc65..01526a17 100644 --- a/demo/rust/filedemo/Cargo.lock +++ b/demo/rust/filedemo/Cargo.lock @@ -306,9 +306,7 @@ dependencies = [ [[package]] name = "pv_rhino" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83df0b253a4ee96e3428394f2f7a4769505c7e0bd91e1b4379141a289494c53" +version = "3.0.0" dependencies = [ "libc", "libloading", diff --git a/demo/rust/filedemo/Cargo.toml b/demo/rust/filedemo/Cargo.toml index 09246c61..d54470e6 100644 --- a/demo/rust/filedemo/Cargo.toml +++ b/demo/rust/filedemo/Cargo.toml @@ -8,4 +8,4 @@ chrono = "0.4.23" clap = "3.2.3" hound = "3.4.0" itertools = "0.10.3" -pv_rhino = "=2.2.1" +pv_rhino = { path = "../../../binding/rust" } diff --git a/demo/rust/micdemo/Cargo.lock b/demo/rust/micdemo/Cargo.lock index 3535b42e..3780fa93 100644 --- a/demo/rust/micdemo/Cargo.lock +++ b/demo/rust/micdemo/Cargo.lock @@ -277,9 +277,7 @@ dependencies = [ [[package]] name = "pv_rhino" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83df0b253a4ee96e3428394f2f7a4769505c7e0bd91e1b4379141a289494c53" +version = "3.0.0" dependencies = [ "libc", "libloading 0.7.4", diff --git a/demo/rust/micdemo/Cargo.toml b/demo/rust/micdemo/Cargo.toml index 54b91a70..2f55e1c4 100644 --- a/demo/rust/micdemo/Cargo.toml +++ b/demo/rust/micdemo/Cargo.toml @@ -10,4 +10,4 @@ ctrlc = "3.2.2" hound = "3.4.0" itertools = "0.10.3" pv_recorder = "=1.2.1" -pv_rhino = "=2.2.1" +pv_rhino = { path = "../../../binding/rust" } diff --git a/resources/.lint/spell-check/dict.txt b/resources/.lint/spell-check/dict.txt index e207a36b..4931cd80 100644 --- a/resources/.lint/spell-check/dict.txt +++ b/resources/.lint/spell-check/dict.txt @@ -106,6 +106,7 @@ rhinomicdemo rhinotestapp rodio rosado +Rustonomicon RTLD seumateu shōmei