From 97aa749157bf3648d821745ccba15c20cffc77ff Mon Sep 17 00:00:00 2001 From: timofey Date: Sat, 9 Mar 2024 00:22:33 +0000 Subject: [PATCH] improve anystr solution --- src/exercises/anystr.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/exercises/anystr.md b/src/exercises/anystr.md index ea76c7d..ad2a04c 100644 --- a/src/exercises/anystr.md +++ b/src/exercises/anystr.md @@ -21,7 +21,7 @@ Example of what it may allow (solution isn't required to pass these tests, but s # type E; # fn accept(self) -> Self::Output where Self::E: Equivalent; # } -# pub trait AnyStr{fn provide+Accepts,E=Self,Output=Output>,Output>(accepts:A)->Output;} +# pub trait AnyStr:Equivalent{fn provide+Accepts,E=Self,Output=Output>,Output>(accepts:A)->Output;} # impl Equivalent for T { # type T = T; # fn st_ref(&self) -> &Self::T { self } @@ -37,23 +37,23 @@ Example of what it may allow (solution isn't required to pass these tests, but s # impl AnyStr for Vec { # fn provide+Accepts,E=Self,Output=Output>,Output>(accepts:A)->Output{>>::accept(accepts)} # } -# pub struct Concat(E, E); +# pub struct Concat(E::T, E::T); # impl Accepts for Concat { -# type Output = E; +# type Output = E::T; # type E = E; -# fn accept(self) -> Self::Output where E: Equivalent { E::ts_move(self.0.st_move() + self.1.st_ref()) } +# fn accept(self) -> Self::Output where E: Equivalent { self.0 + &self.1 } # } # impl Accepts> for Concat { -# type Output = E; +# type Output = E::T; # type E = E; # fn accept(self) -> Self::Output where E: Equivalent> { -# let mut a: Vec = self.0.st_move(); -# let mut b: Vec = self.1.st_move(); +# let mut a = self.0; +# let mut b = self.1; # a.append(&mut b); -# E::ts_move(a) +# a # } # } -# pub fn concat(a: T, b: T) -> T { T::provide(Concat(a, b)) } +# pub fn concat(a: T, b: T) -> T { T::ts_move(T::provide(Concat(a.st_move(), b.st_move()))) } assert_eq!(concat("ab".to_string(), "cd".to_string()), "abcd".to_string()); assert_eq!(concat(vec![2u8, 3u8], vec![5u8, 7u8]), vec![2u8, 3u8, 5u8, 7u8]); ```