thfmr_util/lib.rs
1//! The `thfmr-util` crate provides several utility functions and traits used by the
2//! TouHou.FM Radio project.
3
4pub mod graphql;
5
6/// A trait to define the ability to drop a result.
7///
8/// This can be used when the return type of a [core::result::Result] is not interesting. In
9/// particular, this can be used with [try_join!] which returns a [core::result::Result] with
10/// a tuple of all original [core::result::Result] values. When the original [core::result::Result]s
11/// were all `()`, this trait can be used to simplify the return value by calling
12/// [DropResult::drop_result]
13pub trait DropResult<T, E> {
14 /// Drops the result from a [core::result::Result], turning it into `()`
15 fn drop_result(self) -> core::result::Result<(), E>;
16}
17
18/// Implementation of DropResult for all [core::result::Result] types
19impl<T, E> DropResult<T, E> for core::result::Result<T, E> {
20 /// Drops the result from a [core::result::Result], turning it into `()`
21 #[inline]
22 fn drop_result(self) -> core::result::Result<(), E> {
23 self.map(|_| ())
24 }
25}