mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-13 00:00:32 +02:00
Track Rust nightlies
This commit is contained in:
+10
-12
@@ -2,13 +2,13 @@ use {ByteBuf, SmallByteStr};
|
||||
use traits::{Buf, ByteStr, ToBytes};
|
||||
use std::{fmt, mem, ops, ptr};
|
||||
use std::any::{Any, TypeId};
|
||||
use std::marker::Reflect;
|
||||
use std::raw::TraitObject;
|
||||
use core::nonzero::NonZero;
|
||||
|
||||
const INLINE: usize = 1;
|
||||
|
||||
/// A specialized `ByteStr` box.
|
||||
#[unsafe_no_drop_flag]
|
||||
pub struct Bytes {
|
||||
vtable: NonZero<usize>,
|
||||
data: *mut (),
|
||||
@@ -21,7 +21,7 @@ impl Bytes {
|
||||
.unwrap_or_else(|| ByteBuf::from_slice(bytes).to_bytes())
|
||||
}
|
||||
|
||||
pub fn of<B: ByteStr + 'static>(bytes: B) -> Bytes {
|
||||
pub fn of<B: ByteStr>(bytes: B) -> Bytes {
|
||||
unsafe {
|
||||
if inline::<B>() {
|
||||
let mut vtable;
|
||||
@@ -61,7 +61,7 @@ impl Bytes {
|
||||
|
||||
/// If the underlying `ByteStr` is of type `B`, returns a reference to it
|
||||
/// otherwise None.
|
||||
pub fn downcast_ref<'a, B: ByteStr + 'static>(&'a self) -> Option<&'a B> {
|
||||
pub fn downcast_ref<'a, B: ByteStr>(&'a self) -> Option<&'a B> {
|
||||
if TypeId::of::<B>() == self.obj().get_type_id() {
|
||||
unsafe {
|
||||
if inline::<B>() {
|
||||
@@ -77,7 +77,7 @@ impl Bytes {
|
||||
|
||||
/// If the underlying `ByteStr` is of type `B`, returns the unwraped value,
|
||||
/// otherwise, returns the original `Bytes` as `Err`.
|
||||
pub fn try_unwrap<B: ByteStr + 'static>(self) -> Result<B, Bytes> {
|
||||
pub fn try_unwrap<B: ByteStr + Reflect>(self) -> Result<B, Bytes> {
|
||||
if TypeId::of::<B>() == self.obj().get_type_id() {
|
||||
unsafe {
|
||||
// Underlying ByteStr value is of the correct type. Unwrap it
|
||||
@@ -137,7 +137,7 @@ impl ByteStr for Bytes {
|
||||
self.obj().buf()
|
||||
}
|
||||
|
||||
fn concat<B: ByteStr+'static>(&self, other: &B) -> Bytes {
|
||||
fn concat<B: ByteStr>(&self, other: &B) -> Bytes {
|
||||
self.obj().concat(&Bytes::of(other.clone()))
|
||||
}
|
||||
|
||||
@@ -182,13 +182,10 @@ impl Clone for Bytes {
|
||||
|
||||
impl Drop for Bytes {
|
||||
fn drop(&mut self) {
|
||||
if *self.vtable == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
if self.is_inline() {
|
||||
self.obj_mut().drop();
|
||||
let obj = self.obj_mut();
|
||||
obj.drop();
|
||||
} else {
|
||||
let _: Box<ByteStrPriv> =
|
||||
mem::transmute(self.obj());
|
||||
@@ -221,7 +218,7 @@ trait ByteStrPriv {
|
||||
fn split_at(&self, mid: usize) -> (Bytes, Bytes);
|
||||
}
|
||||
|
||||
impl<B: ByteStr + 'static> ByteStrPriv for B {
|
||||
impl<B: ByteStr> ByteStrPriv for B {
|
||||
|
||||
fn buf(&self) -> Box<Buf+'static> {
|
||||
Box::new(self.buf())
|
||||
@@ -264,7 +261,8 @@ impl<B: ByteStr + 'static> ByteStrPriv for B {
|
||||
|
||||
#[test]
|
||||
pub fn test_size_of() {
|
||||
let expect = mem::size_of::<usize>() * 2;
|
||||
// TODO: One day, there shouldn't be a drop flag
|
||||
let expect = mem::size_of::<usize>() * 3;
|
||||
|
||||
assert_eq!(expect, mem::size_of::<Bytes>());
|
||||
assert_eq!(expect, mem::size_of::<Option<Bytes>>());
|
||||
|
||||
+4
-3
@@ -1,7 +1,7 @@
|
||||
#![crate_name = "bytes"]
|
||||
#![unstable]
|
||||
|
||||
#![feature(alloc, convert, core, unsafe_no_drop_flag)]
|
||||
#![feature(alloc, convert, core)]
|
||||
|
||||
pub use byte_buf::{ByteBuf, ROByteBuf, MutByteBuf};
|
||||
pub use byte_str::{SeqByteStr, SmallByteStr, SmallByteStrBuf};
|
||||
@@ -11,6 +11,7 @@ pub use rope::{Rope, RopeBuf};
|
||||
pub use slice::{SliceBuf, MutSliceBuf};
|
||||
|
||||
use std::{cmp, fmt, io, ops, ptr, u32};
|
||||
use std::marker::Reflect;
|
||||
|
||||
extern crate core;
|
||||
|
||||
@@ -198,7 +199,7 @@ pub trait MutBufExt {
|
||||
/// An immutable sequence of bytes. Operations will not mutate the original
|
||||
/// value. Since only immutable access is permitted, operations do not require
|
||||
/// copying (though, sometimes copying will happen as an optimization).
|
||||
pub trait ByteStr : Clone + Sized + Send + Sync + ToBytes + ops::Index<usize, Output=u8> {
|
||||
pub trait ByteStr : Clone + Sized + Send + Sync + Reflect + ToBytes + ops::Index<usize, Output=u8> + 'static {
|
||||
|
||||
// Until HKT lands, the buf must be bound by 'static
|
||||
type Buf: Buf+'static;
|
||||
@@ -382,7 +383,7 @@ impl<'a> Sink for &'a mut Vec<u8> {
|
||||
|
||||
unsafe {
|
||||
{
|
||||
let dst = self.as_mut_slice();
|
||||
let dst = &mut self[..];
|
||||
let cnt = buf.read_slice(slice::from_raw_parts_mut(dst.as_mut_ptr(), rem));
|
||||
|
||||
debug_assert!(cnt == rem);
|
||||
|
||||
Reference in New Issue
Block a user