Skip to main content

ephemeris_release/adapters/
version_file.rs

1//! Plain files that hold nothing but a semantic version.
2
3use std::path::Path;
4
5use super::holder::HolderError;
6
7/// The version in `text`, which must be one line.
8pub(super) fn read(path: &Path, text: &str) -> Result<String, HolderError> {
9    let version = text.trim();
10    if version.is_empty() || version.lines().count() != 1 {
11        return Err(HolderError::Malformed {
12            path: path.to_path_buf(),
13        });
14    }
15    Ok(version.to_owned())
16}
17
18pub(super) fn render(version: &str) -> Vec<u8> {
19    format!("{version}\n").into_bytes()
20}