Struct target_spec::TargetSpec[][src]

pub struct TargetSpec<'a> { /* fields omitted */ }

A parsed target specification or triple, as found in a Cargo.toml file.

Use the FromStr implementation or str::parse to obtain an instance.

Examples

use target_spec::{Platform, TargetFeatures, TargetSpec};

let i686_windows = Platform::new("i686-pc-windows-gnu", TargetFeatures::Unknown).unwrap();
let x86_64_mac = Platform::new("x86_64-apple-darwin", TargetFeatures::none()).unwrap();
let i686_linux = Platform::new(
    "i686-unknown-linux-gnu",
    TargetFeatures::features(["sse2"].iter().copied()),
).unwrap();

let spec: TargetSpec = "cfg(any(windows, target_arch = \"x86_64\"))".parse().unwrap();
assert_eq!(spec.eval(&i686_windows), Some(true), "i686 Windows");
assert_eq!(spec.eval(&x86_64_mac), Some(true), "x86_64 MacOS");
assert_eq!(spec.eval(&i686_linux), Some(false), "i686 Linux (should not match)");

let spec: TargetSpec = "cfg(any(target_feature = \"sse2\", target_feature = \"sse\"))".parse().unwrap();
assert_eq!(spec.eval(&i686_windows), None, "i686 Windows features are unknown");
assert_eq!(spec.eval(&x86_64_mac), Some(false), "x86_64 MacOS matches no features");
assert_eq!(spec.eval(&i686_linux), Some(true), "i686 Linux matches some features");

Implementations

impl<'a> TargetSpec<'a>[src]

pub fn custom(target_info: &'a TargetInfo<'a>) -> Self[src]

Creates a new exact, custom target spec to match against.

Note that this is for an exact target spec, similar to a triple specified, not an expression like cfg(windows).

Custom platforms are often found in embedded and similar environments. For built-in platforms, the FromStr implementation is recommended instead.

pub fn eval(&self, platform: &Platform<'_>) -> Option<bool>[src]

Evaluates this specification against the given platform.

Returns Some(true) if there's a match, Some(false) if there's none, or None if the result of the evaluation is unknown (typically found if target features are involved).

Trait Implementations

impl<'a> Clone for TargetSpec<'a>[src]

impl<'a> Debug for TargetSpec<'a>[src]

impl FromStr for TargetSpec<'static>[src]

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations

impl<'a> RefUnwindSafe for TargetSpec<'a>[src]

impl<'a> Send for TargetSpec<'a>[src]

impl<'a> Sync for TargetSpec<'a>[src]

impl<'a> Unpin for TargetSpec<'a>[src]

impl<'a> UnwindSafe for TargetSpec<'a>[src]

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, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,