mod addresses;
mod archive;
mod container;
mod ext4;
mod images;
mod os;
mod pod;
mod registry;
mod spec;
use crate::bridge::ffi;
use std::collections::BTreeMap;
use std::path::Path;
fn path(path: &Path) -> Option<String> {
path.to_str().map(str::to_string)
}
fn lossy_path(path: &Path) -> String {
path.display().to_string()
}
fn present<T>(value: &Option<T>) -> &T {
value
.as_ref()
.expect("Swift asks for an optional field only after its `has_` getter")
}
fn entry_at<T>(map: &BTreeMap<String, T>, index: usize) -> (&str, &T) {
map
.iter()
.nth(index)
.map(|(key, value)| (key.as_str(), value))
.expect("Swift asks for an entry only below the length")
}
impl ffi::CzOutcome {
fn optional<T>(&self, read: impl FnOnce(&Self) -> T) -> Option<T> {
self.is_some().then(|| read(self))
}
fn list<T>(&self, read: impl Fn(&Self) -> T) -> Vec<T> {
(0..self.len()).map(|index| read(&self.at(index))).collect()
}
fn map(&self) -> BTreeMap<String, String> {
self.map_keys().into_iter().zip(self.map_values()).collect()
}
fn map_of<T>(&self, read: impl Fn(&Self) -> T) -> BTreeMap<String, T> {
self
.entry_keys()
.into_iter()
.zip(self.entry_values().list(read))
.collect()
}
pub(crate) fn optional_text(&self) -> Option<String> {
self.optional(Self::text)
}
pub(crate) fn optional_int32(&self) -> Option<i32> {
self.optional(Self::int32)
}
pub(crate) fn int32_map(&self) -> BTreeMap<String, i32> {
self.map_of(Self::int32)
}
}