mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
chore(core): switch to (maintained) bytestring::ByteString from string::String<Bytes>
This commit is contained in:
parent
e8ea502cbb
commit
91fa554063
@ -1,8 +1,8 @@
|
||||
use std::io;
|
||||
|
||||
use bytes::{Buf, Bytes};
|
||||
use bytestring::ByteString;
|
||||
use memchr::memchr;
|
||||
use string::String;
|
||||
|
||||
// UNSAFE: _unchecked string methods
|
||||
// intended for use when the protocol is *known* to always produce
|
||||
@ -10,23 +10,23 @@ use string::String;
|
||||
|
||||
pub trait BufExt: Buf {
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_str_unchecked(&mut self, n: usize) -> String<Bytes>;
|
||||
unsafe fn get_str_unchecked(&mut self, n: usize) -> ByteString;
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_str_nul_unchecked(&mut self) -> io::Result<String<Bytes>>;
|
||||
unsafe fn get_str_nul_unchecked(&mut self) -> io::Result<ByteString>;
|
||||
}
|
||||
|
||||
impl BufExt for Bytes {
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_str_unchecked(&mut self, n: usize) -> String<Bytes> {
|
||||
String::from_utf8_unchecked(self.split_to(n))
|
||||
unsafe fn get_str_unchecked(&mut self, n: usize) -> ByteString {
|
||||
ByteString::from_bytes_unchecked(self.split_to(n))
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_str_nul_unchecked(&mut self) -> io::Result<String<Bytes>> {
|
||||
unsafe fn get_str_nul_unchecked(&mut self) -> io::Result<ByteString> {
|
||||
let nul = memchr(b'\0', self).ok_or(io::ErrorKind::InvalidData)?;
|
||||
|
||||
Ok(String::from_utf8_unchecked(self.split_to(nul + 1).slice(..nul)))
|
||||
Ok(ByteString::from_bytes_unchecked(self.split_to(nul + 1).slice(..nul)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,18 +1,27 @@
|
||||
#[cfg(feature = "_mock")]
|
||||
#[doc(hidden)]
|
||||
pub mod mock;
|
||||
|
||||
#[cfg(feature = "async-std")]
|
||||
mod async_std;
|
||||
#[path = "runtime/async_std.rs"]
|
||||
mod async_std_;
|
||||
|
||||
#[cfg(feature = "actix")]
|
||||
mod actix;
|
||||
#[path = "runtime/actix.rs"]
|
||||
mod actix_;
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
mod tokio;
|
||||
#[path = "runtime/tokio.rs"]
|
||||
mod tokio_;
|
||||
|
||||
#[cfg(feature = "actix")]
|
||||
pub use self::actix::Actix;
|
||||
pub use actix_::Actix;
|
||||
#[cfg(feature = "async-std")]
|
||||
pub use self::async_std::AsyncStd;
|
||||
pub use async_std_::AsyncStd;
|
||||
#[cfg(feature = "_mock")]
|
||||
pub use mock::Mock;
|
||||
#[cfg(feature = "tokio")]
|
||||
pub use self::tokio::Tokio;
|
||||
pub use tokio_::Tokio;
|
||||
|
||||
/// Describes a set of types and functions used to open and manage
|
||||
/// resources within SQLx.
|
||||
@ -21,10 +30,7 @@ pub trait Runtime: 'static + Send + Sync {
|
||||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
pub trait AsyncRuntime: Runtime
|
||||
where
|
||||
Self::TcpStream: futures_io::AsyncRead,
|
||||
{
|
||||
pub trait AsyncRuntime: Runtime {
|
||||
/// Opens a TCP connection to a remote host at the specified port.
|
||||
fn connect_tcp(
|
||||
host: &str,
|
||||
@ -32,14 +38,14 @@ where
|
||||
) -> futures_util::future::BoxFuture<'_, std::io::Result<Self::TcpStream>>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
pub trait AsyncRead {
|
||||
fn read(&mut self, buf: &mut [u8]) -> futures_util::future::BoxFuture<'_, u64>;
|
||||
}
|
||||
|
||||
// when the async feature is not specified, this is an empty trait
|
||||
// we implement `()` for it to allow the lib to still compile
|
||||
#[cfg(not(feature = "async"))]
|
||||
#[cfg(not(any(
|
||||
feature = "async_std",
|
||||
feature = "actix",
|
||||
feature = "tokio",
|
||||
feature = "blocking"
|
||||
)))]
|
||||
impl Runtime for () {
|
||||
type TcpStream = ();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user