Skip to content

Commit

Permalink
add unflatten trait
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulk29 committed Dec 13, 2024
1 parent 183d347 commit f86cc27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion substrate/src/types/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use super::{
FlatLen, Flatten, HasBundleKind, HasNameTree, NameBuf, NameFragment, NameTree, Signal,
Unflatten,
};
use crate::error::Result;
use crate::layout::element::NamedPorts;
Expand Down Expand Up @@ -67,7 +68,12 @@ impl<L> Bbox for PortGeometry<L> {
///
/// An instance of a [`BundleKind`].
pub trait LayoutBundle<S: Schema>:
super::HasBundleKind + Flatten<PortGeometry<S::Layer>> + TransformRef + Send + Sync
super::HasBundleKind
+ Flatten<PortGeometry<S::Layer>>
+ Unflatten<Self::BundleKind, PortGeometry<S::Layer>>
+ TransformRef
+ Send
+ Sync
{
}

Expand All @@ -77,6 +83,7 @@ where
T: super::HasBundleKind
+ FlatLen
+ Flatten<PortGeometry<S::Layer>>
+ Unflatten<Self::BundleKind, PortGeometry<S::Layer>>
+ TransformRef
+ Send
+ Sync,
Expand Down
13 changes: 13 additions & 0 deletions substrate/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ pub trait Flatten<T>: FlatLen {
}
}

/// Unflatten a structure from an iterator.
pub trait Unflatten<D, T>: FlatLen + Sized {
/// Unflatten a structure from an iterator.
///
/// A correct implementation must only return [`None`]
/// if the iterator has insufficient elements.
/// Returning None for any other reason is a logic error.
/// Unsafe code should not rely on implementations of this method being correct.
fn unflatten<I>(data: &D, source: &mut I) -> Option<Self>
where
I: Iterator<Item = T>;
}

impl<S, T: Flatten<S>> Flatten<S> for &T {
fn flatten<E>(&self, output: &mut E)
where
Expand Down

0 comments on commit f86cc27

Please sign in to comment.