Files
base64
byteorder
bytes
cfg_if
crossbeam_deque
crossbeam_epoch
crossbeam_queue
crossbeam_utils
fnv
futures
futures_cpupool
httparse
hyper
iovec
language_tags
lazy_static
libc
lock_api
log
maybe_uninit
memoffset
mime
mio
mio_uds
net2
num_cpus
parking_lot
parking_lot_core
percent_encoding
proc_macro2
quote
rand
relay
rfsapi
safemem
scoped_tls
scopeguard
serde
serde_derive
slab
smallvec
syn
take
time
tokio
tokio_codec
tokio_core
tokio_current_thread
tokio_executor
tokio_fs
tokio_io
tokio_proto
tokio_reactor
tokio_service
tokio_sync
tokio_tcp
tokio_threadpool
tokio_timer
tokio_udp
tokio_uds
try_lock
unicase
unicode_xid
want
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::ops::Deref;
use std::str;

use bytes::Bytes;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ByteStr(Bytes);

impl ByteStr {
    pub unsafe fn from_utf8_unchecked(slice: Bytes) -> ByteStr {
        ByteStr(slice)
    }

    pub fn from_static(s: &'static str) -> ByteStr {
        ByteStr(Bytes::from_static(s.as_bytes()))
    }

    pub fn slice(&self, from: usize, to: usize) -> ByteStr {
        assert!(self.as_str().is_char_boundary(from));
        assert!(self.as_str().is_char_boundary(to));
        ByteStr(self.0.slice(from, to))
    }

    pub fn slice_to(&self, idx: usize) -> ByteStr {
        assert!(self.as_str().is_char_boundary(idx));
        ByteStr(self.0.slice_to(idx))
    }

    pub fn as_str(&self) -> &str {
        unsafe { str::from_utf8_unchecked(self.0.as_ref()) }
    }

    pub fn insert(&mut self, idx: usize, ch: char) {
        let mut s = self.as_str().to_owned();
        s.insert(idx, ch);
        let bytes = Bytes::from(s);
        self.0 = bytes;
    }

    #[cfg(feature = "compat")]
    pub fn into_bytes(self) -> Bytes {
        self.0
    }
}

impl Deref for ByteStr {
    type Target = str;
    fn deref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> From<&'a str> for ByteStr {
    fn from(s: &'a str) -> ByteStr {
        ByteStr(Bytes::from(s))
    }
}