1mod as_ref;
30mod display;
31mod from;
32mod into_ref;
33mod try_from;
34
35pub use as_ref::*;
36pub use display::*;
37pub use from::*;
38pub use into_ref::*;
39pub use try_from::*;
40
41pub struct Contextual<T, C>(pub T, pub C);
42
43pub trait WithContext {
44 fn with<C>(&self, context: C) -> Contextual<&Self, C>;
45
46 fn into_with<C>(self, context: C) -> Contextual<Self, C>
47 where
48 Self: Sized;
49}
50
51impl<T: ?Sized> WithContext for T {
52 fn with<C>(&self, context: C) -> Contextual<&Self, C> {
53 Contextual(self, context)
54 }
55
56 fn into_with<C>(self, context: C) -> Contextual<Self, C>
57 where
58 Self: Sized,
59 {
60 Contextual(self, context)
61 }
62}
63
64impl<T, C> std::ops::Deref for Contextual<T, C> {
65 type Target = T;
66
67 fn deref(&self) -> &T {
68 &self.0
69 }
70}
71
72impl<T, C> std::ops::DerefMut for Contextual<T, C> {
73 fn deref_mut(&mut self) -> &mut T {
74 &mut self.0
75 }
76}