@@ -49,18 +49,22 @@ impl<T> CtOption<T> {
4949 /// Construct a new [`CtOption`], with a [`Choice`] parameter `is_some` as a stand-in for
5050 /// `Some` or `None` enum variants of a typical [`Option`] type.
5151 #[ inline]
52+ #[ must_use]
5253 pub const fn new ( value : T , is_some : Choice ) -> CtOption < T > {
5354 Self { value, is_some }
5455 }
5556
5657 /// Construct a new [`CtOption`] where `self.is_some()` is [`Choice::TRUE`].
5758 #[ inline]
59+ #[ must_use]
5860 pub const fn some ( value : T ) -> CtOption < T > {
5961 Self :: new ( value, Choice :: TRUE )
6062 }
6163
6264 /// Construct a new [`CtOption`] with the [`Default`] value, and where `self.is_some()` is
6365 /// [`Choice::FALSE`].
66+ #[ inline]
67+ #[ must_use]
6468 pub fn none ( ) -> CtOption < T >
6569 where
6670 T : Default ,
@@ -70,6 +74,7 @@ impl<T> CtOption<T> {
7074
7175 /// Convert from a `&mut CtOption<T>` to `CtOption<&mut T>`.
7276 #[ inline]
77+ #[ must_use]
7378 pub const fn as_mut ( & mut self ) -> CtOption < & mut T > {
7479 CtOption {
7580 value : & mut self . value ,
@@ -79,6 +84,7 @@ impl<T> CtOption<T> {
7984
8085 /// Convert from a `&CtOption<T>` to `CtOption<&T>`.
8186 #[ inline]
87+ #[ must_use]
8288 pub const fn as_ref ( & self ) -> CtOption < & T > {
8389 CtOption {
8490 value : & self . value ,
@@ -88,6 +94,8 @@ impl<T> CtOption<T> {
8894
8995 /// Convert from `CtOption<T>` (or `&CtOption<T>`) to `CtOption<&T::Target>`, for types which
9096 /// impl the [`Deref`] trait.
97+ #[ inline]
98+ #[ must_use]
9199 pub fn as_deref ( & self ) -> CtOption < & T :: Target >
92100 where
93101 T : Deref ,
@@ -97,6 +105,8 @@ impl<T> CtOption<T> {
97105
98106 /// Convert from `CtOption<T>` (or `&mut CtOption<T>`) to `CtOption<&mut T::Target>`, for types
99107 /// which impl the [`DerefMut`] trait.
108+ #[ inline]
109+ #[ must_use]
100110 pub fn as_deref_mut ( & mut self ) -> CtOption < & mut T :: Target >
101111 where
102112 T : DerefMut ,
@@ -110,6 +120,7 @@ impl<T> CtOption<T> {
110120 /// In the event `self.is_some()` is [`Choice::FALSE`], panics with a custom panic message
111121 /// provided as the `msg` argument.
112122 #[ inline]
123+ #[ must_use]
113124 #[ track_caller]
114125 pub fn expect ( self , msg : & str ) -> T {
115126 assert ! ( self . is_some( ) . to_bool( ) , "{}" , msg) ;
@@ -127,6 +138,7 @@ impl<T> CtOption<T> {
127138 // TODO(tarcieri): get rid of this when we can make `expect` a `const fn`
128139 // (needs `const_precise_live_drops`)
129140 #[ inline]
141+ #[ must_use]
130142 #[ track_caller]
131143 pub const fn expect_copied ( self , msg : & str ) -> T
132144 where
@@ -143,6 +155,7 @@ impl<T> CtOption<T> {
143155 // TODO(tarcieri): get rid of this when we can make `expect` a `const fn`
144156 // (needs `const_precise_live_drops`)
145157 #[ inline]
158+ #[ must_use]
146159 #[ track_caller]
147160 pub const fn expect_ref ( & self , msg : & str ) -> & T {
148161 // TODO(tarcieri): use `self.is_some().to_bool()` when MSRV is 1.86
@@ -234,6 +247,7 @@ impl<T> CtOption<T> {
234247 /// Returns `optb` if `self.is_some()` is [`Choice::TRUE`], otherwise returns a [`CtOption`]
235248 /// where `self.is_some()` is [`Choice::FALSE`].
236249 #[ inline]
250+ #[ must_use]
237251 pub fn and < U > ( self , mut optb : CtOption < U > ) -> CtOption < U > {
238252 optb. is_some &= self . is_some ;
239253 optb
@@ -248,6 +262,7 @@ impl<T> CtOption<T> {
248262 /// (e.g. if the [`CtOption`] was constructed with a supplied placeholder value and
249263 /// [`Choice::FALSE`], the placeholder value will be provided).
250264 #[ inline]
265+ #[ must_use]
251266 pub fn and_then < U , F > ( self , f : F ) -> CtOption < U >
252267 where
253268 F : FnOnce ( T ) -> CtOption < U > ,
@@ -271,6 +286,7 @@ impl<T> CtOption<T> {
271286 /// take great care to ensure that `self.is_some()` is checked elsewhere.
272287 /// </div>
273288 #[ inline]
289+ #[ must_use]
274290 pub const fn as_inner_unchecked ( & self ) -> & T {
275291 & self . value
276292 }
@@ -281,6 +297,7 @@ impl<T> CtOption<T> {
281297 /// It updates it to be [`Choice::FALSE`] in the event the returned choice is also false.
282298 /// If it was [`Choice::FALSE`] to begin with, it will unconditionally remain that way.
283299 #[ inline]
300+ #[ must_use]
284301 pub fn filter < P > ( mut self , predicate : P ) -> Self
285302 where
286303 P : FnOnce ( & T ) -> Choice ,
@@ -291,6 +308,7 @@ impl<T> CtOption<T> {
291308
292309 /// Apply an additional [`Choice`] requirement to `is_some`.
293310 #[ inline]
311+ #[ must_use]
294312 pub const fn filter_by ( mut self , is_some : Choice ) -> Self {
295313 self . is_some = self . is_some . and ( is_some) ;
296314 self
@@ -299,6 +317,7 @@ impl<T> CtOption<T> {
299317 /// Maps a `CtOption<T>` to a `CtOption<U>` by unconditionally applying a function to the
300318 /// contained `value`, but returning a new option value which inherits `self.is_some()`.
301319 #[ inline]
320+ #[ must_use]
302321 pub fn map < U , F > ( self , f : F ) -> CtOption < U >
303322 where
304323 F : FnOnce ( T ) -> U ,
@@ -322,6 +341,7 @@ impl<T> CtOption<T> {
322341 /// `U::default()` using the [`Default`] trait, and returning it in the event `self.is_some()`
323342 /// is [`Choice::FALSE`].
324343 #[ inline]
344+ #[ must_use]
325345 pub fn map_or_default < U , F > ( self , f : F ) -> U
326346 where
327347 U : CtSelect + Default ,
@@ -364,6 +384,7 @@ impl<T> CtOption<T> {
364384
365385 /// Returns `self` if `self.is_some()` is [`Choice::TRUE`], otherwise returns `optb`.
366386 #[ inline]
387+ #[ must_use]
367388 pub fn or ( self , optb : CtOption < T > ) -> CtOption < T >
368389 where
369390 T : CtSelect ,
@@ -388,6 +409,7 @@ impl<T> CtOption<T> {
388409 /// take great care to ensure that `self.is_some()` is checked elsewhere.
389410 /// </div>
390411 #[ inline]
412+ #[ must_use]
391413 pub const fn to_inner_unchecked ( self ) -> T
392414 where
393415 T : Copy ,
@@ -410,6 +432,8 @@ impl<T> CtOption<T> {
410432 /// # Panics
411433 /// In the event `self.is_some()` is [`Choice::FALSE`].
412434 #[ inline]
435+ #[ must_use]
436+ #[ track_caller]
413437 pub fn unwrap ( self ) -> T {
414438 assert ! (
415439 self . is_some. to_bool( ) ,
@@ -421,6 +445,7 @@ impl<T> CtOption<T> {
421445 /// Return the contained value in the event `self.is_some()` is [`Choice::TRUE`], or if not,
422446 /// uses a provided default.
423447 #[ inline]
448+ #[ must_use]
424449 pub fn unwrap_or ( self , default : T ) -> T
425450 where
426451 T : CtSelect ,
@@ -432,6 +457,7 @@ impl<T> CtOption<T> {
432457 /// the contained value if `self.is_some()` is [`Choice::TRUE`], or if it's [`Choice::FALSE`]
433458 /// returns the previously computed default.
434459 #[ inline]
460+ #[ must_use]
435461 pub fn unwrap_or_default ( self ) -> T
436462 where
437463 T : CtSelect + Default ,
@@ -443,6 +469,7 @@ impl<T> CtOption<T> {
443469 /// the event exactly one of them has `self.is_some()` set to [`Choice::TRUE`], or else returns
444470 /// a [`CtOption`] with `self.is_some()` set to [`Choice::FALSE`].
445471 #[ inline]
472+ #[ must_use]
446473 pub fn xor ( self , optb : CtOption < T > ) -> CtOption < T >
447474 where
448475 T : CtSelect ,
@@ -694,7 +721,7 @@ mod tests {
694721 #[ test]
695722 #[ should_panic]
696723 fn expect_none ( ) {
697- NONE . expect ( "should panic" ) ;
724+ let _ = NONE . expect ( "should panic" ) ;
698725 }
699726
700727 #[ test]
@@ -834,7 +861,7 @@ mod tests {
834861 #[ test]
835862 #[ should_panic]
836863 fn unwrap_none ( ) {
837- NONE . unwrap ( ) ;
864+ let _ = NONE . unwrap ( ) ;
838865 }
839866
840867 #[ test]
0 commit comments