1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Link components
16 use pyo3::{intern, types::PyModule, PyObject, PyResult, Python, ToPyObject};
17 
18 /// Link bus for controllers to communicate with each other
19 #[derive(Clone)]
20 pub struct Link(pub(crate) PyObject);
21 
22 impl Link {
23     /// Creates a [Link] object that transports messages locally
new_local_link() -> PyResult<Self>24     pub fn new_local_link() -> PyResult<Self> {
25         Python::with_gil(|py| {
26             PyModule::import(py, intern!(py, "bumble.link"))?
27                 .getattr(intern!(py, "LocalLink"))?
28                 .call0()
29                 .map(|any| Self(any.into()))
30         })
31     }
32 }
33 
34 impl ToPyObject for Link {
to_object(&self, _py: Python<'_>) -> PyObject35     fn to_object(&self, _py: Python<'_>) -> PyObject {
36         self.0.clone()
37     }
38 }
39