Skip to content

Commit

Permalink
Update disk image builder to use the builder pattern (Return &mut self)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncouture committed Jan 9, 2023
1 parent 9731b68 commit f2c8bbe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,27 @@ impl<'a> DiskImageBuilder<'a> {
Self { files: Vec::new() }
}
/// Add or replace a ramdisk to be included in the final image.
pub fn set_ramdisk(&mut self, path: &'a PathBuf) {
self.add_or_replace_file(path, RAMDISK_FILE_NAME);
pub fn set_ramdisk(&mut self, path: &'a PathBuf) -> &mut Self {
self.add_or_replace_file(path, RAMDISK_FILE_NAME)
}

/// Add or replace a kernel to be included in the final image.
pub fn set_kernel(&mut self, path: &'a PathBuf) {
pub fn set_kernel(&mut self, path: &'a PathBuf) -> &mut Self {
self.add_or_replace_file(path, KERNEL_FILE_NAME)
}

/// Add or replace arbitrary files.
/// NOTE: You can overwrite internal files if you choose, such as EFI/BOOT/BOOTX64.EFI
/// This can be useful in situations where you want to generate an image, but not use the provided bootloader.
pub fn add_or_replace_file(&mut self, path: &'a PathBuf, target: &'a str) {
pub fn add_or_replace_file(&mut self, path: &'a PathBuf, target: &'a str) -> &mut Self {
self.files.insert(
0,
DiskImageFile::<'a> {
source: &path,
destination: &target,
},
);
self
}
fn create_fat_filesystem_image(
&self,
Expand Down

0 comments on commit f2c8bbe

Please sign in to comment.