use mf2_catalog::Dir;
use mf2_runtime::Registry;
use crate::LanguageMatching;
#[derive(Clone, Copy, Debug)]
pub struct Corpus {
source_locale: &'static str,
manifest_hash: u64,
locales: &'static [(&'static str, Dir)],
registry: &'static Registry,
catalogs: &'static [CatalogFile],
#[cfg_attr(
not(feature = "native"),
allow(dead_code, reason = "read by `mf2::native`")
)]
language_matching: Option<&'static LanguageMatching>,
}
#[derive(Clone, Copy, Debug)]
pub struct CatalogFile {
tag: &'static str,
file_name: &'static str,
bytes: Option<&'static [u8]>,
}
impl Corpus {
#[doc(hidden)]
#[must_use]
pub const fn new(
source_locale: &'static str,
manifest_hash: u64,
locales: &'static [(&'static str, Dir)],
registry: &'static Registry,
catalogs: &'static [CatalogFile],
) -> Corpus {
Corpus {
source_locale,
manifest_hash,
locales,
registry,
catalogs,
language_matching: None,
}
}
#[doc(hidden)]
#[must_use]
pub const fn with_language_matching(mut self, matching: &'static LanguageMatching) -> Corpus {
self.language_matching = Some(matching);
self
}
#[cfg(feature = "native")]
pub(crate) fn language_matching(&self) -> &'static LanguageMatching {
self.language_matching.unwrap_or(&LanguageMatching::EMPTY)
}
#[must_use]
pub const fn source_locale(&self) -> &'static str {
self.source_locale
}
#[must_use]
pub const fn manifest_hash(&self) -> u64 {
self.manifest_hash
}
#[must_use]
pub const fn locales(&self) -> &'static [(&'static str, Dir)] {
self.locales
}
#[must_use]
pub const fn registry(&self) -> &'static Registry {
self.registry
}
#[must_use]
pub const fn catalogs(&self) -> &'static [CatalogFile] {
self.catalogs
}
}
impl CatalogFile {
#[doc(hidden)]
#[must_use]
pub const fn new(
tag: &'static str,
file_name: &'static str,
bytes: Option<&'static [u8]>,
) -> CatalogFile {
CatalogFile {
tag,
file_name,
bytes,
}
}
#[must_use]
pub const fn tag(&self) -> &'static str {
self.tag
}
#[must_use]
pub const fn file_name(&self) -> &'static str {
self.file_name
}
#[must_use]
pub const fn bytes(&self) -> Option<&'static [u8]> {
self.bytes
}
}