Skip to main content

harmos_domain/operations/storage/
follow_file.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17
18// Third Party Imports
19
20// Local Imports
21use super::IO_POLICY;
22use crate::MemorySize;
23use crate::model::storage::codec::{Nested, product};
24use crate::model::storage::files::{FileCompletion, FileEvent, FileSource, FollowStart};
25use crate::operations::Visibility;
26
27/* === Constants === */
28
29/* === Macros === */
30
31product!(FollowFile {
32    source: Nested<FileSource> => 1,
33    start: Nested<FollowStart> => 2,
34});
35
36crate::declare!(FollowFile {
37    id: "storage.follow_file",
38    version: 1,
39    policy: IO_POLICY,
40    response: FileCompletion,
41    output: FileEvent,
42    visibility: Visibility::Shared,
43    grpc: ("harmos.storage.v1", "Storage", "FollowFile"),
44    grant: |request: &FollowFile| request.source.grant_scope().map(|scope| crate::plugin::Grant::of("storage.follow_file", scope)),
45});
46
47/* === Type Aliases === */
48
49/* === Structs === */
50
51#[derive(Clone, Debug, PartialEq, Eq)]
52pub struct FollowFile {
53    pub source: FileSource,
54    pub start: FollowStart,
55}
56
57/* === Enums === */
58
59/* === Traits === */
60
61/* === Implementations === */
62
63impl MemorySize for FollowFile {
64    fn memory_size(&self) -> usize {
65        std::mem::size_of::<Self>()
66            .saturating_add(self.source.memory_size().saturating_sub(std::mem::size_of_val(&self.source)))
67            .saturating_add(self.start.memory_size().saturating_sub(std::mem::size_of_val(&self.start)))
68    }
69}
70
71/* === Public Functions === */
72
73/* === Private Functions === */
74
75/* === Tests === */