Skip to content

Commit 935c90e

Browse files
committed
add some base impls for chain struct
1 parent d932d6c commit 935c90e

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

packages/chain/src/lib.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use self::sealed::*;
2+
use core::fmt;
23

34
mod array;
45
mod string;
@@ -70,6 +71,26 @@ impl<T> Chain<T> {
7071
}
7172
}
7273

74+
impl<T, T2> AsRef<T2> for Chain<T>
75+
where
76+
T: AsRef<T2>
77+
{
78+
#[inline]
79+
fn as_ref(&self) -> &T2 {
80+
self.inner.as_ref()
81+
}
82+
}
83+
84+
impl<T, T2> AsMut<T2> for Chain<T>
85+
where
86+
T: AsMut<T2>
87+
{
88+
#[inline]
89+
fn as_mut(&mut self) -> &mut T2 {
90+
self.inner.as_mut()
91+
}
92+
}
93+
7394
impl<T> Clone for Chain<T>
7495
where
7596
T: Clone
@@ -90,6 +111,18 @@ where
90111
T: Copy
91112
{}
92113

114+
impl<T> fmt::Debug for Chain<T>
115+
where
116+
T: fmt::Debug
117+
{
118+
#[inline]
119+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120+
f.debug_struct("Chain<T>")
121+
.field("_", self.as_inner())
122+
.finish()
123+
}
124+
}
125+
93126
impl<T> Default for Chain<T>
94127
where
95128
T: Default
@@ -100,6 +133,41 @@ where
100133
}
101134
}
102135

136+
impl<T> fmt::Display for Chain<T>
137+
where
138+
T: fmt::Display
139+
{
140+
#[inline]
141+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142+
T::fmt(self.as_inner(), f)
143+
}
144+
}
145+
146+
// todo eq
147+
148+
// todo ord
149+
150+
impl<T, T2> PartialEq<T2> for Chain<T>
151+
where
152+
T: PartialEq<T2>
153+
{
154+
#[inline]
155+
fn eq(&self, other: &T2) -> bool {
156+
self.as_inner().eq(other)
157+
}
158+
159+
#[expect(
160+
clippy::partialeq_ne_impl,
161+
reason = "inner might have overridden ne for whatever reason, and we should use it if so"
162+
)]
163+
#[inline]
164+
fn ne(&self, other: &T2) -> bool {
165+
self.as_inner().ne(other)
166+
}
167+
}
168+
169+
// todo partialord
170+
103171
pub trait ChainInner: Sized {
104172
#[inline]
105173
fn from_chain(chain: Chain<Self>) -> Self {

0 commit comments

Comments
 (0)