mod private
{
use std::
{
fmt,
borrow::Cow,
};
#[ derive( Debug, Default, Clone, Copy ) ]
pub struct WithRef;
#[ derive( Debug, Default, Clone, Copy ) ]
pub struct WithDebug;
#[ derive( Debug, Default, Clone, Copy ) ]
pub struct WithDebugMultiline;
#[ derive( Debug, Default, Clone, Copy ) ]
pub struct WithDisplay;
#[ derive( Debug, Default, Clone, Copy ) ]
pub struct WithWell;
pub trait ToStringWith< How >
{
fn to_string_with< 's >( &'s self ) -> Cow< 's, str >;
}
impl< 'a, T > ToStringWith< WithRef > for T
where
T : 'a,
T : AsRef< str >,
T : ?Sized,
{
#[ inline ]
fn to_string_with< 's >( &'s self ) -> Cow< 's, str >
{
Cow::Borrowed( self.as_ref() )
}
}
impl< 'a, T > ToStringWith< WithDebug > for T
where
T : fmt::Debug,
T : ?Sized,
{
#[ inline ]
fn to_string_with< 's >( &'s self ) -> Cow< 's, str >
{
Cow::Owned( format!( "{:?}", self ) )
}
}
impl< 'a, T > ToStringWith< WithDebugMultiline > for T
where
T : fmt::Debug,
T : ?Sized,
{
#[ inline ]
fn to_string_with< 's >( &'s self ) -> Cow< 's, str >
{
Cow::Owned( format!( "{:#?}", self ) )
}
}
impl< 'a, T > ToStringWith< WithDisplay > for T
where
T : 'a,
T : fmt::Display,
T : ?Sized,
{
#[ inline ]
fn to_string_with< 's >( &'s self ) -> Cow< 's, str >
{
Cow::Owned( format!( "{}", self ) )
}
}
}
mod aref;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use own::*;
#[ allow( unused_imports ) ]
pub mod own
{
use super::*;
#[ doc( inline ) ]
pub use orphan::*;
}
#[ allow( unused_imports ) ]
pub mod orphan
{
use super::*;
pub use super::super::to_string;
#[ doc( inline ) ]
pub use exposed::*;
#[ doc( inline ) ]
pub use private::
{
WithDebug,
WithDebugMultiline,
WithDisplay,
WithRef,
WithWell,
ToStringWith,
};
}
#[ allow( unused_imports ) ]
pub mod exposed
{
use super::*;
#[ doc( inline ) ]
pub use prelude::*;
}
#[ allow( unused_imports ) ]
pub mod prelude
{
use super::*;
}