1 use std::fs::File;
2 use std::io;
3 use std::path::Path;
4 
5 static ERROR_MESSAGE: &str = "same-file is not supported on this platform.";
6 // This implementation is to allow same-file to be compiled on
7 // unsupported platforms in case it was incidentally included
8 // as a transitive, unused dependency
9 #[derive(Debug, Hash)]
10 pub struct Handle;
11 
12 impl Eq for Handle {}
13 
14 impl PartialEq for Handle {
eq(&self, _other: &Handle) -> bool15     fn eq(&self, _other: &Handle) -> bool {
16         unreachable!(ERROR_MESSAGE);
17     }
18 }
19 
20 impl Handle {
from_path<P: AsRef<Path>>(_p: P) -> io::Result<Handle>21     pub fn from_path<P: AsRef<Path>>(_p: P) -> io::Result<Handle> {
22         error()
23     }
24 
from_file(_file: File) -> io::Result<Handle>25     pub fn from_file(_file: File) -> io::Result<Handle> {
26         error()
27     }
28 
stdin() -> io::Result<Handle>29     pub fn stdin() -> io::Result<Handle> {
30         error()
31     }
32 
stdout() -> io::Result<Handle>33     pub fn stdout() -> io::Result<Handle> {
34         error()
35     }
36 
stderr() -> io::Result<Handle>37     pub fn stderr() -> io::Result<Handle> {
38         error()
39     }
40 
as_file(&self) -> &File41     pub fn as_file(&self) -> &File {
42         unreachable!(ERROR_MESSAGE);
43     }
44 
as_file_mut(&self) -> &mut File45     pub fn as_file_mut(&self) -> &mut File {
46         unreachable!(ERROR_MESSAGE);
47     }
48 }
49 
error<T>() -> io::Result<T>50 fn error<T>() -> io::Result<T> {
51     Err(io::Error::new(io::ErrorKind::Other, ERROR_MESSAGE))
52 }
53