1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
use crate::Version;
use bytes::Bytes;
use std::path::Path;
use tokio::runtime::Runtime;
lazy_static! {
static ref RUNTIME: Runtime = Runtime::new().unwrap();
}
/// Gets the version of PostgreSQL for the specified [version](Version). If the version minor or release is not
/// specified, then the latest version is returned. If a release for the [version](Version) is not found, then a
/// [ReleaseNotFound](crate::Error::ReleaseNotFound) error is returned.
///
/// # Errors
///
/// Returns an error if the version is not found.
pub fn get_version(releases_url: &str, version: &Version) -> crate::Result<Version> {
RUNTIME
.handle()
.block_on(async move { crate::get_version(releases_url, version).await })
}
/// Gets the archive for a given [version](Version) of PostgreSQL for the current target.
/// If the [version](Version) is not found for this target, then an
/// [error](crate::Error) is returned.
///
/// Returns the archive version and bytes.
///
/// # Errors
///
/// Returns an error if the version is not found.
pub fn get_archive(releases_url: &str, version: &Version) -> crate::Result<(Version, Bytes)> {
RUNTIME
.handle()
.block_on(async move { crate::get_archive(releases_url, version).await })
}
/// Gets the archive for a given [version](Version) of PostgreSQL and
/// [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html).
/// If the [version](Version) or [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html)
/// is not found, then an [error](crate::error::Error) is returned.
///
/// Returns the archive version and bytes.
///
/// # Errors
///
/// Returns an error if the version or target is not found.
pub fn get_archive_for_target<S: AsRef<str>>(
releases_url: &str,
version: &Version,
target: S,
) -> crate::Result<(Version, Bytes)> {
RUNTIME
.handle()
.block_on(async move { crate::get_archive_for_target(releases_url, version, target).await })
}
/// Extracts the compressed tar [bytes](Bytes) to the [out_dir](Path).
///
/// # Errors
///
/// Returns an error if the extraction fails.
pub fn extract(bytes: &Bytes, out_dir: &Path) -> crate::Result<()> {
RUNTIME
.handle()
.block_on(async move { crate::extract(bytes, out_dir).await })
}