edgehog_device_runtime/repository/mod.rs
1/*
2 * This file is part of Edgehog.
3 *
4 * Copyright 2022 SECO Mind Srl
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * SPDX-License-Identifier: Apache-2.0
19 */
20
21use std::error::Error;
22
23use async_trait::async_trait;
24#[cfg(test)]
25use mockall::automock;
26
27pub(crate) mod file_state_repository;
28
29#[cfg_attr(test, automock(type Err = self::file_state_repository::FileStateError;))]
30#[async_trait]
31pub trait StateRepository<T: Send + Sync>: Send + Sync {
32 type Err: Error;
33
34 async fn write(&self, value: &T) -> Result<(), Self::Err>;
35 async fn read(&self) -> Result<T, Self::Err>;
36 async fn exists(&self) -> bool;
37 async fn clear(&self) -> Result<(), Self::Err>;
38}