pub struct Structure {
pub width: usize,
pub depth: usize,
pub target_size: usize,
}
Expand description
Everything is a file in Unix :) including directories Struct for representing a file structure, regardless of depth (i.e. a file or a directory) We use this for generating random data for testing
Fields§
§width: usize
How many files should be in the file (if it has depth > 0)
depth: usize
How deep the directory structure should be. 0 means this is a file
target_size: usize
How much data should be in the file, in bytes
Implementations§
Source§impl Structure
impl Structure
Sourcepub fn new(
width: usize,
depth: usize,
target_size: usize,
strategy: Strategy,
) -> Self
pub fn new( width: usize, depth: usize, target_size: usize, strategy: Strategy, ) -> Self
Create a new FileStructure
§Arguments
width: Desired width of the file structure depth: Desired depth of the file structure target_size: Desired size of the file structure strategy: The strategy to use for generating the file structure
§Returns
FileStructure
§Examples
use fake_file::{Structure, Strategy};
let s = Structure::new(
4, // width
4, // depth
1024, // target_size
Strategy::Simple, // strategy
);
Sourcepub fn to_path_string(&self) -> String
pub fn to_path_string(&self) -> String
Convert the FileStructure to a string that can be used as a filename
§Example
use fake_file::{Structure, Strategy};
let s = Structure::new(
4, // width
4, // depth
1024 * 1024,
Strategy::Simple // target size in bytes (1Mb)
);
assert_eq!(s.to_path_string(), "w4_d4_s1048576");
Sourcepub fn generate(&self, path: &Path) -> Result<(), Error>
pub fn generate(&self, path: &Path) -> Result<(), Error>
Generate a FileStructure with the given path. Does not check if the path can hold the file structure. Use with caution!
§Arguments
path: The path to generate the file structure at
§Panics
Panics if it can’t create a directory at the given path (i.e. the path parent doesn’t exist) Panics if the given path already exists Errors if the file structure cannot be generated for some reason
§Example
use fake_file::{Structure, Strategy};
use std::path::Path;
let s = Structure::new(
4, // width
4, // depth
1024 * 1024, // target size in bytes (1Mb)
Strategy::Simple,
);
let path = Path::new("/tmp/fake_file");
s.generate(path).unwrap();