Struct Window

Source
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

Source

pub fn new(size: u16, chunk_size: usize, file: File) -> Window

Creates a new Window with the supplied size and chunk size.

Source

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.

Source

pub fn empty(&mut self) -> Result<(), Box<dyn Error>>

Empties the Window by writing the data to the file.

Source

pub fn remove(&mut self, amount: u16) -> Result<(), &'static str>

Removes the first amount of elements from the Window.

Source

pub fn add(&mut self, data: Vec<u8>) -> Result<(), &'static str>

Adds a data Vec<u8> to the Window.

Source

pub fn get_elements(&self) -> &VecDeque<Vec<u8>>

Returns a reference to the VecDeque containing the elements.

Source

pub fn len(&self) -> u16

Returns the length of the Window.

Source

pub fn is_empty(&self) -> bool

Returns true if the Window is empty.

Source

pub fn is_full(&self) -> bool

Returns true if the Window is full.

Source

pub fn file_len(&self) -> Result<usize, Box<dyn Error>>

Returns the length of the file

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.