use super::*;
pub struct Adapter<'a, T>
where
T: FromStr + Display,
{
string: &'a mut String,
temp: T,
}
impl<'a, T> Adapter<'a, T>
where
T: FromStr + Display,
{
pub fn from(string: &'a mut String) -> Result<Adapter<'a, T>, T::Err> {
string.parse().map(move |temp| Adapter { string, temp })
}
pub fn finish(self) {}
}
impl<'a, T> Deref for Adapter<'a, T>
where
T: FromStr + Display,
{
type Target = T;
fn deref(&self) -> &Self::Target {
&self.temp
}
}
impl<'a, T> DerefMut for Adapter<'a, T>
where
T: FromStr + Display,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.temp
}
}
impl<'a, T> Drop for Adapter<'a, T>
where
T: FromStr + Display,
{
fn drop(&mut self) {
*self.string = self.temp.to_string()
}
}
impl<'a, T> Debug for Adapter<'a, T>
where
T: FromStr + Display + Debug,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
<T as Debug>::fmt(&self.temp, f)
}
}
impl<'a, T> Display for Adapter<'a, T>
where
T: FromStr + Display,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
<T as Display>::fmt(&self.temp, f)
}
}
impl<'a, T> AsRef<T> for Adapter<'a, T>
where
T: FromStr + Display,
{
fn as_ref(&self) -> &T {
&self.temp
}
}
impl<'a, T> std::borrow::Borrow<T> for Adapter<'a, T>
where
T: FromStr + Display,
{
fn borrow(&self) -> &T {
&self.temp
}
}