to_ref/
lib.rs

1pub trait ToRef {
2    fn to_ref<T>(&self) -> &T
3    where
4        T: ?Sized,
5        Self: AsRef<T>,
6    {
7        self.as_ref()
8    }
9}
10
11impl<T> ToRef for T {}
12
13#[cfg(test)]
14mod tests {
15    #[test]
16    fn it_works() {
17        use crate::ToRef;
18        use std::path::Path;
19        let url = "www.google.com".to_string();
20        let path = url.to_ref::<Path>();
21        assert_eq!(path, AsRef::<Path>::as_ref("www.google.com"));
22    }
23}