(self)
| 67 | /// Remove any redundant flags from the open mode. |
| 68 | #[must_use] |
| 69 | pub fn reduce(self) -> Self { |
| 70 | let mut open_mode = self; |
| 71 | |
| 72 | // `t` is always redundant. |
| 73 | open_mode.remove(Self::TEXT); |
| 74 | |
| 75 | // `U` is always redundant. |
| 76 | open_mode.remove(Self::UNIVERSAL_NEWLINES); |
| 77 | |
| 78 | // `r` is redundant, unless `b` or `+` is also set, in which case, we need one of `w`, `a`, `r`, or `x`. |
| 79 | if open_mode.intersects(Self::BINARY | Self::PLUS) { |
| 80 | if !open_mode.intersects(Self::WRITE | Self::CREATE | Self::APPEND) { |
| 81 | open_mode.insert(Self::READ); |
| 82 | } |
| 83 | } else { |
| 84 | open_mode.remove(Self::READ); |
| 85 | } |
| 86 | |
| 87 | open_mode |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /// Write the [`OpenMode`] as a string. |
no test coverage detected