Struct BinaryBuilder

Source
pub struct BinaryBuilder { /* private fields */ }
Expand description

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

Implementations§

Source§

impl BinaryBuilder

Source

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.

Source

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.

Source

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

Sets the out directory.

Source

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.

Source

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

Source

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.

Source

pub fn build(self) -> Result<Self>

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

Source

pub fn validate(&self) -> Result<()>

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

Source

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

Gets the paths to all files this builder created.

Source

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,

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.

Source

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>,

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,