pub struct Triple { /* private fields */ }
Expand description
A single, specific target, uniquely identified by a triple.
A Triple
may be constructed through new
or the FromStr
implementation.
Every Platform
is backed by one of these.
§Standard and custom platforms
target-spec
recognizes two kinds of platforms:
-
Standard platforms: These platforms are only specified by their triple string, either directly or via a
Triple
. For example, the platformx86_64-unknown-linux-gnu
is a standard platform since it is recognized by Rust.All builtin platforms are standard platforms.
By default, if a platform isn’t builtin, target-spec attempts to heuristically determine the characteristics of the platform based on the triple string. (Use the
new_strict
constructor to disable this.) -
Custom platforms: These platforms are specified via both a triple string and a JSON file in the format defined by Rust. Custom platforms are used for targets not recognized by Rust.
§Examples
use target_spec::Triple;
// Parse a simple target.
let target = Triple::new("x86_64-unknown-linux-gnu").unwrap();
// This is not a valid triple.
let err = Triple::new("cannot-be-known").unwrap_err();
Implementations§
Source§impl Triple
impl Triple
Sourcepub fn new(
triple_str: impl Into<Cow<'static, str>>,
) -> Result<Self, TripleParseError>
pub fn new( triple_str: impl Into<Cow<'static, str>>, ) -> Result<Self, TripleParseError>
Creates a new Triple
from a triple string.
Sourcepub fn new_strict(
triple_str: impl Into<Cow<'static, str>>,
) -> Result<Self, TripleParseError>
pub fn new_strict( triple_str: impl Into<Cow<'static, str>>, ) -> Result<Self, TripleParseError>
Creates a new Triple
from a triple string.
This constructor only consults the builtin platform table, and does not attempt to heuristically determine the platform’s characteristics based on the triple string.
Sourcepub fn new_custom(
triple_str: impl Into<Cow<'static, str>>,
json: &str,
) -> Result<Self, CustomTripleCreateError>
Available on crate feature custom
only.
pub fn new_custom( triple_str: impl Into<Cow<'static, str>>, json: &str, ) -> Result<Self, CustomTripleCreateError>
custom
only.Creates a new custom Triple
from the given triple string and JSON specification.
Sourcepub fn is_standard(&self) -> bool
pub fn is_standard(&self) -> bool
Returns true if this is a triple corresponding to a standard platform.
A standard platform can be either builtin, or heuristically determined.
§Examples
use target_spec::Triple;
// x86_64-unknown-linux-gnu is Linux x86_64.
let platform = Triple::new("x86_64-unknown-linux-gnu").unwrap();
assert!(platform.is_standard());
Sourcepub fn is_builtin(&self) -> bool
pub fn is_builtin(&self) -> bool
Returns true if this is a triple corresponding to a builtin platform.
§Examples
use target_spec::Triple;
// x86_64-unknown-linux-gnu is Linux x86_64, which is a Rust tier 1 platform.
let triple = Triple::new("x86_64-unknown-linux-gnu").unwrap();
assert!(triple.is_builtin());
Sourcepub fn is_heuristic(&self) -> bool
pub fn is_heuristic(&self) -> bool
Returns true if this triple was heuristically determined.
All heuristically determined platforms are standard, but most of the time, standard platforms are builtin.
§Examples
use target_spec::Triple;
// armv5te-apple-darwin is not a real platform, but target-spec can heuristically
// guess at its characteristics.
let triple = Triple::new("armv5te-apple-darwin").unwrap();
assert!(triple.is_heuristic());