inflation / vapoursynth4-rs

A safe wrapper for Vapoursynth v4 API
6 stars 2 forks source link

refactor: simplify maps to just `Map` and `MapRef` #10

Closed sgt0 closed 1 week ago

sgt0 commented 2 weeks ago

I wanted to use Plugin.invoke() to call another plugin, but found that it required a MapRef<'_> and there wasn't an ergonomic way to dereference a Map into a MapRef. The only way I saw to get a MapRef was to do:

let mut args = Map::new();
// [set args]
let args_ref = NonNull::new(args.as_mut_ptr()).map(MapRef::new).unwrap();
plugin.invoke(cstr!("Filter"), args_ref);

To make this easier, I refactored Map, MapMut, and MapRef into just Map and MapRef, with implementations for AsRef, Borrow, Deref, etc. The same general pattern is still here, with one type being an owned map and the other being a borrowed one, but there's one less type now and no explicit lifetimes. Methods that did not require ownership of the map have been moved to MapRef.

Now the above code can be written as:

let mut args = Map::new();
// [set args]
plugin.invoke(cstr!("Filter"), &args);

Also added a second sample filter to the sample plugin to demonstrate it.

codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 35.86207% with 93 lines in your changes missing coverage. Please review.

Project coverage is 27.20%. Comparing base (7c1b3b8) to head (74c26f9). Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
sample-plugin/src/dither.rs 0.00% 74 Missing :warning:
vapoursynth4-rs/src/map.rs 89.65% 6 Missing :warning:
vapoursynth4-rs/src/core.rs 0.00% 4 Missing :warning:
vapoursynth4-rs/src/frame.rs 0.00% 4 Missing :warning:
sample-plugin/src/lib.rs 0.00% 2 Missing :warning:
vapoursynth4-rs/src/plugin.rs 0.00% 2 Missing :warning:
vapoursynth4-rs/src/node/internal.rs 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #10 +/- ## ========================================== + Coverage 26.01% 27.20% +1.18% ========================================== Files 18 19 +1 Lines 1526 1599 +73 ========================================== + Hits 397 435 +38 - Misses 1129 1164 +35 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.