Skip to content

Commit c5e2508

Browse files
fix style in code examples
Signed-off-by: Andreea Florescu <fandree@amazon.com>
1 parent 453c820 commit c5e2508

File tree

9 files changed

+82
-77
lines changed

9 files changed

+82
-77
lines changed

src/cmdline/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,13 @@ impl Cmdline {
284284
/// # use std::ffi::CString;
285285
/// # use vm_memory::{GuestAddress, GuestUsize};
286286
/// let mut cl = Cmdline::new(100);
287-
/// cl.add_virtio_mmio_device(1 << 12, GuestAddress(0x1000), 5, Some(42)).unwrap();
287+
/// cl.add_virtio_mmio_device(1 << 12, GuestAddress(0x1000), 5, Some(42))
288+
/// .unwrap();
288289
/// let cl_cstring = CString::new(cl).unwrap();
289-
/// assert_eq!(cl_cstring.to_str().unwrap(), "virtio_mmio.device=4K@0x1000:5:42");
290+
/// assert_eq!(
291+
/// cl_cstring.to_str().unwrap(),
292+
/// "virtio_mmio.device=4K@0x1000:5:42"
293+
/// );
290294
/// ```
291295
///
292296
/// [documentation]: https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html

src/configurator/aarch64/fdt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl BootConfigurator for FdtBootConfigurator {
7373
/// FdtBootConfigurator::write_bootparams::<GuestMemoryMmap>(
7474
/// &BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr),
7575
/// &guest_memory,
76-
/// ).unwrap();
76+
/// )
77+
/// .unwrap();
7778
/// # }
7879
/// ```
7980
fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()>

src/configurator/mod.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,20 @@ impl BootParams {
248248
/// // Sections start address needs to be configured first.
249249
/// assert!(boot_params.add_section::<Section>(&section, None).is_err());
250250
/// let sections_start = GuestAddress(0x2000);
251-
/// assert!(boot_params.add_section::<Section>(
252-
/// &section, Some(sections_start)
253-
/// ).is_ok());
251+
/// assert!(boot_params
252+
/// .add_section::<Section>(&section, Some(sections_start))
253+
/// .is_ok());
254254
/// // It can be overwritten...
255-
/// assert_eq!(boot_params.add_section::<Section>(
256-
/// &section,
257-
/// Some(sections_start)
258-
/// ).unwrap(), sections_start);
255+
/// assert_eq!(
256+
/// boot_params
257+
/// .add_section::<Section>(&section, Some(sections_start))
258+
/// .unwrap(),
259+
/// sections_start
260+
/// );
259261
/// // But only if the address is valid.
260-
/// assert!(boot_params.add_section::<Section>(
261-
/// &section,
262-
/// Some(sections_start.unchecked_sub(0x100))
263-
/// ).is_err());
262+
/// assert!(boot_params
263+
/// .add_section::<Section>(&section, Some(sections_start.unchecked_sub(0x100)))
264+
/// .is_err());
264265
/// // Or appended...
265266
/// assert_eq!(
266267
/// boot_params.add_section::<Section>(&section, None).unwrap(),
@@ -356,19 +357,20 @@ impl BootParams {
356357
/// // Modules start address needs to be configured first.
357358
/// assert!(boot_params.add_module::<Module>(&module, None).is_err());
358359
/// let modules_start = GuestAddress(0x2000);
359-
/// assert!(boot_params.add_module::<Module>(
360-
/// &module, Some(modules_start)
361-
/// ).is_ok());
360+
/// assert!(boot_params
361+
/// .add_module::<Module>(&module, Some(modules_start))
362+
/// .is_ok());
362363
/// // It can be overwritten...
363-
/// assert_eq!(boot_params.add_module::<Module>(
364-
/// &module,
365-
/// Some(modules_start)
366-
/// ).unwrap(), modules_start);
364+
/// assert_eq!(
365+
/// boot_params
366+
/// .add_module::<Module>(&module, Some(modules_start))
367+
/// .unwrap(),
368+
/// modules_start
369+
/// );
367370
/// // But only if the address is valid.
368-
/// assert!(boot_params.add_module::<Module>(
369-
/// &module,
370-
/// Some(modules_start.unchecked_sub(0x100))
371-
/// ).is_err());
371+
/// assert!(boot_params
372+
/// .add_module::<Module>(&module, Some(modules_start.unchecked_sub(0x100)))
373+
/// .is_err());
372374
/// // Or appended...
373375
/// assert_eq!(
374376
/// boot_params.add_module::<Module>(&module, None).unwrap(),

src/configurator/x86_64/linux.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ impl BootConfigurator for LinuxBootConfigurator {
8989
/// let guest_memory = create_guest_memory();
9090
/// let params = build_bootparams();
9191
/// let mut bootparams = BootParams::new::<boot_params>(&params, zero_page_addr);
92-
/// LinuxBootConfigurator::write_bootparams::<GuestMemoryMmap>(
93-
/// &bootparams,
94-
/// &guest_memory,
95-
/// ).unwrap();
92+
/// LinuxBootConfigurator::write_bootparams::<GuestMemoryMmap>(&bootparams, &guest_memory)
93+
/// .unwrap();
9694
/// }
9795
/// ```
9896
///

src/configurator/x86_64/pvh.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ impl BootConfigurator for PvhBootConfigurator {
107107
/// size: 0,
108108
/// type_: E820_RAM,
109109
/// reserved: 0,
110-
/// };
111-
/// start_info.magic = XEN_HVM_START_MAGIC_VALUE;
112-
/// start_info.version = 1;
113-
/// start_info.nr_modules = 0;
114-
/// start_info.memmap_entries = 0;
115-
/// (start_info, vec![memmap_entry])
110+
/// };
111+
/// start_info.magic = XEN_HVM_START_MAGIC_VALUE;
112+
/// start_info.version = 1;
113+
/// start_info.nr_modules = 0;
114+
/// start_info.memmap_entries = 0;
115+
/// (start_info, vec![memmap_entry])
116116
/// }
117117
///
118118
/// fn main() {

src/lib.rs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
//! boot protocol.
2929
//!
3030
//! ```rust
31-
//!
3231
//! # extern crate linux_loader;
3332
//! # extern crate vm_memory;
3433
//! # use std::{io::{Cursor, Read}, fs::File};
@@ -47,52 +46,52 @@
4746
//!
4847
//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
4948
//! fn build_boot_params() -> (hvm_start_info, Vec<hvm_memmap_table_entry>) {
50-
//! let mut start_info = hvm_start_info::default();
51-
//! let memmap_entry = hvm_memmap_table_entry {
52-
//! addr: 0x7000,
53-
//! size: 0,
54-
//! type_: E820_RAM,
55-
//! reserved: 0,
56-
//! };
57-
//! start_info.magic = XEN_HVM_START_MAGIC_VALUE;
58-
//! start_info.version = 1;
59-
//! start_info.nr_modules = 0;
60-
//! start_info.memmap_entries = 0;
61-
//! (start_info, vec![memmap_entry])
49+
//! let mut start_info = hvm_start_info::default();
50+
//! let memmap_entry = hvm_memmap_table_entry {
51+
//! addr: 0x7000,
52+
//! size: 0,
53+
//! type_: E820_RAM,
54+
//! reserved: 0,
55+
//! };
56+
//! start_info.magic = XEN_HVM_START_MAGIC_VALUE;
57+
//! start_info.version = 1;
58+
//! start_info.nr_modules = 0;
59+
//! start_info.memmap_entries = 0;
60+
//! (start_info, vec![memmap_entry])
6261
//! }
6362
//!
6463
//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6564
//! fn main() {
66-
//! let guest_mem =
67-
//! GuestMemoryMmap::from_ranges( &[(GuestAddress(0x0), MEM_SIZE)]) .unwrap();
68-
//!
69-
//! let mut elf_pvh_image = Vec::new();
70-
//! let path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/loader/x86_64/elf/test_elfnote.bin");
71-
//! let mut file = File::open(path).unwrap();
72-
//! file.read_to_end(&mut elf_pvh_image).unwrap();
73-
//!
74-
//! // Load the kernel image.
75-
//! let loader_result = Elf::load(
76-
//! &guest_mem, None, &mut Cursor::new(&elf_pvh_image), None
77-
//! ).unwrap();
78-
//!
79-
//! // Build boot parameters.
80-
//! let (mut start_info, memmap_entries) = build_boot_params();
81-
//! // Address in guest memory where the `start_info` struct will be written.
82-
//! let start_info_addr = GuestAddress(0x6000);
83-
//! // Address in guest memory where the memory map will be written.
84-
//! let memmap_addr = GuestAddress(0x7000);
85-
//! start_info.memmap_paddr = memmap_addr.raw_value();
86-
//!
87-
//! // Write boot parameters in guest memory.
88-
//! let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
89-
//! boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
90-
//! PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_mem).unwrap();
65+
//! let guest_mem = GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), MEM_SIZE)]).unwrap();
66+
//!
67+
//! let mut elf_pvh_image = Vec::new();
68+
//! let path = concat!(
69+
//! env!("CARGO_MANIFEST_DIR"),
70+
//! "/src/loader/x86_64/elf/test_elfnote.bin"
71+
//! );
72+
//! let mut file = File::open(path).unwrap();
73+
//! file.read_to_end(&mut elf_pvh_image).unwrap();
74+
//!
75+
//! // Load the kernel image.
76+
//! let loader_result =
77+
//! Elf::load(&guest_mem, None, &mut Cursor::new(&elf_pvh_image), None).unwrap();
78+
//!
79+
//! // Build boot parameters.
80+
//! let (mut start_info, memmap_entries) = build_boot_params();
81+
//! // Address in guest memory where the `start_info` struct will be written.
82+
//! let start_info_addr = GuestAddress(0x6000);
83+
//! // Address in guest memory where the memory map will be written.
84+
//! let memmap_addr = GuestAddress(0x7000);
85+
//! start_info.memmap_paddr = memmap_addr.raw_value();
86+
//!
87+
//! // Write boot parameters in guest memory.
88+
//! let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
89+
//! boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
90+
//! PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_mem).unwrap();
9191
//! }
9292
//!
9393
//! # #[cfg(target_arch = "aarch64")]
9494
//! # fn main() {}
95-
//!
9695
//! ```
9796
//!
9897
//! [`BootConfigurator`]: trait.BootConfigurator.html

src/loader/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ unsafe impl ByteValued for bootparam::boot_params {}
206206
/// let result = load_cmdline(&gm, GuestAddress(0x1000), &cl).unwrap();
207207
/// gm.read_slice(buf.as_mut_slice(), GuestAddress(0x1000)).unwrap();
208208
/// assert_eq!(buf.as_slice(), "foo=bar\0".as_bytes());
209-
///
210209
pub fn load_cmdline<M: GuestMemory>(
211210
guest_mem: &M,
212211
guest_addr: GuestAddress,

src/loader/x86_64/bzimage/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ impl KernelLoader for BzImage {
9696
/// Some(kernel_addr),
9797
/// &mut Cursor::new(&kernel_image),
9898
/// Some(himem_start),
99-
/// ).unwrap();
99+
/// )
100+
/// .unwrap();
100101
/// ```
101102
///
102103
/// [`GuestMemory`]: https://docs.rs/vm-memory/latest/vm_memory/guest_memory/trait.GuestMemory.html

src/loader/x86_64/elf/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ impl KernelLoader for Elf {
190190
/// Some(kernel_addr),
191191
/// &mut Cursor::new(&kernel_image),
192192
/// Some(himem_start),
193-
/// ).unwrap();
193+
/// )
194+
/// .unwrap();
194195
/// ```
195196
///
196197
/// [`GuestMemory`]: https://docs.rs/vm-memory/latest/vm_memory/guest_memory/trait.GuestMemory.html

0 commit comments

Comments
 (0)