diff --git a/server/src/file_route.rs b/server/src/file_route.rs new file mode 100644 index 00000000..ef6f6270 --- /dev/null +++ b/server/src/file_route.rs @@ -0,0 +1,37 @@ +use std::path::{Path, PathBuf}; + +// TODO: Add lifetime, switch to using Cow<'a, str> instead of String? It's +// possible that it would be too cumbersome! +#[derive(Debug, Clone, PartialEq, Hash)] +pub struct FileRoute { + pub partition: String, + pub route: Vec, +} + +impl FileRoute { + /// Creates a PathBuf out of the `FileRoute` based on the given partition + /// `Path`. + // TODO: Tests + pub fn to_path_buf(&self, partition_path: &Path) -> PathBuf { + let mut result = partition_path.to_path_buf(); + + for route_piece in &self.route { + result.push(route_piece); + } + + result + } + + /// Creates a version of the FileRoute with the given extra pieces appended + /// to the end. + // TODO: Test + pub fn extended_with(&self, pieces: &[&str]) -> FileRoute { + let mut result = self.clone(); + + for piece in pieces { + result.route.push(piece.to_string()); + } + + result + } +} diff --git a/server/src/lib.rs b/server/src/lib.rs index 7aeab04a..76e68573 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -10,13 +10,14 @@ extern crate regex; #[cfg(test)] extern crate tempfile; -pub mod rbx_session; +pub mod commands; +pub mod file_route; pub mod id; +pub mod middleware; +pub mod pathext; +pub mod project; +pub mod rbx; +pub mod rbx_session; +pub mod vfs; pub mod web; pub mod web_util; -pub mod project; -pub mod pathext; -pub mod vfs; -pub mod rbx; -pub mod middleware; -pub mod commands; diff --git a/server/src/rbx_session.rs b/server/src/rbx_session.rs index 6b1f206d..a0ae657a 100644 --- a/server/src/rbx_session.rs +++ b/server/src/rbx_session.rs @@ -1,45 +1,10 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::collections::HashMap; use std::io::Read; use std::fs::{self, File}; use id::{Id}; - -// TODO: Add lifetime, switch to using Cow<'a, str> instead of String? It's -// possible that it would be too cumbersome! -#[derive(Debug, Clone, PartialEq, Hash)] -struct FileRoute { - pub partition: String, - pub route: Vec, -} - -impl FileRoute { - /// Creates a PathBuf out of the `FileRoute` based on the given partition - /// `Path`. - // TODO: Tests - pub fn to_path_buf(&self, partition_path: &Path) -> PathBuf { - let mut result = partition_path.to_path_buf(); - - for route_piece in &self.route { - result.push(route_piece); - } - - result - } - - /// Creates a version of the FileRoute with the given extra pieces appended - /// to the end. - // TODO: Test - pub fn extended_with(&self, pieces: &[&str]) -> FileRoute { - let mut result = self.clone(); - - for piece in pieces { - result.route.push(piece.to_string()); - } - - result - } -} +use file_route::FileRoute; /// Represents a file or directory that has been read from the filesystem. // TODO: Keep track of file Path or FileRoute?