Skip to main content

Result

Struct Result 

Source
pub struct Result<E> { /* private fields */ }
Expand description

A parse result.

This struct contains the results of parsing either (a) a WDL parse tree or (b) a WDL abstract syntax tree. It contains two distinct entities:

  • An optional list of Concerns, if any were emitted during parsing.
  • An optional tree based on type E, if one was able to be constructed.

Notably, you cannot create a Result that has no concerns and no parse tree, as that scenario is non-sensical.

Implementations§

Source§

impl<E> Result<E>

Source

pub fn try_new( tree: Option<E>, concerns: Option<Concerns>, ) -> Result<Self, Error>

Attempts to create a new Result.

§Examples
use wdl_core::concern::concerns::Builder;
use wdl_core::concern::parse;
use wdl_core::file::Location;
use wdl_core::parse::Result;
use wdl_core::Concern;

// Substitute `42` for your parse tree or abstract syntax tree.
let result = Result::try_new(Some(42), None).unwrap();
assert!(result.tree().is_some());
assert!(result.concerns().is_none());

let error = parse::Error::new("Hello, world!", Location::Unplaced);
let concern = Concern::ParseError(error);
let concerns = Builder::default().push(concern).build();

let result = Result::<usize>::try_new(None, concerns).unwrap();
assert!(result.tree().is_none());
assert!(result.concerns().is_some());

let err = Result::<usize>::try_new(None, None).unwrap_err();
assert_eq!(
    err.to_string(),
    String::from(
        "contradiction encountered: cannot create a parse Result with no concerns and no \
         parse tree"
    )
);
Source

pub fn concerns(&self) -> Option<&Concerns>

Gets the concerns from the Result by reference.

§Examples
use wdl_core::concern::concerns::Builder;
use wdl_core::concern::parse;
use wdl_core::file::Location;
use wdl_core::parse::Result;
use wdl_core::Concern;

let error = parse::Error::new("Hello, world!", Location::Unplaced);
let concern = Concern::ParseError(error);
let concerns = Builder::default().push(concern).build();

let result = Result::<usize>::try_new(None, concerns).unwrap();

let first = result.concerns().unwrap().inner().iter().next().unwrap();
let error = first.as_parse_error().unwrap();
assert_eq!(error.message(), "Hello, world!");
Source

pub fn into_concerns(self) -> Option<Concerns>

Consumes self and returns the concerns from the Result.

§Examples
use wdl_core::concern::concerns::Builder;
use wdl_core::concern::parse;
use wdl_core::file::Location;
use wdl_core::parse::Result;
use wdl_core::Concern;

let error = parse::Error::new("Hello, world!", Location::Unplaced);
let concern = Concern::ParseError(error);
let concerns = Builder::default().push(concern).build();

let result = Result::<usize>::try_new(None, concerns).unwrap();

let first = result
    .into_concerns()
    .unwrap()
    .into_inner()
    .into_iter()
    .next()
    .unwrap();
let error = first.into_parse_error().unwrap();
assert_eq!(error.message(), String::from("Hello, world!"));
Source

pub fn tree(&self) -> Option<&E>

Gets the tree from the Result by reference.

§Examples
use wdl_core::parse::Result;

// Substitute `42` for your parse tree or abstract syntax tree.
let result = Result::<usize>::try_new(Some(42), None).unwrap();

let first = result.tree().unwrap();
assert_eq!(first, &42);
Source

pub fn into_tree(self) -> Option<E>

Consumes self and returns the tree from the Result.

§Examples
use wdl_core::parse::Result;

// Substitute `42` for your parse tree or abstract syntax tree.
let result = Result::<usize>::try_new(Some(42), None).unwrap();

let first = result.into_tree().unwrap();
assert_eq!(first, 42);
Source

pub fn into_parts(self) -> (Option<E>, Option<Concerns>)

Breaks a Result down into its parts.

§Examples
use wdl_core::concern::concerns::Builder;
use wdl_core::concern::parse;
use wdl_core::file::Location;
use wdl_core::parse::Result;
use wdl_core::Concern;

let error = parse::Error::new("Hello, world!", Location::Unplaced);
let concern = Concern::ParseError(error);
let concerns = Builder::default().push(concern).build();

// Substitute `42` for your parse tree or abstract syntax tree.
let result = Result::<usize>::try_new(Some(42), concerns).unwrap();
assert_eq!(result.tree(), Some(&42));
assert_eq!(
    result
        .concerns()
        .unwrap()
        .inner()
        .iter()
        .next()
        .unwrap()
        .as_parse_error()
        .unwrap()
        .message(),
    "Hello, world!"
);

Trait Implementations§

Source§

impl<E: Debug> Debug for Result<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E> Freeze for Result<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for Result<E>
where E: RefUnwindSafe,

§

impl<E> Send for Result<E>
where E: Send,

§

impl<E> Sync for Result<E>
where E: Sync,

§

impl<E> Unpin for Result<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for Result<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for Result<E>
where E: UnwindSafe,

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