Skip to content
This repository was archived by the owner on Jan 4, 2026. It is now read-only.

Commit 5de87d4

Browse files
authored
Merge pull request #3 from jamesmunns/james/type-bundle
Condense types to be associated types on the handle
2 parents 9f2673f + d48d861 commit 5de87d4

3 files changed

Lines changed: 114 additions & 202 deletions

File tree

src/prod_cons/framed.rs

Lines changed: 48 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ unsafe impl LenHeader for usize {
5151
}
5252

5353
impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> {
54-
pub fn framed_producer(&self) -> FramedProducer<&'_ Self, S, C, N> {
54+
pub fn framed_producer(&self) -> FramedProducer<&'_ Self> {
5555
FramedProducer {
5656
bbq: self.bbq_ref(),
5757
pd: PhantomData,
5858
}
5959
}
6060

61-
pub fn framed_consumer(&self) -> FramedConsumer<&'_ Self, S, C, N> {
61+
pub fn framed_consumer(&self) -> FramedConsumer<&'_ Self> {
6262
FramedConsumer {
6363
bbq: self.bbq_ref(),
6464
pd: PhantomData,
@@ -68,42 +68,36 @@ impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> {
6868

6969
#[cfg(feature = "std")]
7070
impl<S: Storage, C: Coord, N: Notifier> crate::queue::ArcBBQueue<S, C, N> {
71-
pub fn framed_producer(&self) -> FramedProducer<std::sync::Arc<BBQueue<S, C, N>>, S, C, N> {
71+
pub fn framed_producer(&self) -> FramedProducer<std::sync::Arc<BBQueue<S, C, N>>> {
7272
FramedProducer {
7373
bbq: self.0.bbq_ref(),
7474
pd: PhantomData,
7575
}
7676
}
7777

78-
pub fn framed_consumer(&self) -> FramedConsumer<std::sync::Arc<BBQueue<S, C, N>>, S, C, N> {
78+
pub fn framed_consumer(&self) -> FramedConsumer<std::sync::Arc<BBQueue<S, C, N>>> {
7979
FramedConsumer {
8080
bbq: self.0.bbq_ref(),
8181
pd: PhantomData,
8282
}
8383
}
8484
}
8585

86-
pub struct FramedProducer<Q, S, C, N, H = u16>
86+
pub struct FramedProducer<Q, H = u16>
8787
where
88-
S: Storage,
89-
C: Coord,
90-
N: Notifier,
91-
Q: BbqHandle<S, C, N>,
88+
Q: BbqHandle,
9289
H: LenHeader,
9390
{
9491
bbq: Q::Target,
95-
pd: PhantomData<(S, C, N, H)>,
92+
pd: PhantomData<H>,
9693
}
9794

98-
impl<Q, S, C, N, H> FramedProducer<Q, S, C, N, H>
95+
impl<Q, H> FramedProducer<Q, H>
9996
where
100-
S: Storage,
101-
C: Coord,
102-
N: Notifier,
103-
Q: BbqHandle<S, C, N>,
97+
Q: BbqHandle,
10498
H: LenHeader,
10599
{
106-
pub fn grant(&self, sz: H) -> Result<FramedGrantW<Q, S, C, N, H>, ()> {
100+
pub fn grant(&self, sz: H) -> Result<FramedGrantW<Q, H>, ()> {
107101
let (ptr, cap) = self.bbq.sto.ptr_len();
108102
let needed = sz.into() + core::mem::size_of::<H>();
109103

@@ -121,40 +115,32 @@ where
121115
}
122116
}
123117

124-
impl<Q, S, C, N, H> FramedProducer<Q, S, C, N, H>
118+
impl<Q, H> FramedProducer<Q, H>
125119
where
126-
S: Storage,
127-
C: Coord,
128-
N: AsyncNotifier,
129-
Q: BbqHandle<S, C, N>,
120+
Q: BbqHandle,
121+
Q::Notifier: AsyncNotifier,
130122
H: LenHeader,
131123
{
132-
pub async fn wait_grant(&self, sz: H) -> FramedGrantW<Q, S, C, N, H> {
124+
pub async fn wait_grant(&self, sz: H) -> FramedGrantW<Q, H> {
133125
self.bbq.not.wait_for_not_full(|| self.grant(sz).ok()).await
134126
}
135127
}
136128

137-
pub struct FramedConsumer<Q, S, C, N, H = u16>
129+
pub struct FramedConsumer<Q, H = u16>
138130
where
139-
S: Storage,
140-
C: Coord,
141-
N: Notifier,
142-
Q: BbqHandle<S, C, N>,
131+
Q: BbqHandle,
143132
H: LenHeader,
144133
{
145134
bbq: Q::Target,
146-
pd: PhantomData<(S, C, N, H)>,
135+
pd: PhantomData<H>,
147136
}
148137

149-
impl<Q, S, C, N, H> FramedConsumer<Q, S, C, N, H>
138+
impl<Q, H> FramedConsumer<Q, H>
150139
where
151-
S: Storage,
152-
C: Coord,
153-
N: Notifier,
154-
Q: BbqHandle<S, C, N>,
140+
Q: BbqHandle,
155141
H: LenHeader,
156142
{
157-
pub fn read(&self) -> Result<FramedGrantR<Q, S, C, N, H>, ()> {
143+
pub fn read(&self) -> Result<FramedGrantR<Q, H>, ()> {
158144
let (ptr, _cap) = self.bbq.sto.ptr_len();
159145
let (offset, grant_len) = self.bbq.cor.read()?;
160146

@@ -197,50 +183,39 @@ where
197183
}
198184
}
199185

200-
impl<Q, S, C, N, H> FramedConsumer<Q, S, C, N, H>
186+
impl<Q, H> FramedConsumer<Q, H>
201187
where
202-
S: Storage,
203-
C: Coord,
204-
N: AsyncNotifier,
205-
Q: BbqHandle<S, C, N>,
188+
Q: BbqHandle,
189+
Q::Notifier: AsyncNotifier,
206190
H: LenHeader,
207191
{
208-
pub async fn wait_read(&self) -> FramedGrantR<Q, S, C, N, H> {
192+
pub async fn wait_read(&self) -> FramedGrantR<Q, H> {
209193
self.bbq.not.wait_for_not_empty(|| self.read().ok()).await
210194
}
211195
}
212196

213-
pub struct FramedGrantW<Q, S, C, N, H = u16>
197+
pub struct FramedGrantW<Q, H = u16>
214198
where
215-
S: Storage,
216-
C: Coord,
217-
N: Notifier,
218-
Q: BbqHandle<S, C, N>,
199+
Q: BbqHandle,
219200
H: LenHeader,
220201
{
221202
bbq: Q::Target,
222203
base_ptr: NonNull<u8>,
223204
hdr: H,
224205
}
225206

226-
unsafe impl<Q, S, C, N, H> Send for FramedGrantW<Q, S, C, N, H>
207+
unsafe impl<Q, H> Send for FramedGrantW<Q, H>
227208
where
228-
S: Storage,
229-
C: Coord,
230-
N: Notifier,
231-
Q: BbqHandle<S, C, N>,
209+
Q: BbqHandle,
232210
Q::Target: Send,
233211
H: LenHeader + Send
234212
{
235213

236214
}
237215

238-
impl<Q, S, C, N, H> Deref for FramedGrantW<Q, S, C, N, H>
216+
impl<Q, H> Deref for FramedGrantW<Q, H>
239217
where
240-
S: Storage,
241-
C: Coord,
242-
N: Notifier,
243-
Q: BbqHandle<S, C, N>,
218+
Q: BbqHandle,
244219
H: LenHeader,
245220
{
246221
type Target = [u8];
@@ -255,12 +230,9 @@ where
255230
}
256231
}
257232

258-
impl<Q, S, C, N, H> DerefMut for FramedGrantW<Q, S, C, N, H>
233+
impl<Q, H> DerefMut for FramedGrantW<Q, H>
259234
where
260-
S: Storage,
261-
C: Coord,
262-
N: Notifier,
263-
Q: BbqHandle<S, C, N>,
235+
Q: BbqHandle,
264236
H: LenHeader,
265237
{
266238
fn deref_mut(&mut self) -> &mut Self::Target {
@@ -273,12 +245,9 @@ where
273245
}
274246
}
275247

276-
impl<Q, S, C, N, H> Drop for FramedGrantW<Q, S, C, N, H>
248+
impl<Q, H> Drop for FramedGrantW<Q, H>
277249
where
278-
S: Storage,
279-
C: Coord,
280-
N: Notifier,
281-
Q: BbqHandle<S, C, N>,
250+
Q: BbqHandle,
282251
H: LenHeader,
283252
{
284253
fn drop(&mut self) {
@@ -290,12 +259,9 @@ where
290259
}
291260
}
292261

293-
impl<Q, S, C, N, H> FramedGrantW<Q, S, C, N, H>
262+
impl<Q, H> FramedGrantW<Q, H>
294263
where
295-
S: Storage,
296-
C: Coord,
297-
N: Notifier,
298-
Q: BbqHandle<S, C, N>,
264+
Q: BbqHandle,
299265
H: LenHeader,
300266
{
301267
pub fn commit(self, used: H) {
@@ -323,37 +289,28 @@ where
323289
}
324290
}
325291

326-
pub struct FramedGrantR<Q, S, C, N, H = u16>
292+
pub struct FramedGrantR<Q, H = u16>
327293
where
328-
S: Storage,
329-
C: Coord,
330-
N: Notifier,
331-
Q: BbqHandle<S, C, N>,
294+
Q: BbqHandle,
332295
H: LenHeader,
333296
{
334297
bbq: Q::Target,
335298
body_ptr: NonNull<u8>,
336299
hdr: H,
337300
}
338301

339-
unsafe impl<Q, S, C, N, H> Send for FramedGrantR<Q, S, C, N, H>
302+
unsafe impl<Q, H> Send for FramedGrantR<Q, H>
340303
where
341-
S: Storage,
342-
C: Coord,
343-
N: Notifier,
344-
Q: BbqHandle<S, C, N>,
304+
Q: BbqHandle,
345305
Q::Target: Send,
346306
H: LenHeader + Send
347307
{
348308

349309
}
350310

351-
impl<Q, S, C, N, H> Deref for FramedGrantR<Q, S, C, N, H>
311+
impl<Q, H> Deref for FramedGrantR<Q, H>
352312
where
353-
S: Storage,
354-
C: Coord,
355-
N: Notifier,
356-
Q: BbqHandle<S, C, N>,
313+
Q: BbqHandle,
357314
H: LenHeader,
358315
{
359316
type Target = [u8];
@@ -364,12 +321,9 @@ where
364321
}
365322
}
366323

367-
impl<Q, S, C, N, H> DerefMut for FramedGrantR<Q, S, C, N, H>
324+
impl<Q, H> DerefMut for FramedGrantR<Q, H>
368325
where
369-
S: Storage,
370-
C: Coord,
371-
N: Notifier,
372-
Q: BbqHandle<S, C, N>,
326+
Q: BbqHandle,
373327
H: LenHeader,
374328
{
375329
fn deref_mut(&mut self) -> &mut Self::Target {
@@ -378,12 +332,9 @@ where
378332
}
379333
}
380334

381-
impl<Q, S, C, N, H> Drop for FramedGrantR<Q, S, C, N, H>
335+
impl<Q, H> Drop for FramedGrantR<Q, H>
382336
where
383-
S: Storage,
384-
C: Coord,
385-
N: Notifier,
386-
Q: BbqHandle<S, C, N>,
337+
Q: BbqHandle,
387338
H: LenHeader,
388339
{
389340
fn drop(&mut self) {
@@ -392,12 +343,9 @@ where
392343
}
393344
}
394345

395-
impl<Q, S, C, N, H> FramedGrantR<Q, S, C, N, H>
346+
impl<Q, H> FramedGrantR<Q, H>
396347
where
397-
S: Storage,
398-
C: Coord,
399-
N: Notifier,
400-
Q: BbqHandle<S, C, N>,
348+
Q: BbqHandle,
401349
H: LenHeader,
402350
{
403351
pub fn release(self) {

0 commit comments

Comments
 (0)