pub struct Window { /* private fields */ }
Expand description
Window struct
is used to store chunks of data from a file. It is
used to help store the data that is being sent or received for the
RFC 7440 Windowsize option.
§Example
use std::{fs::{self, OpenOptions, File}, io::Write};
use tftpd::Window;
let mut file = File::create("test.txt").unwrap();
file.write_all(b"Hello, world!").unwrap();
file.flush().unwrap();
let file = File::open("test.txt").unwrap();
let mut window = Window::new(5, 512, file);
window.fill().unwrap();
fs::remove_file("test.txt").unwrap();
Implementations§
Source§impl Window
impl Window
Sourcepub fn new(size: u16, chunk_size: usize, file: File) -> Window
pub fn new(size: u16, chunk_size: usize, file: File) -> Window
Creates a new Window
with the supplied size and chunk size.
Sourcepub fn fill(&mut self) -> Result<bool, Box<dyn Error>>
pub fn fill(&mut self) -> Result<bool, Box<dyn Error>>
Fills the Window
with chunks of data from the file.
Returns true
if the Window
is full.
Sourcepub fn empty(&mut self) -> Result<(), Box<dyn Error>>
pub fn empty(&mut self) -> Result<(), Box<dyn Error>>
Empties the Window
by writing the data to the file.
Sourcepub fn remove(&mut self, amount: u16) -> Result<(), &'static str>
pub fn remove(&mut self, amount: u16) -> Result<(), &'static str>
Removes the first amount
of elements from the Window
.
Sourcepub fn add(&mut self, data: Vec<u8>) -> Result<(), &'static str>
pub fn add(&mut self, data: Vec<u8>) -> Result<(), &'static str>
Adds a data Vec<u8>
to the Window
.
Sourcepub fn get_elements(&self) -> &VecDeque<Vec<u8>>
pub fn get_elements(&self) -> &VecDeque<Vec<u8>>
Returns a reference to the VecDeque
containing the elements.
Auto Trait Implementations§
impl Freeze for Window
impl RefUnwindSafe for Window
impl Send for Window
impl Sync for Window
impl Unpin for Window
impl UnwindSafe for Window
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