Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

object: Refactor ObjectMode into enum #114

Merged
merged 4 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:

build:
runs-on: ${{ matrix.os }}
needs: check
strategy:
matrix:
os:
Expand All @@ -33,7 +32,6 @@ jobs:

unit:
runs-on: ${{ matrix.os }}
needs: check
strategy:
matrix:
os:
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ aws-smithy-client = "0.38"
aws-smithy-http = "0.38"
aws-smithy-http-tower = "0.38"
aws-types = { version = "0.8", features = ["hardcoded-credentials"] }
bitflags = "1"
blocking = "1"
bytes = "1"
futures = { version = "0.3", features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn main() -> Result<()> {
let meta = o.metadata().await?;
if meta.path().contains("test_file") {
let mode = meta.mode();
assert!(mode.contains(ObjectMode::FILE));
assert_eq!(mode, ObjectMode::FILE);

found = true
}
Expand Down
33 changes: 26 additions & 7 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::Context;
use std::task::Poll;

use bitflags::bitflags;
use futures::future::BoxFuture;
use futures::ready;

Expand Down Expand Up @@ -185,12 +186,30 @@ impl Metadata {
}
}

bitflags! {
#[derive(Default)]
pub struct ObjectMode: u32 {
const FILE =1<<0;
const DIR = 1<<1;
const LINK = 1<<2;
/// ObjectMode represents the corresponding object's mode.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ObjectMode {
/// FILE means the object has data to read.
FILE,
/// DIR means the object can be listed.
DIR,
/// Unknown means we don't know what we can do on thi object.
Unknown,
}

impl Default for ObjectMode {
fn default() -> Self {
Self::Unknown
}
}

impl Display for ObjectMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ObjectMode::FILE => write!(f, "file"),
ObjectMode::DIR => write!(f, "dir"),
ObjectMode::Unknown => write!(f, "unknown"),
}
}
}

Expand Down
7 changes: 1 addition & 6 deletions tests/behavior/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ impl BehaviorTest {
let meta = o.metadata().await?;
if meta.path() == path {
let mode = meta.mode();
assert!(
mode.contains(ObjectMode::FILE),
"expected: {:?}, actual: {:?}",
ObjectMode::FILE,
mode
);
assert_eq!(mode, ObjectMode::FILE);

found = true
}
Expand Down