Skip to content

Commit ff07d75

Browse files
committed
Remove unwrap
1 parent 285c66f commit ff07d75

File tree

1 file changed

+24
-39
lines changed

1 file changed

+24
-39
lines changed

src/opamp.rs

+24-39
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,21 @@ pub struct Disabled<Opamp> {
104104
pub struct Follower<Opamp, Input, Output> {
105105
opamp: PhantomData<Opamp>,
106106
input: Input,
107-
output: Option<Output>,
107+
output: Output,
108108
}
109109
/// State type for opamp running in open-loop mode.
110110
pub struct OpenLoop<Opamp, NonInverting, Inverting, Output> {
111111
opamp: PhantomData<Opamp>,
112112
non_inverting: NonInverting,
113113
inverting: Inverting,
114-
output: Option<Output>,
114+
output: Output,
115115
}
116116
/// State type for opamp running in programmable-gain mode.
117117
pub struct Pga<Opamp, NonInverting, MODE, Output> {
118118
opamp: PhantomData<Opamp>,
119119
non_inverting: PhantomData<NonInverting>,
120120
config: MODE,
121-
output: Option<Output>,
121+
output: Output,
122122
}
123123
/// State type for an opamp that has been locked.
124124
pub struct Locked<Opamp, Output> {
@@ -277,24 +277,19 @@ macro_rules! opamps {
277277
/// Disables the opamp and returns the resources it held.
278278
pub fn disable(self) -> (Disabled<$opamp>, Input, $output) {
279279
unsafe { $opamp::_reset() };
280-
// Safe to unwrap `self.output` because `self.output` is only None
281-
// when the Output type is InternalOutput
282-
(Disabled { opamp: PhantomData }, self.input, self.output.unwrap())
280+
(Disabled { opamp: PhantomData }, self.input, self.output)
283281
}
284282

285283
/// Disables the external output.
286284
/// This will connect the opamp output to the internal ADC.
287285
/// If the output was enabled, the output pin is returned.
288-
pub fn disable_output(mut self) -> (Follower<$opamp, Input, InternalOutput>, $output) {
286+
pub fn disable_output(self) -> (Follower<$opamp, Input, InternalOutput>, $output) {
289287
unsafe { $opamp::_disable_output(); }
290-
291-
// Safe to unwrap `self.output` because `self.output` is only None
292-
// when the Output type is InternalOutput
293288
(Follower::<$opamp, Input, InternalOutput> {
294289
opamp: PhantomData,
295290
input: self.input,
296-
output: None,
297-
}, self.output.take().unwrap())
291+
output: InternalOutput,
292+
}, self.output)
298293
}
299294

300295
/// Set the lock bit in the registers. After the lock bit is
@@ -320,7 +315,7 @@ macro_rules! opamps {
320315
Follower::<$opamp, Input, $output> {
321316
opamp: PhantomData,
322317
input: self.input,
323-
output: Some(output),
318+
output,
324319
}
325320
}
326321

@@ -337,25 +332,20 @@ macro_rules! opamps {
337332
/// Disables the opamp and returns the resources it held.
338333
pub fn disable(self) -> (Disabled<$opamp>, NonInverting, Inverting, $output) {
339334
unsafe { $opamp::_reset() };
340-
// Safe to unwrap `self.output` because `self.output` is only None
341-
// when the Output type is InternalOutput
342-
(Disabled { opamp: PhantomData }, self.non_inverting, self.inverting, self.output.unwrap())
335+
(Disabled { opamp: PhantomData }, self.non_inverting, self.inverting, self.output)
343336
}
344337

345338
/// Disables the external output.
346339
/// This will connect the opamp output to the internal ADC.
347340
/// If the output was enabled, the output pin is returned.
348-
pub fn disable_output(mut self) -> (OpenLoop<$opamp, NonInverting, Inverting, InternalOutput>, $output) {
341+
pub fn disable_output(self) -> (OpenLoop<$opamp, NonInverting, Inverting, InternalOutput>, $output) {
349342
unsafe { $opamp::_disable_output(); }
350-
351-
// Safe to unwrap `self.output` because `self.output` is only None
352-
// when the Output type is InternalOutput
353343
(OpenLoop::<$opamp, NonInverting, Inverting, InternalOutput> {
354344
opamp: PhantomData,
355345
inverting: self.inverting,
356346
non_inverting: self.non_inverting,
357-
output: None,
358-
}, self.output.take().unwrap())
347+
output: InternalOutput,
348+
}, self.output)
359349
}
360350

361351
/// Set the lock bit in the registers. After the lock bit is
@@ -382,7 +372,7 @@ macro_rules! opamps {
382372
opamp: PhantomData,
383373
inverting: self.inverting,
384374
non_inverting: self.non_inverting,
385-
output: Some(output),
375+
output,
386376
}
387377
}
388378

@@ -399,24 +389,19 @@ macro_rules! opamps {
399389
/// Disables the opamp and returns the resources it held.
400390
pub fn disable(self) -> (Disabled<$opamp>, MODE, $output) {
401391
unsafe { $opamp::_reset() };
402-
// Safe to unwrap `self.output` because `self.output` is only None
403-
// when the Output type is InternalOutput
404-
(Disabled { opamp: PhantomData }, self.config, self.output.unwrap())
392+
(Disabled { opamp: PhantomData }, self.config, self.output)
405393
}
406394

407395
/// Disables the external output.
408396
/// This will connect the opamp output to the internal ADC.
409-
pub fn disable_output(mut self) -> (Pga<$opamp, NonInverting, MODE, InternalOutput>, $output) {
397+
pub fn disable_output(self) -> (Pga<$opamp, NonInverting, MODE, InternalOutput>, $output) {
410398
unsafe { $opamp::_disable_output(); }
411-
412-
// Safe to unwrap `self.output` because `self.output` is only None
413-
// when the Output type is InternalOutput
414399
(Pga::<$opamp, NonInverting, MODE, InternalOutput> {
415400
opamp: PhantomData,
416401
non_inverting: self.non_inverting,
417402
config: self.config,
418-
output: None,
419-
}, self.output.take().unwrap())
403+
output: InternalOutput,
404+
}, self.output)
420405
}
421406

422407
/// Set the lock bit in the registers. After the lock bit is
@@ -443,7 +428,7 @@ macro_rules! opamps {
443428
opamp: PhantomData,
444429
non_inverting: self.non_inverting,
445430
config: self.config,
446-
output: Some(output),
431+
output,
447432
}
448433
}
449434

