The init functions are actually a bit special, because they can't be
turned into static methods on the new trait without running into compile
errors. I recommend doing this instead:
trait BluetoothAdapter {
// ...
}
impl BluetoothAdapter {
#[cfg(all(target_os = "macos", feature = "bluetooth"))]
pub fn new() -> Result<Box<BluetoothAdapter>, Box<Error>> {
// ...
}
#[cfg(all(target_os = "linux", feature = "bluetooth"))]
pub fn new() -> Result<Box<BluetoothAdapter>, Box<Error>> {
// ...
}
}
This will allow callers to use `BluetoothAdapter::new()` to create a new
instance.
Cheers,
Josh
On 3/30/19 11:40 AM, Niveditha Shankar wrote:
Thank you!
We meant to ask if code in
https://github.com/servo/devices/blob/d6c62e0873b2ec9a68c97a3370667e8b9a879cf4/src/bluetooth.rs#L276-L305
should
be split and the functions corresponding to say linux should be put in the
structure we created for implementing BluetoothAdapter for linux.
Sincerely
Niveditha Shankar
On Sat, Mar 30, 2019 at 12:26 AM Josh Bowman-Matthews <j...@joshmatthews.net>
wrote:
That sounds like the right idea. I'm not quite sure what this question
is asking, however:
> Are we right in assuming that the current BluetoothAdapter function
has to
> be broken for each component and put in the respective structure?
If you are asking if code like
https://github.com/servo/devices/blob/d6c62e0873b2ec9a68c97a3370667e8b9a879cf4/src/bluetooth.rs#L276-L305
should be distributed across the various trait implementations, then the
answer is yes.
Cheers,
Josh
On 3/28/19 8:23 PM, Sruthi Kannan wrote:
Hello,
I am a NC state graduate student working in the Refactoring Bluetooth
support project with Niveditha.
We went went through the documentation on traits. We arrived at the
following approach and we just want to make sure we are doing it right.
1) Create an adapter.rs file. Define a trait object using a vector.
Create
a structure, say DeviceType for the same.
2) Create individual structures for each component(like Android,Mac..)
and
implement BluetoothAdapter function in each.
3) Make changes in the servo crate to call adapter.rs
Are we right in assuming that the current BluetoothAdapter function has
to
be broken for each component and put in the respective structure?
Thank you.
_______________________________________________
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