Skip to content

Commit 1e56fdc

Browse files
committed
feat: 为 ChoiceBlock 添加默认实现,简化实例化过程
1 parent 07eb687 commit 1e56fdc

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

kconfig-serde/src/converter.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ impl KconfigConverter {
6666
}
6767

6868
fn end_menu_block(&mut self) -> Option<MenuBlock> {
69-
if let Some(menu) = self.menu_stack.pop() {
70-
// Add the completed menu to elements
71-
Some(menu)
72-
} else {
73-
None
74-
}
69+
self.menu_stack.pop().map(|menu| menu)
7570
}
7671

7772
fn add_config_option(&mut self, config: ConfigOption) {
@@ -92,7 +87,7 @@ impl Default for KconfigConverter {
9287
}
9388
}
9489

95-
impl<'a> ser::Serializer for &'a mut KconfigConverter {
90+
impl ser::Serializer for &mut KconfigConverter {
9691
type Ok = ();
9792
type Error = crate::error::Error;
9893

@@ -301,7 +296,7 @@ impl<'a> ser::Serializer for &'a mut KconfigConverter {
301296
}
302297
}
303298

304-
impl<'a> ser::SerializeMap for &'a mut KconfigConverter {
299+
impl ser::SerializeMap for &mut KconfigConverter {
305300
type Ok = ();
306301
type Error = crate::error::Error;
307302

@@ -321,7 +316,7 @@ impl<'a> ser::SerializeMap for &'a mut KconfigConverter {
321316
}
322317
}
323318

324-
impl<'a> ser::SerializeStruct for &'a mut KconfigConverter {
319+
impl ser::SerializeStruct for &mut KconfigConverter {
325320
type Ok = ();
326321
type Error = crate::error::Error;
327322

@@ -348,7 +343,7 @@ impl<'a> ser::SerializeStruct for &'a mut KconfigConverter {
348343
}
349344
}
350345

351-
impl<'a> ser::SerializeSeq for &'a mut KconfigConverter {
346+
impl ser::SerializeSeq for &mut KconfigConverter {
352347
type Ok = ();
353348
type Error = crate::error::Error;
354349

@@ -363,7 +358,7 @@ impl<'a> ser::SerializeSeq for &'a mut KconfigConverter {
363358
}
364359
}
365360

366-
impl<'a> ser::SerializeTuple for &'a mut KconfigConverter {
361+
impl ser::SerializeTuple for &mut KconfigConverter {
367362
type Ok = ();
368363
type Error = crate::error::Error;
369364

@@ -376,7 +371,7 @@ impl<'a> ser::SerializeTuple for &'a mut KconfigConverter {
376371
}
377372
}
378373

379-
impl<'a> ser::SerializeTupleStruct for &'a mut KconfigConverter {
374+
impl ser::SerializeTupleStruct for &mut KconfigConverter {
380375
type Ok = ();
381376
type Error = crate::error::Error;
382377

@@ -389,7 +384,7 @@ impl<'a> ser::SerializeTupleStruct for &'a mut KconfigConverter {
389384
}
390385
}
391386

392-
impl<'a> ser::SerializeTupleVariant for &'a mut KconfigConverter {
387+
impl ser::SerializeTupleVariant for &mut KconfigConverter {
393388
type Ok = ();
394389
type Error = crate::error::Error;
395390

@@ -402,7 +397,7 @@ impl<'a> ser::SerializeTupleVariant for &'a mut KconfigConverter {
402397
}
403398
}
404399

405-
impl<'a> ser::SerializeStructVariant for &'a mut KconfigConverter {
400+
impl ser::SerializeStructVariant for &mut KconfigConverter {
406401
type Ok = ();
407402
type Error = crate::error::Error;
408403

kconfig-serde/src/elements.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ pub struct ChoiceBlock {
172172
pub elements: Vec<String>, // config names
173173
}
174174

175+
impl Default for ChoiceBlock {
176+
fn default() -> Self {
177+
Self::new()
178+
}
179+
}
180+
175181
impl ChoiceBlock {
176182
pub fn new() -> Self {
177183
Self {

0 commit comments

Comments
 (0)