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)
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
fn main() {
// create a TcpListener
let listener = std::net::TcpListener::bind("0.0.0.0:3333").expect("Failed to start tcp listener!");
println!("Listening on :3333");
// listen for incoming connections
for stream in listener.incoming() {
let mut stream = stream.expect("Invalid stream!");
// handle a new connection
std::thread::spawn(move || {
// create a reader for the TcpStream
let mut reader = send_it::reader::VarReader::new(&mut stream);
// loop while there is incoming data
while let Ok(data) = reader.read_data() {
// convert our segments to strings in the vector
let readable_data = Segment::to_readable(data);
// print out the vector of strings
println!("Segments from client: [{}]", readable_data.join(", "));
}
println!("Connection closed!");
});
}
}pub fn to_raw(&self) -> Vec<u8>
Trait Implementations§
Auto Trait Implementations§
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