Skip to content

Commit 0afc3a6

Browse files
committed
refactor: 🎨 defaul to Some(T)
1 parent 4ec0e7b commit 0afc3a6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

crates/rspack_core/src/compilation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl Compilation {
428428
module_executor,
429429
in_finish_make: AtomicBool::new(false),
430430

431-
build_module_graph_artifact: BuildModuleGraphArtifact::default().into(),
431+
build_module_graph_artifact: Default::default(),
432432
modified_files,
433433
removed_files,
434434
input_filesystem,

crates/rspack_core/src/utils/deref_option.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ use std::{
33
ops::{Deref, DerefMut},
44
};
55

6-
#[derive(Debug, Default)]
6+
#[derive(Debug)]
77
pub struct DerefOption<T>(Option<T>);
88

9+
impl<T> Default for DerefOption<T>
10+
where
11+
T: Default,
12+
{
13+
fn default() -> Self {
14+
Self(Some(T::default()))
15+
}
16+
}
17+
918
impl<T> From<T> for DerefOption<T> {
1019
fn from(value: T) -> Self {
1120
Self::new(value)
@@ -40,10 +49,7 @@ impl<T> Deref for DerefOption<T> {
4049
.unwrap_or_else(|| panic!("should set in compilation first"))
4150
}
4251
}
43-
impl<T> DerefMut for DerefOption<T>
44-
where
45-
T: Debug,
46-
{
52+
impl<T> DerefMut for DerefOption<T> {
4753
fn deref_mut(&mut self) -> &mut Self::Target {
4854
self
4955
.0

0 commit comments

Comments
 (0)