diff --git a/src/http/responses.rs b/src/http/responses.rs index d349ea9..3cdebc1 100644 --- a/src/http/responses.rs +++ b/src/http/responses.rs @@ -15,6 +15,11 @@ pub struct Response { } impl Response { + /// Create a new response from a request + /// + /// request: the request to respond to + /// status: the HTTP status code + /// body: the body of the response (see Body enum) pub fn new(request: Request, status: u16, body: Body) -> Self { Response { request, @@ -23,6 +28,9 @@ impl Response { } } + /// Send off this response (write to the stream) + /// + /// Consumes the response and returns a Result with either () or a Boxed Error pub fn send(self) -> UnitOrBoxedError { send_response(self.request.mut_stream(), self.status, self.body) } diff --git a/src/icons.rs b/src/icons.rs index 0392d41..9cfd098 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -33,6 +33,12 @@ impl Icons { }) } + /// Check if the icon exists + /// + /// Cheap; does not actually call the fs - instead checks against the cached filenames in the Vec internal to this struct. + /// Therefore, it is not guaranteed to be up-to-date with the actual filesystem + /// + /// icon: the icon name to check (no .svg extension) pub fn has_iconname(&self, icon: &str) -> bool { self.icon_filenames .iter() @@ -43,15 +49,28 @@ impl Icons { .is_some() } + /// Get the number of icons + /// + /// Cheap; does not actually call the fs - instead returns the length of the cached filenames in the Vec internal to this struct. pub fn icons_len(&self) -> usize { self.icon_filenames.len() } + /// Read an .svg icon from disk to a Vec + /// + /// You may want to check if the icon exists first with has_iconname(), although that method does not guarantee the icon is still present on the disk. + /// + /// icon: the icon name to read (no .svg extension) pub fn get_icon(&self, icon: &str) -> Option> { let icon_path = format!("{}/{}.svg", self.icons_dir_path, icon); fs::read(icon_path).ok() } + /// Read an .svg icon from disk to a String, instead of a Vec + /// + /// You may want to check if the icon exists first with has_iconname(), although that method does not guarantee the icon is still present on the disk. + /// + /// icon: the icon name to read (no .svg extension) pub fn get_icon_string(&self, icon: &str) -> Option { let icon_path = format!("{}/{}.svg", self.icons_dir_path, icon); fs::read_to_string(icon_path).ok()