mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-25 04:54:07 +00:00
Factor FileRoute into separate module
This commit is contained in:
parent
610db157c8
commit
c61445ddaa
3 changed files with 47 additions and 44 deletions
37
server/src/file_route.rs
Normal file
37
server/src/file_route.rs
Normal file
|
|
@ -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<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,13 +10,14 @@ extern crate regex;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate tempfile;
|
extern crate tempfile;
|
||||||
|
|
||||||
pub mod rbx_session;
|
pub mod commands;
|
||||||
|
pub mod file_route;
|
||||||
pub mod id;
|
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;
|
||||||
pub mod web_util;
|
pub mod web_util;
|
||||||
pub mod project;
|
|
||||||
pub mod pathext;
|
|
||||||
pub mod vfs;
|
|
||||||
pub mod rbx;
|
|
||||||
pub mod middleware;
|
|
||||||
pub mod commands;
|
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,10 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::PathBuf;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
|
|
||||||
use id::{Id};
|
use id::{Id};
|
||||||
|
use file_route::FileRoute;
|
||||||
// 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<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Represents a file or directory that has been read from the filesystem.
|
/// Represents a file or directory that has been read from the filesystem.
|
||||||
// TODO: Keep track of file Path or FileRoute?
|
// TODO: Keep track of file Path or FileRoute?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue