[][src]Struct tweep::Output

pub struct Output<T> { /* fields omitted */ }

Represents the output of an operation along with a Vec of any Warnings generated by the operation.

If the contained type T implements the Positional trait, then Output<T> will also implement the Positional trait, and will apply any changes to both the contained output and the contained Warnings.

Implementations

impl<T> Output<T>[src]

pub fn new(value: T) -> Self[src]

Creates a new Output with the given value and no Warnings

Arguments

  • value - The output value

Examples

use tweep::Output;
let out:Output<u32> = Output::new(23);
assert_eq!(*out.get_output(), 23);
assert!(!out.has_warnings());

pub fn with_warnings(self, warnings: Vec<Warning>) -> Self[src]

Builder method to add Warnings to an Output and return the object

Arguments

  • warnings - The list of Warnings to add to the object

Examples

use tweep::{FullContext, Output, Warning, WarningKind};
let warnings = vec![ Warning::new(WarningKind::MissingStoryTitle, Some(context)) ];
let out:Output<u32> = Output::new(23).with_warnings(warnings.clone());
assert!(out.has_warnings());
assert_eq!(*out.get_warnings(), warnings);

pub fn get_output(&self) -> &T[src]

Returns a reference to the output field

Examples

use tweep::Output;
let out = Output::new("hail eris");
assert_eq!(*out.get_output(), "hail eris");

pub fn mut_output(&mut self) -> &mut T[src]

Returns a mutable reference to the output field

Examples

use tweep::Output;
let mut out = Output::new(23 as usize);
*out.mut_output() = 5;
assert_eq!(*out.get_output(), 5);

pub fn has_warnings(&self) -> bool[src]

Returns true if the object has associated Warnings

Examples

use tweep::{FullContext, Output, Warning, WarningKind};
let out:Output<u8> = Output::new(5);
assert!(!out.has_warnings());
let out:Output<u8> = Output::new(5)
    .with_warnings(vec![ Warning::new(WarningKind::UnclosedLink, Some(context)) ]);
assert!(out.has_warnings());

pub fn get_warnings(&self) -> &Vec<Warning>[src]

Returns a reference to the associated Vec of Warnings

Examples

use tweep::{FullContext, Output, Warning, WarningKind};
let out:Output<u8> = Output::new(5)
    .with_warnings(vec![ Warning::new(WarningKind::UnclosedLink, Some(context.clone())) ]);
assert_eq!(out.get_warnings(), &vec![ Warning::new(WarningKind::UnclosedLink, Some(context)) ]);

pub fn take(self) -> (T, Vec<Warning>)[src]

Consumes the Output and returns the output and warnings as a tuple

Examples

use tweep::{FullContext, Output, Warning, WarningKind};
let warnings = vec![ Warning::new(WarningKind::MissingStoryTitle, Some(context.clone())) ];
let out:Output<u32> = Output::new(23).with_warnings(warnings.clone());
let (t, w) = out.take();
assert_eq!(t, 23);
assert_eq!(w, warnings);

// Error!
// let _ = out.get_output();

impl<T, E> Output<Result<T, E>>[src]

This provides a handful of utility methods for an Output that contains a Result as its contained output

pub fn is_ok(&self) -> bool[src]

Returns true if the contained Result is Ok

Examples

use tweep::{Output, Error};
let out:Output<Result<u32, Error>> = Output::new(Ok(23));
assert!(out.is_ok());

pub fn is_err(&self) -> bool[src]

Returns true if the contained Result is Err

Examples

use tweep::{Output, Error, ErrorKind, FullContext};
let context = FullContext::from(None, "::".to_string());
let err = Error::new(ErrorKind::EmptyName, Some(context));
let out:Output<Result<u32, Error>> = Output::new(Err(err));
assert!(out.is_err());

pub fn into_ok<U, F>(self) -> Output<Result<U, F>> where
    T: Into<U>, 
[src]

Converts this Output<Result<T,E>> into an Output<Result<U,F>>, where T can be converted into U.

Panics

Panics if the contained Result<T,E> is not Ok

Examples

use tweep::{Output, Error};
let out:Output<Result<u8, Error>> = Output::new(Ok(23));

// The destination Error type does not need to be convertible from the source
let other:Output<Result<u32, String>> = out.into_ok();
assert!(other.is_ok());
assert_eq!(*other.get_output(), Ok(23));

pub fn into_err<U, F>(self) -> Output<Result<U, F>> where
    E: Into<F>, 
[src]

Converts this Output<Result<T,E>> into an Output<Result<U,F>>, where E can be converted into F

Panics

Panics if the contained Result<T,E> is not Err

Examples

use tweep::Output;
let out:Output<Result<u8, u8>> = Output::new(Err(5));

// The destination Ok type does not need to be convertible from the source
let other:Output<Result<String, u32>> = out.into_err();
assert!(other.is_err());
assert_eq!(*other.get_output(), Err(5));

pub fn into_result<U, F>(self) -> Output<Result<U, F>> where
    T: Into<U>,
    E: Into<F>, 
[src]

Converts this Output<Result<T,E>> into an Output<Result<U,F>>, where T can be converted into U and E can be converted into F

Examples

use tweep::Output;
let mut out:Output<Result<u8, u8>> = Output::new(Ok(23));
let mut other:Output<Result<u32, u32>> = out.into_result();
assert!(other.is_ok());
assert_eq!(*other.get_output(), Ok(23));
out = Output::new(Err(5));
other = out.into_result();
assert!(other.is_err());
assert_eq!(*other.get_output(), Err(5));

Auto Trait Implementations

impl<T> RefUnwindSafe for Output<T> where
    T: RefUnwindSafe

impl<T> Send for Output<T> where
    T: Send

impl<T> Sync for Output<T> where
    T: Sync

impl<T> Unpin for Output<T> where
    T: Unpin

impl<T> UnwindSafe for Output<T> where
    T: UnwindSafe

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