pub trait VerifierWriter {
// Required methods
fn to_bytes(&self) -> Result<Vec<u8>, Error>;
fn technology(&self) -> Technology;
fn file_name(&self) -> PathBuf;
// Provided method
fn write_to_hierarchy(
&self,
path: impl AsRef<Path>,
os: Os,
purpose: Purpose,
context: Option<Context>,
) -> Result<(), Error> { ... }
}
Expand description
A trait that provides functionality for writing a VOA verifier to a VOA hierarchy.
§Note
By default, VerifierWriter
allows to write to arbitrary locations.
While VerifierWriter::write_to_hierarchy
enables the user to write a verifier to the correct
location in a hierarchy, this trait does not concern itself with where that hierarchy is
located, nor does it consider existing symlinking or masking rules.
This trait is meant to provide basic functionality for writing verifiers to a VOA hierarchy.
Users of this trait must care for applying its functionality on the correct location (see [load
paths]) and handle symlinking and masking separately to comply with the strict rules that
Voa::lookup
enforces.
§Examples
use std::{fs::read_to_string, path::PathBuf};
use voa_core::{
Error,
VerifierWriter,
identifiers::{CustomTechnology, Technology},
};
const VERIFIER_DATA: &str = "test";
// A test struct implementing `VerifierWrite`
struct TestWriter;
impl VerifierWriter for TestWriter {
fn to_bytes(&self) -> Result<Vec<u8>, Error> {
Ok(VERIFIER_DATA.as_bytes().to_vec())
}
fn technology(&self) -> Technology {
Technology::Custom(CustomTechnology::new("technology".parse().unwrap()))
}
fn file_name(&self) -> PathBuf {
PathBuf::from("dummy.test")
}
}
let test_dir = tempfile::tempdir()?;
let path = test_dir.path();
let test_writer = TestWriter;
// Write the verifier to a temporary directory.
test_writer.write_to_hierarchy(path, "os".parse()?, "purpose".parse()?, None)?;
// Ensure that the contents match.
let verifier_file = path
.join("os")
.join("purpose")
.join("default")
.join("technology")
.join(test_writer.file_name());
let verifier_contents = read_to_string(verifier_file)?;
assert_eq!(verifier_contents, VERIFIER_DATA);
Required Methods§
Sourcefn technology(&self) -> Technology
fn technology(&self) -> Technology
Returns the Technology
used by the verifier.
Sourcefn file_name(&self) -> PathBuf
fn file_name(&self) -> PathBuf
Returns the file name of the verifier.
File names depend on the Technology
used by the verifier.
Provided Methods§
Sourcefn write_to_hierarchy(
&self,
path: impl AsRef<Path>,
os: Os,
purpose: Purpose,
context: Option<Context>,
) -> Result<(), Error>
fn write_to_hierarchy( &self, path: impl AsRef<Path>, os: Os, purpose: Purpose, context: Option<Context>, ) -> Result<(), Error>
Writes the verifier to a VOA hierarchy.
The VOA hierarchy directory is provided using path
.
Using os
, purpose
and context
and the specific technology (see
VerifierWriter::technology
), the correct directory for the verifier is created in
path
. Afterwards, the verifier data is written to the specific file name (see
VerifierWriter::file_name
).
§Errors
Returns an error if
- the parent directory for the verifier cannot be created,
- the verifier file cannot be created,
- or the verifier data cannot be written to the file.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.