Skip to content

Commit e1c1476

Browse files
committed
From<u32> for Type
1 parent 8dbf8a9 commit e1c1476

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ fn type_bits(mode: u32) -> u32 {
4444
}
4545

4646
/// The different types of files known to this library
47+
///
48+
/// Can be constructed `From<u32>`.
49+
/// ```
50+
/// assert_eq!(unix_mode::Type::from(0o0100640), unix_mode::Type::File);
51+
/// ```
52+
///
53+
/// It is not recommended to match against the [Type::Unknown] variant.
4754
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
55+
#[non_exhaustive]
4856
pub enum Type {
4957
File,
5058
Dir,
@@ -55,16 +63,14 @@ pub enum Type {
5563
CharDevice,
5664
/// Removed file in union filesystems
5765
Whiteout,
66+
#[doc(hidden)]
5867
Unknown,
5968
}
6069

61-
impl Type {
70+
impl From<u32> for Type {
6271
/// Parse type from mode
6372
///
64-
/// ```
65-
/// assert_eq!(unix_mode::Type::from(0o0100640), unix_mode::Type::File);
66-
/// ```
67-
pub fn from(mode: u32) -> Type {
73+
fn from(mode: u32) -> Type {
6874
use Type::*;
6975
match type_bits(mode) {
7076
0o001 => Fifo,

0 commit comments

Comments
 (0)