@@ -226,7 +226,7 @@ impl Type {
226
226
/// This checks whether the argument `other` has attributes which are present
227
227
/// in the given `Type`. This returns `true` on same arguments
228
228
/// `a.is_subtype(a)` is `true`.
229
- pub fn is_subtype ( & self , other : Self ) -> bool {
229
+ pub const fn is_subtype ( & self , other : Self ) -> bool {
230
230
self . corr . is_subtype ( other. corr ) && self . mall . is_subtype ( other. mall )
231
231
}
232
232
@@ -261,142 +261,209 @@ impl Type {
261
261
pub const fn time ( ) -> Self { Type { corr : Correctness :: time ( ) , mall : Malleability :: time ( ) } }
262
262
263
263
/// Constructor for the type of the `a:` fragment.
264
- pub fn cast_alt ( self ) -> Result < Self , ErrorKind > {
264
+ pub const fn cast_alt ( self ) -> Result < Self , ErrorKind > {
265
+ // FIXME need to do manual `?` because ? is not supported in constfns.
265
266
Ok ( Type {
266
- corr : Correctness :: cast_alt ( self . corr ) ?,
267
+ corr : match Correctness :: cast_alt ( self . corr ) {
268
+ Ok ( x) => x,
269
+ Err ( e) => return Err ( e) ,
270
+ } ,
267
271
mall : Malleability :: cast_alt ( self . mall ) ,
268
272
} )
269
273
}
270
274
271
275
/// Constructor for the type of the `s:` fragment.
272
- pub fn cast_swap ( self ) -> Result < Self , ErrorKind > {
276
+ pub const fn cast_swap ( self ) -> Result < Self , ErrorKind > {
277
+ // FIXME need to do manual `?` because ? is not supported in constfns.
273
278
Ok ( Type {
274
- corr : Correctness :: cast_swap ( self . corr ) ?,
279
+ corr : match Correctness :: cast_swap ( self . corr ) {
280
+ Ok ( x) => x,
281
+ Err ( e) => return Err ( e) ,
282
+ } ,
275
283
mall : Malleability :: cast_swap ( self . mall ) ,
276
284
} )
277
285
}
278
286
279
287
/// Constructor for the type of the `c:` fragment.
280
- pub fn cast_check ( self ) -> Result < Self , ErrorKind > {
288
+ pub const fn cast_check ( self ) -> Result < Self , ErrorKind > {
281
289
Ok ( Type {
282
- corr : Correctness :: cast_check ( self . corr ) ?,
290
+ corr : match Correctness :: cast_check ( self . corr ) {
291
+ Ok ( x) => x,
292
+ Err ( e) => return Err ( e) ,
293
+ } ,
283
294
mall : Malleability :: cast_check ( self . mall ) ,
284
295
} )
285
296
}
286
297
287
298
/// Constructor for the type of the `d:` fragment.
288
- pub fn cast_dupif ( self ) -> Result < Self , ErrorKind > {
299
+ pub const fn cast_dupif ( self ) -> Result < Self , ErrorKind > {
300
+ // FIXME need to do manual `?` because ? is not supported in constfns.
289
301
Ok ( Type {
290
- corr : Correctness :: cast_dupif ( self . corr ) ?,
302
+ corr : match Correctness :: cast_dupif ( self . corr ) {
303
+ Ok ( x) => x,
304
+ Err ( e) => return Err ( e) ,
305
+ } ,
291
306
mall : Malleability :: cast_dupif ( self . mall ) ,
292
307
} )
293
308
}
294
309
295
310
/// Constructor for the type of the `v:` fragment.
296
- pub fn cast_verify ( self ) -> Result < Self , ErrorKind > {
311
+ pub const fn cast_verify ( self ) -> Result < Self , ErrorKind > {
312
+ // FIXME need to do manual `?` because ? is not supported in constfns.
297
313
Ok ( Type {
298
- corr : Correctness :: cast_verify ( self . corr ) ?,
314
+ corr : match Correctness :: cast_verify ( self . corr ) {
315
+ Ok ( x) => x,
316
+ Err ( e) => return Err ( e) ,
317
+ } ,
299
318
mall : Malleability :: cast_verify ( self . mall ) ,
300
319
} )
301
320
}
302
321
303
322
/// Constructor for the type of the `j:` fragment.
304
- pub fn cast_nonzero ( self ) -> Result < Self , ErrorKind > {
323
+ pub const fn cast_nonzero ( self ) -> Result < Self , ErrorKind > {
324
+ // FIXME need to do manual `?` because ? is not supported in constfns.
305
325
Ok ( Type {
306
- corr : Correctness :: cast_nonzero ( self . corr ) ?,
326
+ corr : match Correctness :: cast_nonzero ( self . corr ) {
327
+ Ok ( x) => x,
328
+ Err ( e) => return Err ( e) ,
329
+ } ,
307
330
mall : Malleability :: cast_nonzero ( self . mall ) ,
308
331
} )
309
332
}
310
333
311
334
/// Constructor for the type of the `n:` fragment.
312
- pub fn cast_zeronotequal ( self ) -> Result < Self , ErrorKind > {
335
+ pub const fn cast_zeronotequal ( self ) -> Result < Self , ErrorKind > {
336
+ // FIXME need to do manual `?` because ? is not supported in constfns.
313
337
Ok ( Type {
314
- corr : Correctness :: cast_zeronotequal ( self . corr ) ?,
338
+ corr : match Correctness :: cast_zeronotequal ( self . corr ) {
339
+ Ok ( x) => x,
340
+ Err ( e) => return Err ( e) ,
341
+ } ,
315
342
mall : Malleability :: cast_zeronotequal ( self . mall ) ,
316
343
} )
317
344
}
318
345
319
346
/// Constructor for the type of the `t:` fragment.
320
- pub fn cast_true ( self ) -> Result < Self , ErrorKind > {
347
+ pub const fn cast_true ( self ) -> Result < Self , ErrorKind > {
348
+ // FIXME need to do manual `?` because ? is not supported in constfns.
321
349
Ok ( Type {
322
- corr : Correctness :: cast_true ( self . corr ) ?,
350
+ corr : match Correctness :: cast_true ( self . corr ) {
351
+ Ok ( x) => x,
352
+ Err ( e) => return Err ( e) ,
353
+ } ,
323
354
mall : Malleability :: cast_true ( self . mall ) ,
324
355
} )
325
356
}
326
357
327
358
/// Constructor for the type of the `u:` fragment.
328
- pub fn cast_unlikely ( self ) -> Result < Self , ErrorKind > {
359
+ pub const fn cast_unlikely ( self ) -> Result < Self , ErrorKind > {
360
+ // FIXME need to do manual `?` because ? is not supported in constfns.
329
361
Ok ( Type {
330
- corr : Correctness :: cast_or_i_false ( self . corr ) ?,
362
+ corr : match Correctness :: cast_or_i_false ( self . corr ) {
363
+ Ok ( x) => x,
364
+ Err ( e) => return Err ( e) ,
365
+ } ,
331
366
mall : Malleability :: cast_or_i_false ( self . mall ) ,
332
367
} )
333
368
}
334
369
335
370
/// Constructor for the type of the `l:` fragment.
336
- pub fn cast_likely ( self ) -> Result < Self , ErrorKind > {
371
+ pub const fn cast_likely ( self ) -> Result < Self , ErrorKind > {
372
+ // FIXME need to do manual `?` because ? is not supported in constfns.
337
373
Ok ( Type {
338
- corr : Correctness :: cast_or_i_false ( self . corr ) ?,
374
+ corr : match Correctness :: cast_or_i_false ( self . corr ) {
375
+ Ok ( x) => x,
376
+ Err ( e) => return Err ( e) ,
377
+ } ,
339
378
mall : Malleability :: cast_or_i_false ( self . mall ) ,
340
379
} )
341
380
}
342
381
343
382
/// Constructor for the type of the `and_b` fragment.
344
- pub fn and_b ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
383
+ pub const fn and_b ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
384
+ // FIXME need to do manual `?` because ? is not supported in constfns.
345
385
Ok ( Type {
346
- corr : Correctness :: and_b ( left. corr , right. corr ) ?,
386
+ corr : match Correctness :: and_b ( left. corr , right. corr ) {
387
+ Ok ( x) => x,
388
+ Err ( e) => return Err ( e) ,
389
+ } ,
347
390
mall : Malleability :: and_b ( left. mall , right. mall ) ,
348
391
} )
349
392
}
350
393
351
394
/// Constructor for the type of the `and_v` fragment.
352
- pub fn and_v ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
395
+ pub const fn and_v ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
396
+ // FIXME need to do manual `?` because ? is not supported in constfns.
353
397
Ok ( Type {
354
- corr : Correctness :: and_v ( left. corr , right. corr ) ?,
398
+ corr : match Correctness :: and_v ( left. corr , right. corr ) {
399
+ Ok ( x) => x,
400
+ Err ( e) => return Err ( e) ,
401
+ } ,
355
402
mall : Malleability :: and_v ( left. mall , right. mall ) ,
356
403
} )
357
404
}
358
405
359
406
/// Constructor for the type of the `or_b` fragment.
360
- pub fn or_b ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
407
+ pub const fn or_b ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
408
+ // FIXME need to do manual `?` because ? is not supported in constfns.
361
409
Ok ( Type {
362
- corr : Correctness :: or_b ( left. corr , right. corr ) ?,
410
+ corr : match Correctness :: or_b ( left. corr , right. corr ) {
411
+ Ok ( x) => x,
412
+ Err ( e) => return Err ( e) ,
413
+ } ,
363
414
mall : Malleability :: or_b ( left. mall , right. mall ) ,
364
415
} )
365
416
}
366
417
367
418
/// Constructor for the type of the `or_b` fragment.
368
- pub fn or_d ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
419
+ pub const fn or_d ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
420
+ // FIXME need to do manual `?` because ? is not supported in constfns.
369
421
Ok ( Type {
370
- corr : Correctness :: or_d ( left. corr , right. corr ) ?,
422
+ corr : match Correctness :: or_d ( left. corr , right. corr ) {
423
+ Ok ( x) => x,
424
+ Err ( e) => return Err ( e) ,
425
+ } ,
371
426
mall : Malleability :: or_d ( left. mall , right. mall ) ,
372
427
} )
373
428
}
374
429
375
430
/// Constructor for the type of the `or_c` fragment.
376
- pub fn or_c ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
431
+ pub const fn or_c ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
432
+ // FIXME need to do manual `?` because ? is not supported in constfns.
377
433
Ok ( Type {
378
- corr : Correctness :: or_c ( left. corr , right. corr ) ?,
434
+ corr : match Correctness :: or_c ( left. corr , right. corr ) {
435
+ Ok ( x) => x,
436
+ Err ( e) => return Err ( e) ,
437
+ } ,
379
438
mall : Malleability :: or_c ( left. mall , right. mall ) ,
380
439
} )
381
440
}
382
441
383
442
/// Constructor for the type of the `or_i` fragment.
384
- pub fn or_i ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
443
+ pub const fn or_i ( left : Self , right : Self ) -> Result < Self , ErrorKind > {
385
444
Ok ( Type {
386
- corr : Correctness :: or_i ( left. corr , right. corr ) ?,
445
+ corr : match Correctness :: or_i ( left. corr , right. corr ) {
446
+ Ok ( x) => x,
447
+ Err ( e) => return Err ( e) ,
448
+ } ,
387
449
mall : Malleability :: or_i ( left. mall , right. mall ) ,
388
450
} )
389
451
}
390
452
391
453
/// Constructor for the type of the `and_or` fragment.
392
- pub fn and_or ( a : Self , b : Self , c : Self ) -> Result < Self , ErrorKind > {
454
+ pub const fn and_or ( a : Self , b : Self , c : Self ) -> Result < Self , ErrorKind > {
455
+ // FIXME need to do manual `?` because ? is not supported in constfns.
393
456
Ok ( Type {
394
- corr : Correctness :: and_or ( a. corr , b. corr , c. corr ) ?,
457
+ corr : match Correctness :: and_or ( a. corr , b. corr , c. corr ) {
458
+ Ok ( x) => x,
459
+ Err ( e) => return Err ( e) ,
460
+ } ,
395
461
mall : Malleability :: and_or ( a. mall , b. mall , c. mall ) ,
396
462
} )
397
463
}
398
464
399
465
/// Constructor for the type of the `thresh` fragment.
466
+ // Cannot be a constfn because it takes a closure.
400
467
pub fn threshold < S > ( k : usize , n : usize , mut sub_ck : S ) -> Result < Self , ErrorKind >
401
468
where
402
469
S : FnMut ( usize ) -> Result < Self , ErrorKind > ,
0 commit comments