Comments (3)
This would be a good extension to the API.
It would also make sense to provide a wrapper function around CharacteristicWriteMethod::Fun
and similar types that perform the boxing of the specified closure, i.e. Box::new(move |...| { async move { ... }.boxed() })
.
I'd start out with the inner ones (e.g.: Characteristic::builder) and progressively add the higher one.
Yes, we can then discuss the proposed builder pattern in more detail.
from bluer.
It would also make sense to provide a wrapper function around CharacteristicWriteMethod::Fun and similar types that perform the boxing of the specified closure, i.e. Box::new(move |...| { async move { ... }.boxed() }).
Yeah, that's also kind ugly and repetitive. Ideally, the following:
CharacteristicWriteMethod::Fun(Box::new(move |new_value, req| {
async move {
todo!("{:?} {:?}", new_value, req);
}
.boxed()
})),
Could be written as:
CharacteristicWriteMethod::from(async move {
todo!("{:?} {:?}", new_value, req);
}),
However, async closures are unstable: rust-lang/rust#62290.
I used bluer/examples/gatt_server_cb.rs
for some experimenting around simplifying this bit anyway. I ended up hitting lifetime issues that come up due to the async block moving variables into its scope.
I'm not sure that there's anything actionable on simplifying CharacteristicWriteMethod
definition.
from bluer.
You don't need async closures for that. You can create a wrapper function like this:
use futures::future::FutureExt;
use std::future::Future;
use std::io::Result;
use std::pin::Pin; // 0.3.30
pub type CharacteristicWriteFun =
Box<dyn Fn(Vec<u8>, String) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> + Send + Sync>;
pub enum CharacteristicWriteMethod {
Fun(CharacteristicWriteFun),
Io,
}
impl CharacteristicWriteMethod {
pub fn fun<Fut>(f: impl Fn(Vec<u8>, String) -> Fut + Send + Sync + 'static) -> Self
where
Fut: Future<Output = Result<()>> + Send + 'static,
{
Self::Fun(Box::new(move |a, b| f(a, b).boxed()))
}
}
fn main() {
CharacteristicWriteMethod::fun(|a, b| async move { Ok(()) });
}
from bluer.
Related Issues (20)
- BlueZ version is not verified to be compatible HOT 5
- `connect_device` fails with D-Bus error UnknownMethod HOT 1
- agent doesn't work? HOT 2
- Can't get monitor HOT 21
- Is setting the L2CAP LE LL PDU possible? If so, how would this be done in BlueR? HOT 15
- Can setting the connection interval parameter be added? HOT 10
- Get paired/connected devices
- Peer to Peer communication HOT 1
- le_passive_scan example not working HOT 1
- Add ability to save LE Advertising Reports with bluer-tools HOT 6
- Pairing fail due to missing key distribution
- License HOT 4
- Build failure due to git clone without submodules HOT 1
- gatt_echo example: does not work HOT 6
- next release ?
- Minimal RFCOMM client example
- Unexpected Pairing Request Dialog When Connecting to GATT Server with BlueR HOT 7
- Add a command line tool for device advertising HOT 9
- advertising max/min interval being ignored HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bluer.