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