git.delta.rocks / unique-network / refs/commits / fd6af7529aa7

difftreelog

fix force_value in LazyValue

Daniel Shiposha2023-10-03parent: #e48f2d1.patch.diff
in: master

1 file changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
888888
889 /// Get the value. If it is called the first time, the value will be initialized.889 /// Get the value. If it is called the first time, the value will be initialized.
890 pub fn value(&mut self) -> &T {890 pub fn value(&mut self) -> &T {
891 self.compute_value_if_not_already();891 self.force_value();
892 self.value.as_ref().unwrap()892 self.value.as_ref().unwrap()
893 }893 }
894894
895 /// Get the value. If it is called the first time, the value will be initialized.895 /// Get the value. If it is called the first time, the value will be initialized.
896 pub fn value_mut(&mut self) -> &mut T {896 pub fn value_mut(&mut self) -> &mut T {
897 self.compute_value_if_not_already();897 self.force_value();
898 self.value.as_mut().unwrap()898 self.value.as_mut().unwrap()
899 }899 }
900900
901 fn into_inner(mut self) -> T {901 fn into_inner(mut self) -> T {
902 self.compute_value_if_not_already();902 self.force_value();
903 self.value.unwrap()903 self.value.unwrap()
904 }904 }
905905
908 self.value.is_some()908 self.value.is_some()
909 }909 }
910910
911 fn compute_value_if_not_already(&mut self) {911 fn force_value(&mut self) {
912 if self.value.is_none() {912 if self.value.is_none() {
913 self.value = Some(self.f.take().unwrap()())913 self.value = Some(self.f.take().unwrap()())
914 }914 }