tower_web/util/buf_stream/
str.rs

1use error::Never;
2use super::BufStream;
3
4use futures::Poll;
5
6use std::io;
7use std::mem;
8
9impl BufStream for String {
10    type Item = io::Cursor<Vec<u8>>;
11    type Error = Never;
12
13    fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
14        if self.is_empty() {
15            return Ok(None.into());
16        }
17
18        let bytes = mem::replace(self, String::new()).into_bytes();
19        let buf = io::Cursor::new(bytes);
20
21        Ok(Some(buf).into())
22    }
23}
24
25impl BufStream for &'static str {
26    type Item = io::Cursor<&'static [u8]>;
27    type Error = Never;
28
29    fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
30        if self.is_empty() {
31            return Ok(None.into());
32        }
33
34        let bytes = mem::replace(self, "").as_bytes();
35        let buf = io::Cursor::new(bytes);
36
37        Ok(Some(buf).into())
38    }
39}