cap_primitives/fs/follow_symlinks.rs
1/// Should symlinks be followed in the last component of a path?
2///
3/// This doesn't affect path components other than the last. So for example in
4/// "foo/bar/baz", if "foo" or "bar" are symlinks, they will always be
5/// followed. This enum value only determines whether "baz" is followed.
6///
7/// Instead of passing bare `bool`s as parameters, pass a distinct enum so that
8/// the intent is clear.
9#[derive(Copy, Clone, Debug, Eq, PartialEq)]
10#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
11pub enum FollowSymlinks {
12 /// Yes, do follow symlinks in the last component of a path.
13 Yes,
14
15 /// No, do not follow symlinks in the last component of a path.
16 No,
17}
18
19impl FollowSymlinks {
20 /// Convert a bool where true means "follow" and false means "don't follow"
21 /// to a `FollowSymlinks`.
22 #[inline]
23 pub const fn follow(follow: bool) -> Self {
24 if follow {
25 Self::Yes
26 } else {
27 Self::No
28 }
29 }
30}