mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
19 lines
410 B
Rust
19 lines
410 B
Rust
use bytes::Bytes;
|
|
use memchr::memchr;
|
|
use std::{io, str};
|
|
|
|
pub trait Decode {
|
|
fn decode(src: Bytes) -> io::Result<Self>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[inline]
|
|
pub(crate) fn get_str(src: &[u8]) -> io::Result<&str> {
|
|
let end = memchr(b'\0', &src).ok_or(io::ErrorKind::UnexpectedEof)?;
|
|
let buf = &src[..end];
|
|
let s = str::from_utf8(buf).map_err(|_| io::ErrorKind::InvalidData)?;
|
|
|
|
Ok(s)
|
|
}
|