|
1 | 1 | use std::fmt::{self, Display};
|
2 | 2 | use std::mem;
|
3 | 3 | use std::os::raw::c_void;
|
4 |
| -use std::ptr; |
5 | 4 |
|
6 | 5 | use crate::array::VarLenArray;
|
7 | 6 | use crate::references::Reference;
|
@@ -288,57 +287,57 @@ unsafe impl H5Type for bool {
|
288 | 287 | }
|
289 | 288 | }
|
290 | 289 |
|
291 |
| -macro_rules! impl_tuple { |
292 |
| - (@second $a:tt $b:tt) => ($b); |
293 |
| - |
294 |
| - (@parse_fields [$($s:ident)*] $origin:ident $fields:ident | $t:ty $(,$tt:ty)*) => ( |
295 |
| - let &$($s)*(.., ref f, $(impl_tuple!(@second $tt _),)*) = unsafe { &*$origin }; |
296 |
| - let index = $fields.len(); |
297 |
| - $fields.push(CompoundField { |
298 |
| - name: format!("{}", index), |
299 |
| - ty: <$t as H5Type>::type_descriptor(), |
300 |
| - offset: f as *const _ as _, |
301 |
| - index, |
302 |
| - }); |
303 |
| - impl_tuple!(@parse_fields [$($s)*] $origin $fields | $($tt),*); |
304 |
| - ); |
305 |
| - |
306 |
| - (@parse_fields [$($s:ident)*] $origin:ident $fields:ident |) => (); |
307 |
| - |
308 |
| - ($t:ident) => ( |
309 |
| - unsafe impl<$t> H5Type for ($t,) where $t: H5Type { |
310 |
| - #[inline] |
311 |
| - fn type_descriptor() -> TypeDescriptor { |
312 |
| - let size = mem::size_of::<($t,)>(); |
313 |
| - assert_eq!(size, mem::size_of::<$t>()); |
314 |
| - TypeDescriptor::Compound(CompoundType { |
315 |
| - fields: vec![CompoundField::typed::<$t>("0", 0, 0)], |
316 |
| - size, |
317 |
| - }) |
318 |
| - } |
319 |
| - } |
320 |
| - ); |
321 |
| - |
322 |
| - ($t:ident, $($tt:ident),*) => ( |
323 |
| - #[allow(dead_code, unused_variables)] |
324 |
| - unsafe impl<$t, $($tt),*> H5Type for ($t, $($tt),*) |
325 |
| - where $t: H5Type, $($tt: H5Type),* |
326 |
| - { |
327 |
| - fn type_descriptor() -> TypeDescriptor { |
328 |
| - let origin: *const Self = ptr::null(); |
329 |
| - let mut fields = Vec::new(); |
330 |
| - impl_tuple!(@parse_fields [] origin fields | $t, $($tt),*); |
331 |
| - let size = mem::size_of::<Self>(); |
332 |
| - fields.sort_by_key(|f| f.offset); |
333 |
| - TypeDescriptor::Compound(CompoundType { fields, size }) |
334 |
| - } |
335 |
| - } |
336 |
| - |
337 |
| - impl_tuple!($($tt),*); |
338 |
| - ); |
339 |
| -} |
340 |
| - |
341 |
| -impl_tuple! { A, B, C, D, E, F, G, H, I, J, K, L } |
| 290 | +// macro_rules! impl_tuple { |
| 291 | +// (@second $a:tt $b:tt) => ($b); |
| 292 | + |
| 293 | +// (@parse_fields [$($s:ident)*] $origin:ident $fields:ident | $t:ty $(,$tt:ty)*) => ( |
| 294 | +// let &$($s)*(.., ref f, $(impl_tuple!(@second $tt _),)*) = unsafe { &*$origin }; |
| 295 | +// let index = $fields.len(); |
| 296 | +// $fields.push(CompoundField { |
| 297 | +// name: format!("{}", index), |
| 298 | +// ty: <$t as H5Type>::type_descriptor(), |
| 299 | +// offset: f as *const _ as _, |
| 300 | +// index, |
| 301 | +// }); |
| 302 | +// impl_tuple!(@parse_fields [$($s)*] $origin $fields | $($tt),*); |
| 303 | +// ); |
| 304 | + |
| 305 | +// (@parse_fields [$($s:ident)*] $origin:ident $fields:ident |) => (); |
| 306 | + |
| 307 | +// ($t:ident) => ( |
| 308 | +// unsafe impl<$t> H5Type for ($t,) where $t: H5Type { |
| 309 | +// #[inline] |
| 310 | +// fn type_descriptor() -> TypeDescriptor { |
| 311 | +// let size = mem::size_of::<($t,)>(); |
| 312 | +// assert_eq!(size, mem::size_of::<$t>()); |
| 313 | +// TypeDescriptor::Compound(CompoundType { |
| 314 | +// fields: vec![CompoundField::typed::<$t>("0", 0, 0)], |
| 315 | +// size, |
| 316 | +// }) |
| 317 | +// } |
| 318 | +// } |
| 319 | +// ); |
| 320 | + |
| 321 | +// ($t:ident, $($tt:ident),*) => ( |
| 322 | +// #[allow(dead_code, unused_variables)] |
| 323 | +// unsafe impl<$t, $($tt),*> H5Type for ($t, $($tt),*) |
| 324 | +// where $t: H5Type, $($tt: H5Type),* |
| 325 | +// { |
| 326 | +// fn type_descriptor() -> TypeDescriptor { |
| 327 | +// let origin: *const Self = std::ptr::null(); |
| 328 | +// let mut fields = Vec::new(); |
| 329 | +// impl_tuple!(@parse_fields [] origin fields | $t, $($tt),*); |
| 330 | +// let size = mem::size_of::<Self>(); |
| 331 | +// fields.sort_by_key(|f| f.offset); |
| 332 | +// TypeDescriptor::Compound(CompoundType { fields, size }) |
| 333 | +// } |
| 334 | +// } |
| 335 | + |
| 336 | +// impl_tuple!($($tt),*); |
| 337 | +// ); |
| 338 | +// } |
| 339 | + |
| 340 | +// impl_tuple! { A, B, C, D, E, F, G, H, I, J, K, L } |
342 | 341 |
|
343 | 342 | unsafe impl<T: H5Type, const N: usize> H5Type for [T; N] {
|
344 | 343 | #[inline]
|
@@ -385,7 +384,7 @@ unsafe impl H5Type for VarLenUnicode {
|
385 | 384 | #[cfg(test)]
|
386 | 385 | pub mod tests {
|
387 | 386 | use super::TypeDescriptor as TD;
|
388 |
| - use super::{hvl_t, CompoundField, CompoundType, FloatSize, H5Type, IntSize}; |
| 387 | + use super::{hvl_t, FloatSize, H5Type, IntSize}; |
389 | 388 | use crate::array::VarLenArray;
|
390 | 389 | use crate::string::{FixedAscii, FixedUnicode, VarLenAscii, VarLenUnicode};
|
391 | 390 | use std::mem;
|
@@ -453,93 +452,93 @@ pub mod tests {
|
453 | 452 | assert_eq!(VarLenUnicode::type_descriptor(), TD::VarLenUnicode);
|
454 | 453 | }
|
455 | 454 |
|
456 |
| - #[test] |
457 |
| - pub fn test_tuples() { |
458 |
| - type T1 = (u16,); |
459 |
| - let td = T1::type_descriptor(); |
460 |
| - assert_eq!( |
461 |
| - td, |
462 |
| - TD::Compound(CompoundType { |
463 |
| - fields: vec![CompoundField::typed::<u16>("0", 0, 0),], |
464 |
| - size: 2, |
465 |
| - }) |
466 |
| - ); |
467 |
| - assert_eq!(td.size(), 2); |
468 |
| - assert_eq!(mem::size_of::<T1>(), 2); |
469 |
| - |
470 |
| - type T2 = (i32, f32, (u64,)); |
471 |
| - let td = T2::type_descriptor(); |
472 |
| - assert_eq!( |
473 |
| - td, |
474 |
| - TD::Compound(CompoundType { |
475 |
| - fields: vec![ |
476 |
| - CompoundField::typed::<i32>("0", 0, 0), |
477 |
| - CompoundField::typed::<f32>("1", 4, 1), |
478 |
| - CompoundField::new( |
479 |
| - "2", |
480 |
| - TD::Compound(CompoundType { |
481 |
| - fields: vec![CompoundField::typed::<u64>("0", 0, 0),], |
482 |
| - size: 8, |
483 |
| - }), |
484 |
| - 8, |
485 |
| - 2 |
486 |
| - ), |
487 |
| - ], |
488 |
| - size: 16, |
489 |
| - }) |
490 |
| - ); |
491 |
| - assert_eq!(td.size(), 16); |
492 |
| - assert_eq!(mem::size_of::<T2>(), 16); |
493 |
| - } |
494 |
| - |
495 |
| - #[test] |
496 |
| - pub fn test_tuple_various_reprs() { |
497 |
| - type T = (i8, u64, f32, bool); |
498 |
| - assert_eq!(mem::size_of::<T>(), 16); |
499 |
| - |
500 |
| - let td = T::type_descriptor(); |
501 |
| - assert_eq!( |
502 |
| - td, |
503 |
| - TD::Compound(CompoundType { |
504 |
| - fields: vec![ |
505 |
| - CompoundField::typed::<u64>("1", 0, 1), |
506 |
| - CompoundField::typed::<f32>("2", 8, 2), |
507 |
| - CompoundField::typed::<i8>("0", 12, 0), |
508 |
| - CompoundField::typed::<bool>("3", 13, 3), |
509 |
| - ], |
510 |
| - size: 16, |
511 |
| - }) |
512 |
| - ); |
513 |
| - assert_eq!(td.size(), 16); |
514 |
| - |
515 |
| - let td = T::type_descriptor().to_c_repr(); |
516 |
| - assert_eq!( |
517 |
| - td, |
518 |
| - TD::Compound(CompoundType { |
519 |
| - fields: vec![ |
520 |
| - CompoundField::typed::<i8>("0", 0, 0), |
521 |
| - CompoundField::typed::<u64>("1", 8, 1), |
522 |
| - CompoundField::typed::<f32>("2", 16, 2), |
523 |
| - CompoundField::typed::<bool>("3", 20, 3), |
524 |
| - ], |
525 |
| - size: 24, |
526 |
| - }) |
527 |
| - ); |
528 |
| - assert_eq!(td.size(), 24); |
529 |
| - |
530 |
| - let td = T::type_descriptor().to_packed_repr(); |
531 |
| - assert_eq!( |
532 |
| - td, |
533 |
| - TD::Compound(CompoundType { |
534 |
| - fields: vec![ |
535 |
| - CompoundField::typed::<i8>("0", 0, 0), |
536 |
| - CompoundField::typed::<u64>("1", 1, 1), |
537 |
| - CompoundField::typed::<f32>("2", 9, 2), |
538 |
| - CompoundField::typed::<bool>("3", 13, 3), |
539 |
| - ], |
540 |
| - size: 14, |
541 |
| - }) |
542 |
| - ); |
543 |
| - assert_eq!(td.size(), 14); |
544 |
| - } |
| 455 | + // #[test] |
| 456 | + // pub fn test_tuples() { |
| 457 | + // type T1 = (u16,); |
| 458 | + // let td = T1::type_descriptor(); |
| 459 | + // assert_eq!( |
| 460 | + // td, |
| 461 | + // TD::Compound(CompoundType { |
| 462 | + // fields: vec![CompoundField::typed::<u16>("0", 0, 0),], |
| 463 | + // size: 2, |
| 464 | + // }) |
| 465 | + // ); |
| 466 | + // assert_eq!(td.size(), 2); |
| 467 | + // assert_eq!(mem::size_of::<T1>(), 2); |
| 468 | + |
| 469 | + // type T2 = (i32, f32, (u64,)); |
| 470 | + // let td = T2::type_descriptor(); |
| 471 | + // assert_eq!( |
| 472 | + // td, |
| 473 | + // TD::Compound(CompoundType { |
| 474 | + // fields: vec![ |
| 475 | + // CompoundField::typed::<i32>("0", 0, 0), |
| 476 | + // CompoundField::typed::<f32>("1", 4, 1), |
| 477 | + // CompoundField::new( |
| 478 | + // "2", |
| 479 | + // TD::Compound(CompoundType { |
| 480 | + // fields: vec![CompoundField::typed::<u64>("0", 0, 0),], |
| 481 | + // size: 8, |
| 482 | + // }), |
| 483 | + // 8, |
| 484 | + // 2 |
| 485 | + // ), |
| 486 | + // ], |
| 487 | + // size: 16, |
| 488 | + // }) |
| 489 | + // ); |
| 490 | + // assert_eq!(td.size(), 16); |
| 491 | + // assert_eq!(mem::size_of::<T2>(), 16); |
| 492 | + // } |
| 493 | + |
| 494 | + // #[test] |
| 495 | + // pub fn test_tuple_various_reprs() { |
| 496 | + // type T = (i8, u64, f32, bool); |
| 497 | + // assert_eq!(mem::size_of::<T>(), 16); |
| 498 | + |
| 499 | + // let td = T::type_descriptor(); |
| 500 | + // assert_eq!( |
| 501 | + // td, |
| 502 | + // TD::Compound(CompoundType { |
| 503 | + // fields: vec![ |
| 504 | + // CompoundField::typed::<u64>("1", 0, 1), |
| 505 | + // CompoundField::typed::<f32>("2", 8, 2), |
| 506 | + // CompoundField::typed::<i8>("0", 12, 0), |
| 507 | + // CompoundField::typed::<bool>("3", 13, 3), |
| 508 | + // ], |
| 509 | + // size: 16, |
| 510 | + // }) |
| 511 | + // ); |
| 512 | + // assert_eq!(td.size(), 16); |
| 513 | + |
| 514 | + // let td = T::type_descriptor().to_c_repr(); |
| 515 | + // assert_eq!( |
| 516 | + // td, |
| 517 | + // TD::Compound(CompoundType { |
| 518 | + // fields: vec![ |
| 519 | + // CompoundField::typed::<i8>("0", 0, 0), |
| 520 | + // CompoundField::typed::<u64>("1", 8, 1), |
| 521 | + // CompoundField::typed::<f32>("2", 16, 2), |
| 522 | + // CompoundField::typed::<bool>("3", 20, 3), |
| 523 | + // ], |
| 524 | + // size: 24, |
| 525 | + // }) |
| 526 | + // ); |
| 527 | + // assert_eq!(td.size(), 24); |
| 528 | + |
| 529 | + // let td = T::type_descriptor().to_packed_repr(); |
| 530 | + // assert_eq!( |
| 531 | + // td, |
| 532 | + // TD::Compound(CompoundType { |
| 533 | + // fields: vec![ |
| 534 | + // CompoundField::typed::<i8>("0", 0, 0), |
| 535 | + // CompoundField::typed::<u64>("1", 1, 1), |
| 536 | + // CompoundField::typed::<f32>("2", 9, 2), |
| 537 | + // CompoundField::typed::<bool>("3", 13, 3), |
| 538 | + // ], |
| 539 | + // size: 14, |
| 540 | + // }) |
| 541 | + // ); |
| 542 | + // assert_eq!(td.size(), 14); |
| 543 | + // } |
545 | 544 | }
|
0 commit comments