bennetthardwick / rust-obs-plugins

A safe wrapper around the OBS API, useful for creating OBS sources, filters and effects.
GNU General Public License v2.0
187 stars 32 forks source link

Question on the newly added set_default API #34

Closed yoshinorisano closed 1 year ago

yoshinorisano commented 1 year ago

Hi, I have a question on the newly added set_default API. I want to use that API for loading a string default value. But, it is very complicated for me...

I wrote code like this: https://github.com/yoshinorisano/obs-biquad-filter-plugin/commit/7d658d94a92ca3a92e2e1fc36460b9df454454f8#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R170

settings.set_default::<std::borrow::Cow<'_, str>>(obs_string!("filter_type"), std::borrow::Cow::Borrowed("low_pass"));

It works. But, it is not optimal. I want to use the following const to remove the code duplication, but I cannot find how to do that.

const DEFAULT_FILTER_TYPE: ObsString = obs_string!("low_pass");

@bennetthardwick If you have some good idea, could you please let me know...?

bennetthardwick commented 1 year ago

Hey @yoshinorisano I've added a new API for setting defaults with ObsString - let me know how you go 👍🏻

You should be able to do something like this (you might need to .clone())

settings.set_default::<ObsString>(obs_string!("filter_type"), DEFAULT_FILTER_TYPE);

https://github.com/bennetthardwick/rust-obs-plugins/blob/fd1fb6604a43b7b92f37f97fcf0f3ff1585b0cc9/src/data.rs#L87-L98

yoshinorisano commented 1 year ago

@bennetthardwick Thank you so much! I've written a test code that uses the latest API and checked it works perfectly!

bennetthardwick commented 1 year ago

Awesome, great to hear it 🙏🏻