allocative/impls/std/
tuple.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under both the MIT license found in the
5 * LICENSE-MIT file in the root directory of this source tree and the Apache
6 * License, Version 2.0 found in the LICENSE-APACHE file in the root directory
7 * of this source tree.
8 */
9
10use crate::allocative_trait::Allocative;
11use crate::key::Key;
12use crate::visitor::Visitor;
13
14impl Allocative for () {
15    fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) {
16        visitor.visit_simple_sized::<Self>();
17    }
18}
19
20impl<A: Allocative> Allocative for (A,) {
21    fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) {
22        let mut visitor = visitor.enter_self_sized::<Self>();
23        visitor.visit_field(Key::new("0"), &self.0);
24    }
25}
26
27impl<A: Allocative, B: Allocative> Allocative for (A, B) {
28    fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) {
29        let mut visitor = visitor.enter_self_sized::<Self>();
30        visitor.visit_field(Key::new("0"), &self.0);
31        visitor.visit_field(Key::new("1"), &self.1);
32    }
33}
34
35impl<A: Allocative, B: Allocative, C: Allocative> Allocative for (A, B, C) {
36    fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) {
37        let mut visitor = visitor.enter_self_sized::<Self>();
38        visitor.visit_field(Key::new("0"), &self.0);
39        visitor.visit_field(Key::new("1"), &self.1);
40        visitor.visit_field(Key::new("2"), &self.2);
41    }
42}
43
44impl<A: Allocative, B: Allocative, C: Allocative, D: Allocative> Allocative for (A, B, C, D) {
45    fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) {
46        let mut visitor = visitor.enter_self_sized::<Self>();
47        visitor.visit_field(Key::new("0"), &self.0);
48        visitor.visit_field(Key::new("1"), &self.1);
49        visitor.visit_field(Key::new("2"), &self.2);
50        visitor.visit_field(Key::new("3"), &self.3);
51    }
52}
53
54impl<A: Allocative, B: Allocative, C: Allocative, D: Allocative, E: Allocative> Allocative
55    for (A, B, C, D, E)
56{
57    fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) {
58        let mut visitor = visitor.enter_self_sized::<Self>();
59        visitor.visit_field(Key::new("0"), &self.0);
60        visitor.visit_field(Key::new("1"), &self.1);
61        visitor.visit_field(Key::new("2"), &self.2);
62        visitor.visit_field(Key::new("3"), &self.3);
63        visitor.visit_field(Key::new("4"), &self.4);
64    }
65}