use super::error::Problems;
use super::fields::Fields;
use super::name::is_name;
use crate::api_version::{ApiRequirement, ApiVersion};
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct AdapterPart {
pub tools: Vec<String>,
}
impl AdapterPart {
pub(crate) fn read(mut fields: Fields, problems: &mut Problems) -> Option<Self> {
let tools = fields.strings_matching(
"tools",
is_tool_name,
"must be a tool name: a lower-case letter, then lower-case letters, digits and `-`, \
in 64 characters at most",
problems,
);
fields.finish(problems);
Some(Self { tools })
}
}
const FIRST_API_VERSION: ApiVersion = ApiVersion {
major: 0,
minor: 1,
patch: 1,
};
pub(crate) fn require_api(api: ApiRequirement, problems: &mut Problems) {
let minimum = api.minimum();
let first = FIRST_API_VERSION;
if (minimum.major, minimum.minor, minimum.patch) < (first.major, first.minor, first.patch) {
let problem = format!(
"must be `^{first}` or later: the `[adapter]` table needs the extension API version {first}"
);
problems.add("extension.api".to_owned(), problem);
}
}
fn is_tool_name(name: &str) -> bool {
name.len() <= 64 && is_name(name)
}