]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/self-without-lifetime-constraint.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / traits / self-without-lifetime-constraint.rs
1 use std::error::Error;
2 use std::fmt;
3
4 #[derive(Copy, Clone, Debug, PartialEq)]
5 pub enum ValueRef<'a> {
6     Null,
7     Integer(i64),
8     Real(f64),
9     Text(&'a [u8]),
10     Blob(&'a [u8]),
11 }
12
13 impl<'a> ValueRef<'a> {
14     pub fn as_str(&self) -> FromSqlResult<&'a str, &'a &'a str> {
15         match *self {
16             ValueRef::Text(t) => {
17                 std::str::from_utf8(t).map_err(|_| FromSqlError::InvalidType).map(|x| (x, &x))
18             }
19             _ => Err(FromSqlError::InvalidType),
20         }
21     }
22 }
23
24 #[derive(Debug)]
25 #[non_exhaustive]
26 pub enum FromSqlError {
27     InvalidType
28 }
29
30 impl fmt::Display for FromSqlError {
31     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32         write!(f, "InvalidType")
33     }
34 }
35
36 impl Error for FromSqlError {}
37
38 pub type FromSqlResult<T, K> = Result<(T, K), FromSqlError>;
39
40 pub trait FromSql: Sized {
41     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
42 }
43
44 impl FromSql for &str {
45     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
46     //~^ ERROR `impl` item signature doesn't match `trait` item signature
47         value.as_str()
48     }
49 }
50
51 pub fn main() {
52     println!("{}", "Hello World");
53 }