MCPcopy Create free account
hub / github.com/chyyuu/os_kernel_lab / get_mut

Method get_mut

easy-fs/src/block_cache.rs:44–53  ·  view source on GitHub ↗
(&mut self, offset: usize)

Source from the content-addressed store, hash-verified

42 }
43
44 pub fn get_mut<T>(&mut self, offset: usize) -> &mut T
45 where
46 T: Sized,
47 {
48 let type_size = core::mem::size_of::<T>();
49 assert!(offset + type_size <= BLOCK_SZ);
50 self.modified = true;
51 let addr = self.addr_of_offset(offset);
52 unsafe { &mut *(addr as *mut T) }
53 }
54
55 pub fn read<T, V>(&self, offset: usize, f: impl FnOnce(&T) -> V) -> V {
56 f(self.get_ref(offset))

Callers 1

modifyMethod · 0.45

Calls 1

addr_of_offsetMethod · 0.80

Tested by

no test coverage detected