libreda_db/reference_access/
l2n_reference_access.rs

1// Copyright (c) 2020-2021 Thomas Kramer.
2// SPDX-FileCopyrightText: 2022 Thomas Kramer
3//
4// SPDX-License-Identifier: AGPL-3.0-or-later
5
6use super::layout_reference_access::*;
7use super::netlist_reference_access::*;
8use crate::prelude::L2NBase;
9
10impl<'a, L: L2NBase> ShapeRef<'a, L> {
11    /// Get the net which is connected to this shape, if any.
12    pub fn net(&self) -> Option<NetRef<L>> {
13        self.base.get_net_of_shape(&self.id).map(|id| NetRef {
14            id,
15            base: self.base,
16        })
17    }
18
19    /// Get the pin which is connected to this shape, if any.
20    pub fn pin(&self) -> Option<PinRef<L>> {
21        self.base.get_pin_of_shape(&self.id).map(|id| PinRef {
22            id,
23            base: self.base,
24        })
25    }
26}
27
28impl<'a, L: L2NBase> NetRef<'a, L> {
29    /// Iterate over all shapes attached to this net.
30    pub fn each_shape(&self) -> impl Iterator<Item = ShapeRef<L>> {
31        self.base.shapes_of_net(&self.id).map(move |id| ShapeRef {
32            id,
33            base: self.base,
34        })
35    }
36}
37
38impl<'a, L: L2NBase> PinRef<'a, L> {
39    /// Iterate over all shapes attached to this pin.
40    pub fn each_shape(&self) -> impl Iterator<Item = ShapeRef<L>> {
41        self.base.shapes_of_pin(&self.id).map(move |id| ShapeRef {
42            id,
43            base: self.base,
44        })
45    }
46}