1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Generic implementations for some libcnb types.

use crate::platform::Platform;
use crate::{read_platform_env, Env};
use std::fmt::{Debug, Display, Formatter};
use std::path::Path;

pub use libcnb_data::generic::GenericMetadata;

#[derive(Debug)]
pub enum GenericError {}

impl Display for GenericError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str("GenericError")
    }
}

/// A generic platform that only provides access to environment variables.
pub struct GenericPlatform {
    env: Env,
}

impl GenericPlatform {
    #[must_use]
    pub fn new(env: Env) -> Self {
        Self { env }
    }
}

impl Platform for GenericPlatform {
    fn env(&self) -> &Env {
        &self.env
    }

    fn from_path(platform_dir: impl AsRef<Path>) -> std::io::Result<Self> {
        read_platform_env(platform_dir.as_ref()).map(|env| Self { env })
    }
}