Skip to content

Commit 49d9ad1

Browse files
committed
Implement AsRef for AsyncClient
- Makes it shorter to specify the type in some cases.
1 parent 73c4305 commit 49d9ad1

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT"
88
name = "jack"
99
readme = "README.md"
1010
repository = "https://github.com/RustAudio/rust-jack"
11-
version = "0.13.3"
11+
version = "0.13.4"
1212

1313
[dependencies]
1414
bitflags = "2"

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ Refer to the [docs.rs documentation](<https://docs.rs/jack/>) for details about
2626
the API. For more general documentation, visit <https://rustaudio.github.io/rust-jack>.
2727

2828

29+
## FAQ
30+
31+
### How do I return an `AsyncClient` with many generics?
32+
33+
This is especially useful when using `jack::contrib::ClosureProcessHandler`
34+
which may have an innaccessible type.
35+
36+
```rust
37+
// Shortest and allows access to the underlying client.
38+
fn make_client() -> impl AsRef<jack::Client> {
39+
todo!()
40+
}
41+
42+
// With extra bounds
43+
fn make_client() -> impl 'static + AsRef<jack::Client> {
44+
todo!();
45+
}
46+
47+
// For the full async client
48+
fn async_client() -> impl jack::AsyncClient<impl Any, impl Any> {
49+
todo!();
50+
}
51+
```
52+
2953
# Testing
3054

3155
Testing requires setting up a dummy server and running the tests using a single

src/client/async_client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ impl<N, P> Debug for AsyncClient<N, P> {
141141
.finish()
142142
}
143143
}
144+
145+
impl<N, P> AsRef<Client> for AsyncClient<N, P> {
146+
fn as_ref(&self) -> &Client {
147+
self.as_client()
148+
}
149+
}

0 commit comments

Comments
 (0)