| 54 | |
| 55 | impl<'a> FromSqlExt<'a> for BytesStr { |
| 56 | fn from_sql_ext(ty: &Type, (range, buf): (&Range<usize>, &'a Bytes)) -> Result<Self, FromSqlError> { |
| 57 | // copy/paste from postgres-protocol dependency. |
| 58 | fn adjust_start(name: &str, range_start: usize, buf: &Bytes) -> Result<usize, FromSqlError> { |
| 59 | if buf[range_start] == 1u8 { |
| 60 | Ok(range_start + 1) |
| 61 | } else { |
| 62 | Err(format!("only {name} version 1 supported").into()) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | let start = match ty.name() { |
| 67 | "ltree" => adjust_start("ltree", range.start, buf)?, |
| 68 | "lquery" => adjust_start("lquery", range.start, buf)?, |
| 69 | "ltxtquery" => adjust_start("ltxtquery", range.start, buf)?, |
| 70 | _ => range.start, |
| 71 | }; |
| 72 | |
| 73 | BytesStr::try_from(buf.slice(start..range.end)).map_err(Into::into) |
| 74 | } |
| 75 | |
| 76 | #[inline] |
| 77 | fn accepts_ext(ty: &Type) -> bool { |