settings/storage.rs
1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! This module contains types used for sending and receiving messages to and from the storage
6//! agent.
7
8use crate::base::{SettingInfo, SettingType};
9use fuchsia_trace as ftrace;
10use settings_storage::UpdateState;
11
12/// `Payload` wraps the request and response payloads.
13#[derive(Clone, PartialEq, Debug)]
14pub enum Payload {
15 Request(StorageRequest),
16 Response(StorageResponse),
17}
18
19/// `StorageRequest` contains all of the requests that can be made to the storage agent.
20#[derive(Clone, PartialEq, Debug)]
21pub enum StorageRequest {
22 /// A read requests for the corresponding [`StorageInfo`] of this `StorageType`.
23 Read(StorageType, ftrace::Id),
24 /// A write requests for this [`StorageInfo`].
25 Write(StorageInfo, ftrace::Id),
26}
27
28#[derive(Clone, PartialEq, Debug)]
29pub enum StorageType {
30 SettingType(SettingType),
31}
32
33impl From<SettingType> for StorageType {
34 fn from(setting_type: SettingType) -> Self {
35 StorageType::SettingType(setting_type)
36 }
37}
38
39#[derive(Clone, PartialEq, Debug)]
40pub enum StorageInfo {
41 SettingInfo(SettingInfo),
42}
43
44impl From<SettingInfo> for StorageInfo {
45 fn from(setting_info: SettingInfo) -> Self {
46 StorageInfo::SettingInfo(setting_info)
47 }
48}
49
50/// `StorageResponse` contains the corresponding result types to the matching [`StorageRequest`]
51/// variants of the same name.
52#[derive(Clone, PartialEq, Debug)]
53pub enum StorageResponse {
54 /// The storage info read from storage in response to a [`StorageRequest::Read`]
55 Read(StorageInfo),
56 /// The result of a write request with either the [`UpdateState`] after a successful write
57 /// or a formatted error describing why the write could not occur.
58 Write(Result<UpdateState, Error>),
59}
60
61/// `Error` encapsulates a formatted error the occurs due to write failures.
62#[derive(Clone, PartialEq, Debug)]
63pub struct Error {
64 /// The error message.
65 pub message: String,
66}