pub struct Segment { /* private fields */ }
Expand description
A segment of data used by VarReader and VarWriter to send and receive data over a stream.
§Examples
use send_it::Segment;
let mut segment = Segment::new();
segment.append(Segment::from("Hello, "));
segment.append(Segment::from("World!"));
assert_eq!(segment.to_string(), "Hello, World!");
Implementations§
Source§impl Segment
impl Segment
Sourcepub fn to_readable(segments: Vec<Segment>) -> Vec<String>
pub fn to_readable(segments: Vec<Segment>) -> Vec<String>
Examples found in repository?
examples/server.rs (line 19)
3fn main() {
4 // create a TcpListener
5 let listener = std::net::TcpListener::bind("0.0.0.0:3333").expect("Failed to start tcp listener!");
6 println!("Listening on :3333");
7
8 // listen for incoming connections
9 for stream in listener.incoming() {
10 let mut stream = stream.expect("Invalid stream!");
11
12 // handle a new connection
13 std::thread::spawn(move || {
14 // create a reader for the TcpStream
15 let mut reader = send_it::reader::VarReader::new(&mut stream);
16 // loop while there is incoming data
17 while let Ok(data) = reader.read_data() {
18 // convert our segments to strings in the vector
19 let readable_data = Segment::to_readable(data);
20
21 // print out the vector of strings
22 println!("Segments from client: [{}]", readable_data.join(", "));
23 }
24 println!("Connection closed!");
25 });
26 }
27}
pub fn to_raw(&self) -> Vec<u8> ⓘ
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Segment
impl RefUnwindSafe for Segment
impl Send for Segment
impl Sync for Segment
impl Unpin for Segment
impl UnwindSafe for Segment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more