Skip to main content

parse_named

Function parse_named 

pub fn parse_named(entry: &str) -> Result<NamedDistribution>
Expand description

Parses a single name = spec line into a NamedDistribution.

The name is everything before the first = (trimmed); the spec is the rest. A step= inside the spec is therefore never mistaken for the separator, because the name is a plain identifier that ends at the first =.

use atune_core::space::dsl;

let parsed = dsl::parse_named("batch = int(16, 512, step=16)")?;
assert_eq!(parsed.name, "batch");
assert_eq!(parsed.distribution, atune_core::space::Distribution::try_new_with_stepped_int(16, 512, 16)?);

§Errors

Error::InvalidSpace if there is no =, if the name is empty, or if the spec does not parse (the spec error is prefixed with the parameter name). Parses a single name = spec line into a NamedDistribution.

The name is everything before the first = (trimmed); the spec is the rest. A step= inside the spec is therefore never mistaken for the separator, because the name is a plain identifier that ends at the first =.

use atune_core::space::dsl;

let parsed = dsl::parse_named("batch = int(16, 512, step=16)")?;
assert_eq!(parsed.name, "batch");
assert_eq!(parsed.distribution, atune_core::space::Distribution::try_new_with_stepped_int(16, 512, 16)?);

§Errors

Error::InvalidSpace if there is no =, if the name is empty, or if the spec does not parse (the spec error is prefixed with the parameter name).