facet_core/impls_core/
ops.rs1use crate::{ConstTypeId, Facet, Field, Shape, StructType, Type, VTableView, ValueVTable};
2use core::{alloc::Layout, mem};
3
4unsafe impl<'a, Idx: Facet<'a>> Facet<'a> for core::ops::Range<Idx> {
5 const SHAPE: &'static Shape = &const {
6 Shape::builder_for_sized::<Self>()
7 .vtable(
8 ValueVTable::builder::<Self>()
9 .type_name(|f, opts| {
10 write!(f, "{}", Self::SHAPE.type_identifier)?;
11 if let Some(opts) = opts.for_children() {
12 write!(f, "<")?;
13 Idx::SHAPE.vtable.type_name()(f, opts)?;
14 write!(f, ">")?;
15 } else {
16 write!(f, "<…>")?;
17 }
18 Ok(())
19 })
20 .debug({
21 if Idx::SHAPE.vtable.has_debug() {
22 Some(|this, f| {
23 let this = this.get();
24 (<VTableView<Idx>>::of().debug().unwrap())(
25 (&this.start).into(),
26 f,
27 )?;
28 write!(f, "..")?;
29 (<VTableView<Idx>>::of().debug().unwrap())((&this.end).into(), f)?;
30 Ok(())
31 })
32 } else {
33 None
34 }
35 })
36 .build(),
37 )
38 .type_identifier("Range")
39 .type_params(&[crate::TypeParam {
40 name: "Idx",
41 shape: Idx::SHAPE,
42 }])
43 .id(ConstTypeId::of::<Self>())
44 .layout(Layout::new::<Self>())
45 .ty(Type::User(crate::UserType::Struct(
46 StructType::builder()
47 .kind(crate::StructKind::Struct)
48 .repr(crate::Repr::default())
49 .fields(
50 &const {
51 [
52 Field::builder()
53 .name("start")
54 .shape(|| Idx::SHAPE)
55 .offset(mem::offset_of!(core::ops::Range<Idx>, start))
56 .build(),
57 Field::builder()
58 .name("end")
59 .shape(|| Idx::SHAPE)
60 .offset(mem::offset_of!(core::ops::Range<Idx>, end))
61 .build(),
62 ]
63 },
64 )
65 .build(),
66 )))
67 .build()
68 };
69}