chitey_server/tuple.rs
1// pub trait TupleAppend<T> {
2// type ResultType;
3
4// fn append(self, t: T) -> Self::ResultType;
5// }
6
7// impl<T> TupleAppend<T> for () {
8// type ResultType = (T,);
9
10// fn append(self, t: T) -> Self::ResultType {
11// (t,)
12// }
13// }
14
15// macro_rules! impl_tuple_append {
16// ( () ) => {};
17// ( ( $t0:ident $(, $types:ident)* ) ) => {
18// impl<$t0, $($types,)* T> TupleAppend<T> for ($t0, $($types,)*) {
19// // Trailing comma, just to be extra sure we are dealing
20// // with a tuple and not a parenthesized type/expr.
21// type ResultType = ($t0, $($types,)* T,);
22
23// fn append(self, t: T) -> Self::ResultType {
24// // Reuse the type identifiers to destructure ourselves:
25// let ($t0, $($types,)*) = self;
26// // Create a new tuple with the original elements, plus the new one:
27// ($t0, $($types,)* t,)
28// }
29// }
30
31// // Recurse for one smaller size:
32// impl_tuple_append! { ($($types),*) }
33// };
34// }
35
36// impl_tuple_append! {
37// // Supports tuples up to size 12:
38// (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12)
39// }
40
41// #[test]
42// fn test_tuple_append() {
43// let some_tuple: (i32, &str, bool) = (1, "Hello", true);
44// println!("{:?}", some_tuple);
45
46// let n: (u16, u16) = [3, 4].into();
47// println!("{:?}", n);
48
49// let with_world: (i32, &str, bool, &str) = some_tuple.append("World");
50// println!("{:?}", with_world);
51// }
52
53// use http::Uri;
54// use impl_trait_for_tuples::impl_for_tuples;
55
56// pub trait Tuple {
57// fn simbol_of_to_tuple(self) -> Self;
58// }
59
60// #[impl_for_tuples(0, 12)]
61// impl Tuple for TupleIdentifier {
62// fn simbol_of_to_tuple(self) -> Self {
63// self
64// }
65// }
66
67// use derive_more::{AsRef, Deref, DerefMut, Display, From};
68// use urlpattern::{UrlPattern, UrlPatternInit};
69
70// #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef, Display, From)]
71// pub struct Path<T>(T);
72
73// impl<T> Path<T>
74// {
75// pub fn into_inner(self) -> T {
76// self.0
77// }
78
79// pub fn new(t: T) -> Path<T> {
80// Self(t)
81// }
82// // pub fn tuple_new(ptn: UrlPattern, uri: Uri) -> Path<T> {
83
84// // }
85// }
86
87
88// // impl Into<Path<()>> for () {
89// // fn into(self) -> Path<()> {
90// // Path::new(self)
91// // }
92// // }
93// // impl<T> Into<Path<(T,)>> for (T,)
94// // where
95// // T: Tuple,
96// // {
97// // fn into(self) -> Path<(T,)> {
98// // Path::new(self)
99// // }
100// // }
101// // impl<T, T2> Into<Path<(T, T2)>> for (T, T2)
102// // where
103// // T: Tuple,
104// // T2: Tuple,
105// // {
106// // fn into(self) -> Path<(T, T2)> {
107// // Path::new(self)
108// // }
109// // }