You'd use them on the function signature itself, rather than the parameter.

On Sat, Dec 23, 2017 at 1:47 PM, Enrico Weigelt, metux IT consult via
dev-servo <dev-servo@lists.mozilla.org> wrote:
> Hi folks,
>
> while trying to make some features optional (eg. bluetooth, vr, ...)
> I've seen several of the types I'd like to get rid of in new() calls.
> Rust doesn't seem to support #[cfg()] on function parameters. OTOH,
> this works on struct fields.
>
> Just using Option<> here doesn't help as I'd like to completely get
> rid of everything from the disabled features.
>
> Therefore I propose using structs as parameters, where fields certain
> fields are only available when certain features are enabled.
>
> For example in window.rs:
>
>> pub struct Window_Param {
>>     #[cfg(feature = "webapi-bluetooth")]
>>     bluetooth_thread: IpcSender<BluetoothRequest>,
>>     #[cfg(feature = "webapi-webgl")]
>>     webgl_chan: WebGLChan,
>>     #[cfg(feature = "webapi-webvr")]
>>     webvr_chan: Option<IpcSender<WebVRMsg>>,
>>     ...
>> }
>
> Window::new() would now have an additional Window_Param parameter
> instead of the explicit parameters for bluetooth_thread, webgl_chan,
> webvr_chan, ...
>
> Maybe we could also move some feature-dependent logic (that operate
> on these fields) there, to reduce the amount of #[cfg...] places.
>
>
> What's you oppinion on that ?
>
>
> --mtx
>
> --
> Enrico Weigelt, metux IT consult
> Free software and Linux embedded engineering
> i...@metux.net -- +49-151-27565287
> _______________________________________________
> dev-servo mailing list
> dev-servo@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-servo
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo

Reply via email to