pub struct BinaryBuilder { /* private fields */ }
Expand description
Places all nlprule binaries for the given languages in some directory.
Implementations§
Source§impl BinaryBuilder
impl BinaryBuilder
Sourcepub fn new<P: AsRef<Path>>(language_codes: &[&str], out_dir: P) -> Self
pub fn new<P: AsRef<Path>>(language_codes: &[&str], out_dir: P) -> Self
Creates a new binary builder. language_codes
must be in ISO 639-1 (two-letter) format.
If language_codes
is &[]
, uses all supported languages.
If this is used in a build.rs
, out_dir
should probably be the OUT_DIR environment variable.
Sourcepub fn version<S: Into<String>>(self, version: S) -> Self
pub fn version<S: Into<String>>(self, version: S) -> Self
Sets the version for which to fetch binaries.
The version of nlprule-build
(kept in sync with nlprule
version) by default.
Typically does not need to be modified.
Sourcepub fn cache_dir(self, cache_dir: Option<PathBuf>) -> Self
pub fn cache_dir(self, cache_dir: Option<PathBuf>) -> Self
Sets the cache directory. The user cache directory at e. g. ~/.cache/nlprule
by default.
Sourcepub fn fallback_to_build_dir(self, fallback_to_build_dir: bool) -> Self
pub fn fallback_to_build_dir(self, fallback_to_build_dir: bool) -> Self
Sets whether to fallback to building from the build directory if no distributed binaries are found (i. e. a development version of nlprule is used).
Sourcepub fn build_dir(self, build_dir: Option<PathBuf>) -> Self
pub fn build_dir(self, build_dir: Option<PathBuf>) -> Self
Sets the path the build directories should be stored at.
Only relevant if fallback_to_build_dir
is true.
cache_dir.join("build_dirs")
by default.
Sourcepub fn build(self) -> Result<Self>
pub fn build(self) -> Result<Self>
Builds by {downloading, copying, building} the binaries to the out directory.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates the binaries by checking if they can be loaded by nlprule.
Sourcepub fn transform<D, P>(self, proc_fn: D, path_fn: P) -> Self
pub fn transform<D, P>(self, proc_fn: D, path_fn: P) -> Self
Applies the given transformation function to the binary immediately after obtaining it.
This happens before placing the file in the cache (if any) so by using a compression
function the size of the cache directory can be reduced.
Modifies the path of the cached binaries by the given path_fn
.
If no cache directory is set or the binaries are built from the build dir, the path_fn
does nothing.
The resulting files will then reside in the given cache dir if any.
Attention: Any compression applied here, must be undone in the
fn postprocess
provided closure to retain the original binenc file
to be consumed by the application code.
Sourcepub fn postprocess<F, C, P>(self, proc_fn: C, path_fn: F) -> Result<Self>
pub fn postprocess<F, C, P>(self, proc_fn: C, path_fn: F) -> Result<Self>
Applies the given postprocessing function to the binaries e. g. for compression. Modifies the output path by the given path function.
§Example
builder
.build()?
.postprocess(
|reader, mut writer| {
let mut encoder = flate2::read::GzEncoder::new(reader, flate2::Compression::default());
std::io::copy(&mut encoder, &mut writer)?;
Ok(())
},
|p| {
let mut path = p.as_os_str().to_os_string();
path.push(".gz");
path
},
)?;
Auto Trait Implementations§
impl Freeze for BinaryBuilder
impl !RefUnwindSafe for BinaryBuilder
impl !Send for BinaryBuilder
impl !Sync for BinaryBuilder
impl Unpin for BinaryBuilder
impl !UnwindSafe for BinaryBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more