Skip to content

Commit

Permalink
platform/storage: add some basic traits (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
huachaohuang committed Oct 24, 2021
1 parent 1d8e709 commit 027b59a
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 5 deletions.
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["src/engula"]
members = ["src/platform/storage"]
3 changes: 2 additions & 1 deletion src/engula/Cargo.toml → src/platform/storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "engula"
name = "engula-platform-storage"
version = "0.1.0"
edition = "2021"

[dependencies]
async-trait = "0.1"
24 changes: 24 additions & 0 deletions src/platform/storage/src/bucket_handle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 The Engula Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use async_trait::async_trait;

use crate::{error::StorageResult, object_handle::ObjectHandle};

#[async_trait]
pub trait BucketHandle {
fn object(&self, name: &str) -> Box<dyn ObjectHandle>;

async fn delete_object(&self, name: &str) -> StorageResult<()>;
}
17 changes: 17 additions & 0 deletions src/platform/storage/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2021 The Engula Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub struct StorageError {}

pub type StorageResult<T> = Result<T, StorageError>;
25 changes: 25 additions & 0 deletions src/platform/storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2021 The Engula Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

mod bucket_handle;
mod error;
mod object_handle;
mod object_storage;

pub use self::{
bucket_handle::BucketHandle,
error::{StorageError, StorageResult},
object_handle::ObjectHandle,
object_storage::ObjectStorage,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

fn main() {
println!("Hello, world!");
}
use async_trait::async_trait;

#[async_trait]
pub trait ObjectHandle {}
26 changes: 26 additions & 0 deletions src/platform/storage/src/object_storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 The Engula Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use async_trait::async_trait;

use crate::{bucket_handle::BucketHandle, error::StorageResult};

#[async_trait]
pub trait ObjectStorage {
fn bucket(&self, name: &str) -> Box<dyn BucketHandle>;

async fn create_bucket(&self, name: &str) -> StorageResult<()>;

async fn delete_bucket(&self, name: &str) -> StorageResult<()>;
}

0 comments on commit 027b59a

Please sign in to comment.