@@ -532,7 +517,7 @@ macro_rules! opamps {
532517
.enabled()
533518
);
534519
}
535-
Follower {opamp: PhantomData, input, output: Some(output)}
520+
Follower {opamp: PhantomData, input, output}
536521
}
537522
}
538523

@@ -562,7 +547,7 @@ macro_rules! opamps {
562547
.enabled()
563548
);
564549
}
565-
Follower {opamp: PhantomData, input, output: None}
550+
Follower {opamp: PhantomData, input, output: InternalOutput}
566551
}
567552
}
568553

@@ -630,7 +615,7 @@ macro_rules! opamps {
630615
.enabled()
631616
);
632617
}
633-
OpenLoop {opamp: PhantomData, non_inverting, inverting, output: Some(output)}
618+
OpenLoop {opamp: PhantomData, non_inverting, inverting, output}
634619
}
635620
}
636621
impl <IntoNonInverting, IntoInverting> IntoOpenLoop
@@ -662,7 +647,7 @@ macro_rules! opamps {
662647
.enabled()
663648
);
664649
}
665-
OpenLoop {opamp: PhantomData, non_inverting, inverting, output: None}
650+
OpenLoop {opamp: PhantomData, non_inverting, inverting, output: InternalOutput}
666651
}
667652
}
668653
)*
@@ -729,7 +714,7 @@ macro_rules! opamps {
729714
.enabled()
730715
);
731716
}
732-
Pga {opamp: PhantomData, non_inverting: PhantomData, config, output: Some(output)}
717+
Pga {opamp: PhantomData, non_inverting: PhantomData, config, output}
733718
}
734719
}
735720
impl IntoPga<$opamp, $mode, InternalOutput, $non_inverting, InternalOutput> for Disabled<$opamp>
@@ -758,7 +743,7 @@ macro_rules! opamps {
758743
.enabled()
759744
);
760745
}
761-
Pga {opamp: PhantomData, non_inverting: PhantomData, config, output: None}
746+
Pga {opamp: PhantomData, non_inverting: PhantomData, config, output: InternalOutput}
762747
}
763748
}
764749
}

0 commit comments

Comments
 (0)