mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +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
|
|
@ -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<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
|
||||
}
|
||||
}
|
||||
use file_route::FileRoute;
|
||||
|
||||
/// Represents a file or directory that has been read from the filesystem.
|
||||
// TODO: Keep track of file Path or FileRoute?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue