Struct nlprule_build::BinaryBuilder[][src]

pub struct BinaryBuilder { /* fields omitted */ }

Places all nlprule binaries for the given languages in some directory.

Implementations

impl BinaryBuilder[src]

pub fn new<P: AsRef<Path>>(language_codes: &[&str], out_dir: P) -> Self[src]

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.

pub fn version<S: Into<String>>(self, version: S) -> Self[src]

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.

pub fn out_dir(self, out_dir: PathBuf) -> Self[src]

Sets the out directory.

pub fn cache_dir(self, cache_dir: Option<PathBuf>) -> Self[src]

Sets the cache directory. The user cache directory at e. g. ~/.cache/nlprule by default.

pub fn fallback_to_build_dir(self, fallback_to_build_dir: bool) -> Self[src]

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).

pub fn build_dir(self, build_dir: Option<PathBuf>) -> Self[src]

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.

pub fn build(self) -> Result<Self>[src]

Builds by {downloading, copying, building} the binaries to the out directory.

pub fn validate(&self) -> Result<()>[src]

Validates the binaries by checking if they can be loaded by nlprule.

pub fn outputs(&self) -> &[PathBuf][src]

Gets the paths to all files this builder created.

pub fn transform<D, P>(self, proc_fn: D, path_fn: P) -> Self where
    D: Fn(&[u8], &mut Vec<u8>) -> Result<(), OtherError> + 'static,
    P: Fn(PathBuf) -> Result<PathBuf, OtherError> + 'static, 
[src]

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.

pub fn postprocess<F, C, P>(self, proc_fn: C, path_fn: F) -> Result<Self> where
    C: Fn(BufReader<File>, BufWriter<File>) -> Result<(), OtherError>,
    F: Fn(PathBuf) -> P,
    P: AsRef<Path>, 
[src]

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.