amplify/traits/
join_split.rs

1// Rust language amplification library providing multiple generic trait
2// implementations, type wrappers, derive macros and other language enhancements
3//
4// Written in 2019-2020 by
5//     Dr. Maxim Orlovsky <orlovsky@ubideco.org>
6//
7// To the extent possible under law, the author(s) have dedicated all
8// copyright and related and neighboring rights to this software to
9// the public domain worldwide. This software is distributed without
10// any warranty.
11//
12// You should have received a copy of the MIT License
13// along with this software.
14// If not, see <https://opensource.org/licenses/MIT>.
15
16/// Trait for splittable streams and other types, which can be separated into
17/// some two types ([`JoinSplit::A`], [`JoinSplit::B`]), like a reader and
18/// writer streams.
19pub trait JoinSplit {
20    /// First separable type (like reader)
21    type A;
22    /// Second separable type (like writer)
23    type B;
24
25    /// Reconstruct the type from the halves
26    fn join(left: Self::A, right: Self::B) -> Self;
27
28    /// Split the type into two
29    fn split(self) -> (Self::A, Self::B);
30}